private static IReadOnlyCollection <PermissionType> RecursiveUpdateCurrentUserGroupPermissionTypes(UserToken userToken, EntityToken entityToken, IEnumerable <UserGroupPermissionDefinition> userGroupPermissionDefinitions, HashSet <EntityTokenPair> alreadyProcessedTokens) { IReadOnlyCollection <PermissionType> cached = PermissionTypeFacadeCaching.GetUserGroupPermissionTypes(userToken, entityToken); if (cached != null) { return(cached); } IEnumerable <UserGroupPermissionDefinition> selectedUserGroupPermissionDefinitions = userGroupPermissionDefinitions.Where(f => entityToken.EqualsWithVersionIgnore(f.EntityToken)); List <PermissionType> thisPermisstionTypes = new List <PermissionType>(); foreach (UserGroupPermissionDefinition userGroupPermissionDefinition in selectedUserGroupPermissionDefinitions) { List <PermissionType> groupPermissionTypes = userGroupPermissionDefinition.PermissionTypes.ToList(); thisPermisstionTypes.AddRange(groupPermissionTypes); } if (thisPermisstionTypes.Count > 0) { thisPermisstionTypes = thisPermisstionTypes.Distinct().ToList(); if (thisPermisstionTypes.Contains(PermissionType.ClearPermissions)) { thisPermisstionTypes = new List <PermissionType>(); } PermissionTypeFacadeCaching.SetUserGroupPermissionTypes(userToken, entityToken, thisPermisstionTypes); // Local defined permission overrules all other permissions return(thisPermisstionTypes); } // Call resursively on all parents List <EntityToken> parentEntityTokens = ParentsFacade.GetAllParents(entityToken); IEnumerable <PermissionType> parentsPermisstionTypes = new List <PermissionType>(); foreach (EntityToken parentEntityToken in parentEntityTokens) { EntityTokenPair pair = new EntityTokenPair(entityToken, parentEntityToken); if (alreadyProcessedTokens.Contains(pair) == false) { alreadyProcessedTokens.Add(pair); IEnumerable <PermissionType> thisParentPermisstionTypes = RecursiveUpdateCurrentUserGroupPermissionTypes(userToken, parentEntityToken, userGroupPermissionDefinitions, alreadyProcessedTokens); parentsPermisstionTypes = parentsPermisstionTypes.Concat(thisParentPermisstionTypes); } } List <PermissionType> permisstionTypes = parentsPermisstionTypes.Distinct().ToList(); PermissionTypeFacadeCaching.SetUserGroupPermissionTypes(userToken, entityToken, permisstionTypes); return(permisstionTypes); }
public bool Equals(EntityTokenPair entityTokenPair) { if (entityTokenPair == null) { return(false); } return(this.FirstEntityToken.EqualsWithVersionIgnore(entityTokenPair.FirstEntityToken) && this.SecondEntityToken.EqualsWithVersionIgnore(entityTokenPair.SecondEntityToken)); }
private static IReadOnlyCollection<PermissionType> RecursiveUpdateCurrentUserGroupPermissionTypes(UserToken userToken, EntityToken entityToken, IEnumerable<UserGroupPermissionDefinition> userGroupPermissionDefinitions, HashSet<EntityTokenPair> alreadyProcessedTokens) { IReadOnlyCollection<PermissionType> cached = PermissionTypeFacadeCaching.GetUserGroupPermissionTypes(userToken, entityToken); if (cached != null) { return cached; } IEnumerable<UserGroupPermissionDefinition> selectedUserGroupPermissionDefinitions = userGroupPermissionDefinitions.Where(f => entityToken.Equals(f.EntityToken)); List<PermissionType> thisPermisstionTypes = new List<PermissionType>(); foreach (UserGroupPermissionDefinition userGroupPermissionDefinition in selectedUserGroupPermissionDefinitions) { List<PermissionType> groupPermissionTypes = userGroupPermissionDefinition.PermissionTypes.ToList(); thisPermisstionTypes.AddRange(groupPermissionTypes); } if (thisPermisstionTypes.Count > 0) { thisPermisstionTypes = thisPermisstionTypes.Distinct().ToList(); if (thisPermisstionTypes.Contains(PermissionType.ClearPermissions)) { thisPermisstionTypes = new List<PermissionType>(); } PermissionTypeFacadeCaching.SetUserGroupPermissionTypes(userToken, entityToken, thisPermisstionTypes); // Local defined permission overrules all other permissions return thisPermisstionTypes; } // Call resursively on all parents List<EntityToken> parentEntityTokens = ParentsFacade.GetAllParents(entityToken); IEnumerable<PermissionType> parentsPermisstionTypes = new List<PermissionType>(); foreach (EntityToken parentEntityToken in parentEntityTokens) { EntityTokenPair pair = new EntityTokenPair(entityToken, parentEntityToken); if (alreadyProcessedTokens.Contains(pair) == false) { alreadyProcessedTokens.Add(pair); IEnumerable<PermissionType> thisParentPermisstionTypes = RecursiveUpdateCurrentUserGroupPermissionTypes(userToken, parentEntityToken, userGroupPermissionDefinitions, alreadyProcessedTokens); parentsPermisstionTypes = parentsPermisstionTypes.Concat(thisParentPermisstionTypes); } } List<PermissionType> permisstionTypes = parentsPermisstionTypes.Distinct().ToList(); PermissionTypeFacadeCaching.SetUserGroupPermissionTypes(userToken, entityToken, permisstionTypes); return permisstionTypes; }
public bool Equals(EntityTokenPair entityTokenPair) { if (entityTokenPair == null) return false; return this.FirstEntityToken.Equals(entityTokenPair.FirstEntityToken) && this.SecondEntityToken.Equals(entityTokenPair.SecondEntityToken); }
private static IReadOnlyCollection <PermissionType> RecursiveUpdateCurrentUserPermissionTypes(UserToken userToken, EntityToken entityToken, IEnumerable <UserPermissionDefinition> userPermissionDefinitions, HashSet <EntityTokenPair> alreadyProcessedTokens) { var cached = PermissionTypeFacadeCaching.GetUserPermissionTypes(userToken, entityToken); if (cached != null) { return(cached); } UserPermissionDefinition userPermissionDefinition = userPermissionDefinitions .Where(f => entityToken.EqualsWithVersionIgnore(f.EntityToken)).SingleOrDefaultOrException("More then one UserPermissionDefinition for the same entity token"); var thisPermissionTypes = new List <PermissionType>(); if (userPermissionDefinition != null) { thisPermissionTypes.AddRange(userPermissionDefinition.PermissionTypes); } if (thisPermissionTypes.Count > 0) { thisPermissionTypes = thisPermissionTypes.Distinct().ToList(); if (thisPermissionTypes.Contains(PermissionType.ClearPermissions)) { thisPermissionTypes = new List <PermissionType>(); } PermissionTypeFacadeCaching.SetUserPermissionTypes(userToken, entityToken, thisPermissionTypes); // Local defined permission overrules all other permissions return(thisPermissionTypes); } // Call resursively on all parents var parentEntityTokens = ParentsFacade.GetAllParents(entityToken); var parentsPermissionTypes = Enumerable.Empty <PermissionType>(); foreach (var parentEntityToken in parentEntityTokens) { var pair = new EntityTokenPair(entityToken, parentEntityToken); if (alreadyProcessedTokens.Contains(pair)) { continue; } alreadyProcessedTokens.Add(pair); var thisParentPermissionTypes = RecursiveUpdateCurrentUserPermissionTypes(userToken, parentEntityToken, userPermissionDefinitions, alreadyProcessedTokens); var filteredPermissions = FilterParentPermissions(userToken, parentEntityToken, thisParentPermissionTypes); parentsPermissionTypes = parentsPermissionTypes.Concat(filteredPermissions); } List <PermissionType> permissionTypes = parentsPermissionTypes.Distinct().ToList(); PermissionTypeFacadeCaching.SetUserPermissionTypes(userToken, entityToken, permissionTypes); return(permissionTypes); }