/// <summary> /// Adds the page security authentication. Set GroupGuid to null when setting to a special role /// </summary> /// <param name="pageGuid">The page unique identifier.</param> /// <param name="action">The action.</param> /// <param name="groupGuid">The group unique identifier.</param> /// <param name="specialRole">The special role.</param> /// <param name="authGuid">The authentication unique identifier.</param> public void AddSecurityAuthForPage( string pageGuid, int order, string action, bool allow, string groupGuid, Rock.Model.SpecialRole specialRole, string authGuid ) { string entityTypeName = "Rock.Model.Page"; EnsureEntityTypeExists( entityTypeName ); string sql = @" DECLARE @groupId int SET @groupId = (SELECT [Id] FROM [Group] WHERE [Guid] = '{0}') DECLARE @entityTypeId int SET @entityTypeId = (SELECT [Id] FROM [EntityType] WHERE [name] = '{1}') DECLARE @pageId int SET @pageId = (SELECT [Id] FROM [Page] WHERE [Guid] = '{2}') INSERT INTO [dbo].[Auth] ([EntityTypeId] ,[EntityId] ,[Order] ,[Action] ,[AllowOrDeny] ,[SpecialRole] ,[PersonId] ,[GroupId] ,[Guid]) VALUES (@entityTypeId ,@pageId ,{6} ,'{3}' ,'{7}' ,{4} ,null ,@groupId ,'{5}') "; Sql( string.Format( sql, groupGuid ?? Guid.Empty.ToString(), entityTypeName, pageGuid, action, specialRole.ConvertToInt(), authGuid, order, ( allow ? "A" : "D" ) ) ); }
/// <summary> /// Adds a report field to a report /// </summary> /// <param name="reportGuid">The report unique identifier.</param> /// <param name="reportFieldType">Type of the report field.</param> /// <param name="showInGrid">if set to <c>true</c> [show in grid].</param> /// <param name="dataSelectComponentEntityTypeGuid">The data select component entity type unique identifier.</param> /// <param name="selection">The selection.</param> /// <param name="order">The order.</param> /// <param name="columnHeaderText">The column header text.</param> /// <param name="guid">The unique identifier.</param> public void AddReportField(string reportGuid, Rock.Model.ReportFieldType reportFieldType, bool showInGrid, string dataSelectComponentEntityTypeGuid, string selection, int order, string columnHeaderText, string guid ) { Migration.Sql( string.Format( @" DECLARE @ReportId INT = ( SELECT TOP 1 [Id] FROM [Report] WHERE [Guid] = '{0}' ) ,@DataSelectComponentEntityTypeId INT = ( SELECT TOP 1 [Id] FROM [EntityType] WHERE [Guid] = '{3}' ) INSERT INTO [dbo].[ReportField] ( [ReportId] ,[ReportFieldType] ,[ShowInGrid] ,[DataSelectComponentEntityTypeId] ,[Selection] ,[Order] ,[ColumnHeaderText] ,[Guid] ) VALUES ( @ReportId ,{1} ,{2} ,@DataSelectComponentEntityTypeId ,'{4}' ,{5} ,'{6}' ,'{7}' ) ", reportGuid, // {0} reportFieldType.ConvertToInt(), // {1} showInGrid.Bit(), // {2} dataSelectComponentEntityTypeGuid, // {3} selection.Replace("'", "''"), // {4} order, // {5} columnHeaderText, // {6} guid // {7} )); }
/// <summary> /// Adds the security authentication for rest action. /// </summary> /// <param name="restActionMethod">The rest action method.</param> /// <param name="restActionPath">The rest action path.</param> /// <param name="order">The order.</param> /// <param name="action">The action.</param> /// <param name="allow">if set to <c>true</c> [allow].</param> /// <param name="groupGuid">The group unique identifier.</param> /// <param name="specialRole">The special role.</param> /// <param name="authGuid">The authentication unique identifier.</param> public void AddSecurityAuthForRestAction( string restActionMethod, string restActionPath, int order, string action, bool allow, string groupGuid, Rock.Model.SpecialRole specialRole, string authGuid ) { string entityTypeName = "Rock.Model.RestAction"; EnsureEntityTypeExists( entityTypeName ); string sql = @" DECLARE @EntityTypeId int = ( SELECT TOP 1 [Id] FROM [EntityType] WHERE [name] = '{0}') DECLARE @ActionId int = ( SELECT TOP 1 [Id] FROM [RestAction] WHERE [ApiId] = '{1}{2}') IF @EntityTypeId IS NOT NULL AND @ActionId IS NOT NULL BEGIN DECLARE @groupId int = ( SELECT TOP 1 [Id] FROM [Group] WHERE [Guid] = '{6}') IF NOT EXISTS ( SELECT [Id] FROM [dbo].[Auth] WHERE [EntityTypeId] = @entityTypeId AND [EntityId] = @ActionId AND [Action] = '{4}' AND [SpecialRole] = {7} AND [GroupId] = @groupId ) BEGIN INSERT INTO [dbo].[Auth] ([EntityTypeId] ,[EntityId] ,[Order] ,[Action] ,[AllowOrDeny] ,[SpecialRole] ,[GroupId] ,[Guid]) VALUES (@EntityTypeId ,@ActionId ,{3} ,'{4}' ,'{5}' ,{7} ,@groupId ,'{8}') END END "; Migration.Sql( string.Format( sql, entityTypeName, // 0 restActionMethod, // 1 restActionPath, // 2 order, // 3 action, // 4 ( allow ? "A" : "D" ), // 5 groupGuid, // 6 specialRole.ConvertToInt(), // 7 authGuid ) ); // 8 }
/// <summary> /// Adds the security authentication for rest controller. /// </summary> /// <param name="restControllerClass">The rest controller class.</param> /// <param name="order">The order.</param> /// <param name="action">The action.</param> /// <param name="allow">if set to <c>true</c> [allow].</param> /// <param name="groupGuid">The group unique identifier.</param> /// <param name="specialRole">The special role.</param> /// <param name="authGuid">The authentication unique identifier.</param> public void AddSecurityAuthForRestController( string restControllerClass, int order, string action, bool allow, string groupGuid, Rock.Model.SpecialRole specialRole, string authGuid ) { string entityTypeName = "Rock.Model.RestController"; EnsureEntityTypeExists( entityTypeName ); string sql = @" DECLARE @EntityTypeId int = ( SELECT TOP 1 [Id] FROM [EntityType] WHERE [name] = '{0}') DECLARE @ControllerId int = ( SELECT TOP 1 [Id] FROM [RestController] WHERE [ClassName] = '{1}') IF @EntityTypeId IS NOT NULL AND @ControllerId IS NOT NULL BEGIN DECLARE @groupId int = ( SELECT TOP 1 [Id] FROM [Group] WHERE [Guid] = '{5}') IF NOT EXISTS ( SELECT [Id] FROM [dbo].[Auth] WHERE [EntityTypeId] = @entityTypeId AND [EntityId] = @ControllerId AND [Action] = '{3}' AND [SpecialRole] = {6} AND [GroupId] = @groupId ) BEGIN INSERT INTO [dbo].[Auth] ([EntityTypeId] ,[EntityId] ,[Order] ,[Action] ,[AllowOrDeny] ,[SpecialRole] ,[GroupId] ,[Guid]) VALUES (@EntityTypeId ,@ControllerId ,{2} ,'{3}' ,'{4}' ,{6} ,@groupId ,'{7}') END END "; Migration.Sql( string.Format( sql, entityTypeName, // 0 restControllerClass, // 1 order, // 2 action, // 3 ( allow ? "A" : "D" ), // 4 groupGuid, // 5 specialRole.ConvertToInt(), // 6 authGuid ) ); // 7 }
/// <summary> /// Adds the page security authentication. Set GroupGuid to null when setting to a special role /// </summary> /// <param name="groupTypeGuid">The group type unique identifier.</param> /// <param name="order">The order.</param> /// <param name="action">The action.</param> /// <param name="allow">if set to <c>true</c> [allow].</param> /// <param name="groupGuid">The group unique identifier.</param> /// <param name="specialRole">The special role.</param> /// <param name="authGuid">The authentication unique identifier.</param> public void AddSecurityAuthForGroupType( string groupTypeGuid, int order, string action, bool allow, string groupGuid, Rock.Model.SpecialRole specialRole, string authGuid ) { string entityTypeName = "Rock.Model.GroupType"; EnsureEntityTypeExists( entityTypeName ); string sql = @" DECLARE @groupId int SET @groupId = (SELECT [Id] FROM [Group] WHERE [Guid] = '{0}') DECLARE @entityTypeId int SET @entityTypeId = (SELECT [Id] FROM [EntityType] WHERE [name] = '{1}') DECLARE @groupTypeId int SET @groupTypeId = (SELECT [Id] FROM [GroupType] WHERE [Guid] = '{2}') IF NOT EXISTS ( SELECT [Id] FROM [dbo].[Auth] WHERE [EntityTypeId] = @entityTypeId AND [EntityId] = @groupTypeId AND [Action] = '{3}' AND [SpecialRole] = {4} AND [GroupId] = @groupId ) BEGIN INSERT INTO [dbo].[Auth] ([EntityTypeId] ,[EntityId] ,[Order] ,[Action] ,[AllowOrDeny] ,[SpecialRole] ,[GroupId] ,[Guid]) VALUES (@entityTypeId ,@groupTypeId ,{6} ,'{3}' ,'{7}' ,{4} ,@groupId ,'{5}') END "; Migration.Sql( string.Format( sql, groupGuid ?? Guid.Empty.ToString(), entityTypeName, groupTypeGuid, action, specialRole.ConvertToInt(), authGuid, order, ( allow ? "A" : "D" ) ) ); }
/// <summary> /// Adds the security authentication for content channel. /// </summary> /// <param name="contentChannelGuid">The content channel unique identifier.</param> /// <param name="order">The order.</param> /// <param name="action">The action.</param> /// <param name="allow">if set to <c>true</c> [allow].</param> /// <param name="groupGuid">The group unique identifier.</param> /// <param name="specialRole">The special role.</param> /// <param name="authGuid">The authentication unique identifier.</param> public void AddSecurityAuthForContentChannel( string contentChannelGuid, int order, string action, bool allow, string groupGuid, Rock.Model.SpecialRole specialRole, string authGuid ) { if ( string.IsNullOrWhiteSpace( groupGuid ) ) { groupGuid = Guid.Empty.ToString(); } string entityTypeName = "Rock.Model.ContentChannel"; EnsureEntityTypeExists( entityTypeName ); string sql = @" DECLARE @EntityTypeId int = ( SELECT TOP 1 [Id] FROM [EntityType] WHERE [name] = '{0}') DECLARE @ContentChannelId int = (SELECT TOP 1 [Id] FROM [ContentChannel] WHERE [Guid] = '{1}') IF @EntityTypeId IS NOT NULL AND @ContentChannelId IS NOT NULL BEGIN DECLARE @GroupId int = ( SELECT TOP 1 [Id] FROM [Group] WHERE [Guid] = '{2}') IF NOT EXISTS ( SELECT [Id] FROM [dbo].[Auth] WHERE [EntityTypeId] = @EntityTypeId AND [EntityId] = @ContentChannelId AND [Action] = '{4}' AND [AllowOrDeny] = '{5}' AND [SpecialRole] = {6} AND [GroupId] = @GroupId ) BEGIN INSERT INTO [dbo].[Auth] ([EntityTypeId] ,[EntityId] ,[Order] ,[Action] ,[AllowOrDeny] ,[SpecialRole] ,[GroupId] ,[Guid]) VALUES (@EntityTypeId ,@ContentChannelId ,{3} ,'{4}' ,'{5}' ,{6} ,@GroupId ,'{7}') END END "; Migration.Sql( string.Format( sql, entityTypeName, // 0 contentChannelGuid, // 1 groupGuid, // 2 order, // 3 action, // 4 ( allow ? "A" : "D" ), // 5 specialRole.ConvertToInt(), // 6 authGuid ) ); // 7 }