Skip to content

Commit c4cad5e

Browse files
committed
- Added plugin migrations for pre-alpha deployment
1 parent 64efb26 commit c4cad5e

File tree

1 file changed

+148
-0
lines changed

1 file changed

+148
-0
lines changed
Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
// <copyright>
2+
// Copyright by the Spark Development Network
3+
//
4+
// Licensed under the Rock Community License (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
//
8+
// http://www.rockrms.com/license
9+
//
10+
// Unless required by applicable law or agreed to in writing, software
11+
// distributed under the License is distributed on an "AS IS" BASIS,
12+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
// See the License for the specific language governing permissions and
14+
// limitations under the License.
15+
// </copyright>
16+
17+
using System;
18+
19+
using Rock.Model;
20+
21+
namespace Rock.Plugin.HotFixes
22+
{
23+
/// <summary>
24+
/// Plug-in migration
25+
/// </summary>
26+
/// <seealso cref="Rock.Plugin.Migration" />
27+
[MigrationNumber( 271, "19.0" )]
28+
public class MigrationRollupsForV19_0_1 : Migration
29+
{
30+
/// <summary>
31+
/// Operations to be performed during the upgrade process.
32+
/// </summary>
33+
public override void Up()
34+
{
35+
UpdateMobileCommunicationView();
36+
AddEventRegistrationAdminAuthToTopLevelCategories();
37+
}
38+
39+
/// <summary>
40+
/// Operations to be performed during the downgrade process.
41+
/// </summary>
42+
public override void Down()
43+
{
44+
45+
}
46+
47+
#region NA: Rename original Default to "Legacy (Original)"
48+
49+
private void UpdateMobileCommunicationView()
50+
{
51+
// Update original "Default" Template for the Mobile Communication View to be called "Legacy (Original)"
52+
// because there is already a newer Template called "Legacy" and the newest "Default".
53+
Sql( "UPDATE [DefinedValue] SET [Value] = 'Legacy (Original)' WHERE [Guid] = '39B8B16D-D213-46FD-9B8F-710453806193'" );
54+
}
55+
56+
#endregion
57+
58+
#region NA: Migration to Add EDIT/ADMINISTRATE Auth to the "RSR - Event Registration Administration" group on all top-level RegistrationTemplate categories
59+
60+
private void AddEventRegistrationAdminAuthToTopLevelCategories()
61+
{
62+
Sql( @"-- Add Edit and Administrate auth to the RSR Event Registration Administration group
63+
-- on all top-level RegistrationTemplate categories, without duplicates.
64+
65+
DECLARE @Now DATETIME = GETDATE();
66+
DECLARE @RSREventRegistrationAdministrationRoleId INT =
67+
(
68+
SELECT [Id]
69+
FROM [Group]
70+
WHERE [Guid] = '2A92086B-DFF0-4B9C-46CB-4DAD805615AF'
71+
);
72+
73+
DECLARE @RegistrationTemplateEntityTypeId INT =
74+
(
75+
SELECT [Id]
76+
FROM [EntityType]
77+
WHERE [Name] = 'Rock.Model.RegistrationTemplate'
78+
);
79+
80+
DECLARE @CategoryEntityTypeId INT =
81+
(
82+
SELECT [Id]
83+
FROM [EntityType]
84+
WHERE [Name] = 'Rock.Model.Category'
85+
);
86+
87+
;WITH [TopLevelRegistrationTemplateCategories] AS
88+
(
89+
SELECT
90+
c.[Id] AS [CategoryId]
91+
FROM [Category] AS c
92+
WHERE
93+
c.[ParentCategoryId] IS NULL
94+
AND c.[EntityTypeId] = @RegistrationTemplateEntityTypeId
95+
),
96+
[DesiredAuth] AS
97+
(
98+
SELECT
99+
tl.[CategoryId]
100+
, a.[Action]
101+
, a.[Order]
102+
FROM [TopLevelRegistrationTemplateCategories] AS tl
103+
CROSS APPLY (VALUES
104+
('Edit', 0),
105+
('Administrate', 0)
106+
) AS a([Action], [Order])
107+
)
108+
INSERT INTO [Auth]
109+
(
110+
[EntityTypeId]
111+
, [EntityId]
112+
, [Order]
113+
, [Action]
114+
, [AllowOrDeny]
115+
, [SpecialRole]
116+
, [GroupId]
117+
, [Guid]
118+
, [CreatedDateTime]
119+
, [ModifiedDateTime]
120+
)
121+
SELECT
122+
@CategoryEntityTypeId -- [EntityTypeId]
123+
, d.[CategoryId] -- [EntityId]
124+
, d.[Order] -- [Order]
125+
, d.[Action] -- [Action]
126+
, 'A' -- [AllowOrDeny]
127+
, 0 -- [SpecialRole]
128+
, @RSREventRegistrationAdministrationRoleId -- [GroupId]
129+
, NEWID() -- [Guid]
130+
, @Now -- [CreatedDateTime]
131+
, @Now -- [ModifiedDateTime]
132+
FROM [DesiredAuth] AS d
133+
WHERE NOT EXISTS
134+
(
135+
SELECT 1
136+
FROM [Auth] AS a
137+
WHERE
138+
a.[EntityTypeId] = @CategoryEntityTypeId
139+
AND a.[EntityId] = d.[CategoryId]
140+
AND a.[Action] = d.[Action]
141+
AND a.[SpecialRole] = 0
142+
AND a.[GroupId] = @RSREventRegistrationAdministrationRoleId
143+
);" );
144+
}
145+
146+
#endregion
147+
}
148+
}

0 commit comments

Comments
 (0)