private static Dictionary <Guid, PermissionRuleSet> CalculatePermissions(CmsPageLocationNode siteStructure, ILookup <Guid, PermissionRule> allPermissions, PermissionRuleSet defaultPermissions) { Dictionary <Guid, PermissionRuleSet> newRules = new Dictionary <Guid, PermissionRuleSet>(); var permissionsForPage = allPermissions[siteStructure.PageId].ToList(); if (!permissionsForPage.Any()) { newRules.Add(siteStructure.PageId, new PermissionRuleSet(defaultPermissions)); } else { newRules.Add(siteStructure.PageId, new PermissionRuleSet(permissionsForPage)); } foreach (var childNode in siteStructure.ChildNodes) { var subDict = CalculatePermissions(childNode, allPermissions, newRules[siteStructure.PageId]); foreach (var kvp in subDict) { newRules.Add(kvp.Key, kvp.Value); } } return(newRules); }
private static Dictionary <Guid, PermissionRuleSet> CalculatePermissionsForSite(Site site, ILookup <Guid, PermissionRule> allPermissions) { PermissionRuleSet defaultPermissions; if (site.IsFrontendSite) { defaultPermissions = new PermissionRuleSet(); var readRule = new PermissionRule { AppliesToRoleName = "Everyone", PermissionType = PermissionType.Grant, PrivilegeName = KnownPrivilegeNames.Read }; var createRule = new PermissionRule { AppliesToRoleName = "Everyone", PermissionType = PermissionType.Deny, PrivilegeName = KnownPrivilegeNames.Create }; var updateRule = new PermissionRule { AppliesToRoleName = "Everyone", PermissionType = PermissionType.Deny, PrivilegeName = KnownPrivilegeNames.Update }; var deleteRule = new PermissionRule { AppliesToRoleName = "Everyone", PermissionType = PermissionType.Deny, PrivilegeName = KnownPrivilegeNames.Delete }; defaultPermissions.Add(readRule); defaultPermissions.Add(createRule); defaultPermissions.Add(updateRule); defaultPermissions.Add(deleteRule); } else { defaultPermissions = new PermissionRuleSet(); var readRule = new PermissionRule { AppliesToRoleName = "BackendUsers", PermissionType = PermissionType.Grant, PrivilegeName = KnownPrivilegeNames.Read }; var createRule = new PermissionRule { AppliesToRoleName = "BackendUsers", PermissionType = PermissionType.Grant, PrivilegeName = KnownPrivilegeNames.Create }; var updateRule = new PermissionRule { AppliesToRoleName = "BackendUsers", PermissionType = PermissionType.Grant, PrivilegeName = KnownPrivilegeNames.Update }; var deleteRule = new PermissionRule { AppliesToRoleName = "BackendUsers", PermissionType = PermissionType.Grant, PrivilegeName = KnownPrivilegeNames.Delete }; defaultPermissions.Add(readRule); defaultPermissions.Add(createRule); defaultPermissions.Add(updateRule); defaultPermissions.Add(deleteRule); } var siteStructure = SiteStructureMapBuilder.BuildStructureMap(site); Dictionary <Guid, PermissionRuleSet> newRules = new Dictionary <Guid, PermissionRuleSet>(); foreach (var page in siteStructure.ChildNodes) { var subDict = CalculatePermissions(page, allPermissions, defaultPermissions); foreach (var kvp in subDict) { newRules.Add(kvp.Key, kvp.Value); } } return(newRules); }