protected virtual string TryGetNamedConnectionStringFromDataConfig(string connectionStringName)
        {
            ConfigElementDictionary <string, ConnStringSettings> connectionStrings = Config.Get <DataConfig>().ConnectionStrings;

            if (connectionStrings.ContainsKey(connectionStringName))
            {
                return(connectionStrings[connectionStringName].ConnectionString);
            }

            return(string.Empty);
        }
        private void InstallCustomPermissions(SiteInitializer initializer)
        {
            SecurityConfig securityConfig = initializer.Context.GetConfig <SecurityConfig>();
            ConfigElementDictionary <string, Permission> permissionSetConfig = securityConfig.Permissions;
            ConfigElementDictionary <string, CustomPermissionsDisplaySettingsConfig> customPermissionsDisplaySettings = securityConfig.CustomPermissionsDisplaySettings;

            //Add the set
            if (!permissionSetConfig.ContainsKey(AgentsConstants.Security.PermissionSetName))
            {
                var agentsPermissionSet = new Permission(permissionSetConfig)
                {
                    Name            = AgentsConstants.Security.PermissionSetName,
                    Title           = "AgentsPermissions",
                    Description     = "AgentsPermissionsDescription",
                    ResourceClassId = typeof(AgentsResources).Name
                };
                permissionSetConfig.Add(agentsPermissionSet);

                agentsPermissionSet.Actions.Add(new SecurityAction(agentsPermissionSet.Actions)
                {
                    Name            = AgentsConstants.Security.View,
                    Type            = SecurityActionTypes.View,
                    Title           = "ViewAgents",
                    Description     = "ViewAgentsDescription",
                    ResourceClassId = typeof(AgentsResources).Name
                });
                agentsPermissionSet.Actions.Add(new SecurityAction(agentsPermissionSet.Actions)
                {
                    Name            = AgentsConstants.Security.Create,
                    Type            = SecurityActionTypes.Create,
                    Title           = "CreateAgents",
                    Description     = "CreateAgentsDescription",
                    ResourceClassId = typeof(AgentsResources).Name
                });
                agentsPermissionSet.Actions.Add(new SecurityAction(agentsPermissionSet.Actions)
                {
                    Name            = AgentsConstants.Security.Modify,
                    Type            = SecurityActionTypes.Modify,
                    Title           = "ModifyAgents",
                    Description     = "ModifyAgentsDescription",
                    ResourceClassId = typeof(AgentsResources).Name
                });
                agentsPermissionSet.Actions.Add(new SecurityAction(agentsPermissionSet.Actions)
                {
                    Name            = AgentsConstants.Security.Delete,
                    Type            = SecurityActionTypes.Delete,
                    Title           = "DeleteAgents",
                    Description     = "DeleteAgentsDescription",
                    ResourceClassId = typeof(AgentsResources).Name
                });
                agentsPermissionSet.Actions.Add(new SecurityAction(agentsPermissionSet.Actions)
                {
                    Name            = AgentsConstants.Security.ChangeOwner,
                    Type            = SecurityActionTypes.ChangeOwner,
                    Title           = "ChangeAgentsOwner",
                    Description     = "ChangeAgentsOwnerDescription",
                    ResourceClassId = typeof(AgentsResources).Name
                });
                agentsPermissionSet.Actions.Add(new SecurityAction(agentsPermissionSet.Actions)
                {
                    Name            = AgentsConstants.Security.ChangePermissions,
                    Type            = SecurityActionTypes.ChangePermissions,
                    Title           = "ChangeAgentsPermissions",
                    Description     = "ChangeAgentsPermissionsDescription",
                    ResourceClassId = typeof(AgentsResources).Name
                });
            }

            //Custom UI views
            if (!customPermissionsDisplaySettings.ContainsKey(AgentsConstants.Security.PermissionSetName))
            {
                var agentsCustomSet = new CustomPermissionsDisplaySettingsConfig(customPermissionsDisplaySettings)
                {
                    SetName = AgentsConstants.Security.PermissionSetName
                };
                customPermissionsDisplaySettings.Add(agentsCustomSet);

                var agentsCustomActions = new SecuredObjectCustomPermissionSet(agentsCustomSet.SecuredObjectCustomPermissionSets)
                {
                    TypeName = typeof(AgentItem).FullName
                };
                agentsCustomSet.SecuredObjectCustomPermissionSets.Add(agentsCustomActions);

                var agentCreateAction = new CustomSecurityAction(agentsCustomActions.CustomSecurityActions)
                {
                    Name             = AgentsConstants.Security.Create,
                    ShowActionInList = false,
                    Title            = string.Empty,
                    ResourceClassId  = string.Empty
                };
                agentsCustomActions.CustomSecurityActions.Add(agentCreateAction);

                var agentModifyAction = new CustomSecurityAction(agentsCustomActions.CustomSecurityActions)
                {
                    Name             = AgentsConstants.Security.Modify,
                    ShowActionInList = true,
                    Title            = "ModifyThisAgent",
                    ResourceClassId  = typeof(AgentsResources).Name
                };
                agentsCustomActions.CustomSecurityActions.Add(agentModifyAction);

                var agentViewAction = new CustomSecurityAction(agentsCustomActions.CustomSecurityActions)
                {
                    Name             = AgentsConstants.Security.View,
                    ShowActionInList = true,
                    Title            = "ViewThisAgent",
                    ResourceClassId  = typeof(AgentsResources).Name
                };
                agentsCustomActions.CustomSecurityActions.Add(agentViewAction);

                var agentDeleteAction = new CustomSecurityAction(agentsCustomActions.CustomSecurityActions)
                {
                    Name             = AgentsConstants.Security.Delete,
                    ShowActionInList = true,
                    Title            = "DeleteThisAgent",
                    ResourceClassId  = typeof(AgentsResources).Name
                };
                agentsCustomActions.CustomSecurityActions.Add(agentDeleteAction);

                var agentChangeOwnerAction = new CustomSecurityAction(agentsCustomActions.CustomSecurityActions)
                {
                    Name             = AgentsConstants.Security.ChangeOwner,
                    ShowActionInList = true,
                    Title            = "ChangeOwnerOfThisAgent",
                    ResourceClassId  = typeof(AgentsResources).Name
                };
                agentsCustomActions.CustomSecurityActions.Add(agentChangeOwnerAction);

                var agentChangePermissionsAction = new CustomSecurityAction(agentsCustomActions.CustomSecurityActions)
                {
                    Name             = AgentsConstants.Security.ChangePermissions,
                    ShowActionInList = true,
                    Title            = "ChangePermissionsOfThisAgent",
                    ResourceClassId  = typeof(AgentsResources).Name
                };
                agentsCustomActions.CustomSecurityActions.Add(agentChangePermissionsAction);
            }
        }
Beispiel #3
0
        private void InstallCustomPermissions(SiteInitializer initializer)
        {
            SecurityConfig securityConfig = initializer.Context.GetConfig <SecurityConfig>();
            ConfigElementDictionary <string, Telerik.Sitefinity.Security.Configuration.Permission> permissionSetConfig = securityConfig.Permissions;
            ConfigElementDictionary <string, CustomPermissionsDisplaySettingsConfig> CustomPermissionsDisplaySettings  = securityConfig.CustomPermissionsDisplaySettings;

            //Add the set
            if (!permissionSetConfig.ContainsKey(RealEstateConstants.Security.PermissionSetName))
            {
                var realEstatePermissionSet = new Telerik.Sitefinity.Security.Configuration.Permission(permissionSetConfig)
                {
                    Name            = RealEstateConstants.Security.PermissionSetName,
                    Title           = "RealEstatePermissions",
                    Description     = "RealEstatePermissionsDescription",
                    ResourceClassId = typeof(RealEstateResources).Name
                };
                permissionSetConfig.Add(realEstatePermissionSet);

                realEstatePermissionSet.Actions.Add(new SecurityAction(realEstatePermissionSet.Actions)
                {
                    Name            = RealEstateConstants.Security.View,
                    Type            = SecurityActionTypes.View,
                    Title           = "ViewItems",
                    Description     = "ViewItemsDescription",
                    ResourceClassId = typeof(RealEstateResources).Name
                });
                realEstatePermissionSet.Actions.Add(new SecurityAction(realEstatePermissionSet.Actions)
                {
                    Name            = RealEstateConstants.Security.Create,
                    Type            = SecurityActionTypes.Create,
                    Title           = "CreateItems",
                    Description     = "CreateItemsDescription",
                    ResourceClassId = typeof(RealEstateResources).Name
                });
                realEstatePermissionSet.Actions.Add(new SecurityAction(realEstatePermissionSet.Actions)
                {
                    Name            = RealEstateConstants.Security.Modify,
                    Type            = SecurityActionTypes.Modify,
                    Title           = "ModifyItems",
                    Description     = "ModifyItemsDescription",
                    ResourceClassId = typeof(RealEstateResources).Name
                });
                realEstatePermissionSet.Actions.Add(new SecurityAction(realEstatePermissionSet.Actions)
                {
                    Name            = RealEstateConstants.Security.Delete,
                    Type            = SecurityActionTypes.Delete,
                    Title           = "DeleteItems",
                    Description     = "DeleteItemsDescription",
                    ResourceClassId = typeof(RealEstateResources).Name
                });
                realEstatePermissionSet.Actions.Add(new SecurityAction(realEstatePermissionSet.Actions)
                {
                    Name            = RealEstateConstants.Security.ChangeOwner,
                    Type            = SecurityActionTypes.ChangeOwner,
                    Title           = "ChangeItemOwner",
                    Description     = "ChangeItemOwnerDescription",
                    ResourceClassId = typeof(RealEstateResources).Name
                });
                realEstatePermissionSet.Actions.Add(new SecurityAction(realEstatePermissionSet.Actions)
                {
                    Name            = RealEstateConstants.Security.ChangePermissions,
                    Type            = SecurityActionTypes.ChangePermissions,
                    Title           = "ChangeItemPermissions",
                    Description     = "ChangeItemPermissionsDescription",
                    ResourceClassId = typeof(RealEstateResources).Name
                });
            }

            //Custom UI views
            if (!CustomPermissionsDisplaySettings.ContainsKey(RealEstateConstants.Security.PermissionSetName))
            {
                var realEstateCustomSet = new CustomPermissionsDisplaySettingsConfig(CustomPermissionsDisplaySettings)
                {
                    SetName = RealEstateConstants.Security.PermissionSetName
                };
                CustomPermissionsDisplaySettings.Add(realEstateCustomSet);

                var realEstateCustomActions = new SecuredObjectCustomPermissionSet(realEstateCustomSet.SecuredObjectCustomPermissionSets)
                {
                    TypeName = typeof(RealEstateItem).FullName
                };
                realEstateCustomSet.SecuredObjectCustomPermissionSets.Add(realEstateCustomActions);

                var itemCreateAction = new CustomSecurityAction(realEstateCustomActions.CustomSecurityActions)
                {
                    Name             = RealEstateConstants.Security.Create,
                    ShowActionInList = false,
                    Title            = string.Empty,
                    ResourceClassId  = string.Empty
                };
                realEstateCustomActions.CustomSecurityActions.Add(itemCreateAction);

                var itemModifyAction = new CustomSecurityAction(realEstateCustomActions.CustomSecurityActions)
                {
                    Name             = RealEstateConstants.Security.Modify,
                    ShowActionInList = true,
                    Title            = "ModifyThisItem",
                    ResourceClassId  = typeof(RealEstateResources).Name
                };
                realEstateCustomActions.CustomSecurityActions.Add(itemModifyAction);

                var itemViewAction = new CustomSecurityAction(realEstateCustomActions.CustomSecurityActions)
                {
                    Name             = RealEstateConstants.Security.View,
                    ShowActionInList = true,
                    Title            = "ViewThisItem",
                    ResourceClassId  = typeof(RealEstateResources).Name
                };
                realEstateCustomActions.CustomSecurityActions.Add(itemViewAction);

                var itemDeleteAction = new CustomSecurityAction(realEstateCustomActions.CustomSecurityActions)
                {
                    Name             = RealEstateConstants.Security.Delete,
                    ShowActionInList = true,
                    Title            = "DeleteThisItem",
                    ResourceClassId  = typeof(RealEstateResources).Name
                };
                realEstateCustomActions.CustomSecurityActions.Add(itemDeleteAction);

                var itemChangeOwnerAction = new CustomSecurityAction(realEstateCustomActions.CustomSecurityActions)
                {
                    Name             = RealEstateConstants.Security.ChangeOwner,
                    ShowActionInList = true,
                    Title            = "ChangeOwnerOfThisItem",
                    ResourceClassId  = typeof(RealEstateResources).Name
                };
                realEstateCustomActions.CustomSecurityActions.Add(itemChangeOwnerAction);

                var itemChangePermissionsAction = new CustomSecurityAction(realEstateCustomActions.CustomSecurityActions)
                {
                    Name             = RealEstateConstants.Security.ChangePermissions,
                    ShowActionInList = true,
                    Title            = "ChangePermissionsOfThisItem",
                    ResourceClassId  = typeof(RealEstateResources).Name
                };
                realEstateCustomActions.CustomSecurityActions.Add(itemChangePermissionsAction);
            }
        }