public EqualsWithVersionIgnore ( object obj ) : bool | ||
obj | object | |
return | bool |
private static IReadOnlyCollection <PermissionType> RecursiveUpdateCurrentUserPermissionTypes(UserToken userToken, EntityToken entityToken, IEnumerable <UserPermissionDefinition> userPermissionDefinitions, HashSet <EntityTokenPair> alreadyProcessedTokens) { IReadOnlyCollection <PermissionType> 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 thisPermisstionTypes = new List <PermissionType>(); if (userPermissionDefinition != null) { thisPermisstionTypes.AddRange(userPermissionDefinition.PermissionTypes); } if (thisPermisstionTypes.Count > 0) { thisPermisstionTypes = thisPermisstionTypes.Distinct().ToList(); if (thisPermisstionTypes.Contains(PermissionType.ClearPermissions)) { thisPermisstionTypes = new List <PermissionType>(); } PermissionTypeFacadeCaching.SetUserPermissionTypes(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 = RecursiveUpdateCurrentUserPermissionTypes(userToken, parentEntityToken, userPermissionDefinitions, alreadyProcessedTokens); parentsPermisstionTypes = parentsPermisstionTypes.Concat(thisParentPermisstionTypes); } } List <PermissionType> permisstionTypes = parentsPermisstionTypes.Distinct().ToList(); PermissionTypeFacadeCaching.SetUserPermissionTypes(userToken, entityToken, permisstionTypes); return(permisstionTypes); }
private static IEnumerable <PermissionType> GetInheritedGroupPermissionsTypesRecursivly(EntityToken entityToken, IEnumerable <UserGroupPermissionDefinition> userGroupPermissionDefinitions, List <EntityToken> visitedParents = null) { UserGroupPermissionDefinition selectedUserGroupPermissionDefinition = userGroupPermissionDefinitions.Where(f => entityToken.EqualsWithVersionIgnore(f.EntityToken)).SingleOrDefault(); if (selectedUserGroupPermissionDefinition != null) { if (selectedUserGroupPermissionDefinition.PermissionTypes.Contains(PermissionType.ClearPermissions) == false) { foreach (PermissionType permissionType in selectedUserGroupPermissionDefinition.PermissionTypes) { yield return(permissionType); } } yield break; } List <EntityToken> parentEntityTokens = ParentsFacade.GetAllParents(entityToken); if (visitedParents == null) { visitedParents = new List <EntityToken>(); } IEnumerable <PermissionType> parentsPermisstionTypes = new List <PermissionType>(); foreach (EntityToken parentEntityToken in parentEntityTokens) { if (visitedParents.Contains(parentEntityToken)) { continue; } visitedParents.Add(parentEntityToken); IEnumerable <PermissionType> result = GetInheritedGroupPermissionsTypesRecursivly(parentEntityToken, userGroupPermissionDefinitions, visitedParents).ToList(); parentsPermisstionTypes = parentsPermisstionTypes.Concat(result); } foreach (PermissionType permissionType in parentsPermisstionTypes.Distinct()) { yield return(permissionType); } }
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; }
private static IEnumerable<PermissionType> GetInheritedGroupPermissionsTypesRecursivly(EntityToken entityToken, IEnumerable<UserGroupPermissionDefinition> userGroupPermissionDefinitions, List<EntityToken> visitedParents = null) { UserGroupPermissionDefinition selectedUserGroupPermissionDefinition = userGroupPermissionDefinitions.Where(f => entityToken.EqualsWithVersionIgnore(f.EntityToken)).SingleOrDefault(); if (selectedUserGroupPermissionDefinition != null) { if (selectedUserGroupPermissionDefinition.PermissionTypes.Contains(PermissionType.ClearPermissions) == false) { foreach (PermissionType permissionType in selectedUserGroupPermissionDefinition.PermissionTypes) { yield return permissionType; } } yield break; } List<EntityToken> parentEntityTokens = ParentsFacade.GetAllParents(entityToken); if (visitedParents == null) { visitedParents = new List<EntityToken>(); } IEnumerable<PermissionType> parentsPermisstionTypes = new List<PermissionType>(); foreach (EntityToken parentEntityToken in parentEntityTokens) { if (visitedParents.Contains(parentEntityToken)) continue; visitedParents.Add(parentEntityToken); IEnumerable<PermissionType> result = GetInheritedGroupPermissionsTypesRecursivly(parentEntityToken, userGroupPermissionDefinitions, visitedParents).ToList(); parentsPermisstionTypes = parentsPermisstionTypes.Concat(result); } foreach (PermissionType permissionType in parentsPermisstionTypes.Distinct()) { yield return permissionType; } }
private static IReadOnlyCollection <PermissionType> RecursiveUpdateCurrentUserGroupPermissionTypes(UserToken userToken, EntityToken entityToken, IEnumerable <UserGroupPermissionDefinition> userGroupPermissionDefinitions, HashSet <EntityTokenPair> alreadyProcessedTokens) { var cached = PermissionTypeFacadeCaching.GetUserGroupPermissionTypes(userToken, entityToken); if (cached != null) { return(cached); } var selectedUserGroupPermissionDefinitions = userGroupPermissionDefinitions.Where(f => entityToken.EqualsWithVersionIgnore(f.EntityToken)); var thisPermissionTypes = new List <PermissionType>(); foreach (var userGroupPermissionDefinition in selectedUserGroupPermissionDefinitions) { List <PermissionType> groupPermissionTypes = userGroupPermissionDefinition.PermissionTypes.ToList(); thisPermissionTypes.AddRange(groupPermissionTypes); } if (thisPermissionTypes.Count > 0) { thisPermissionTypes = thisPermissionTypes.Distinct().ToList(); if (thisPermissionTypes.Contains(PermissionType.ClearPermissions)) { thisPermissionTypes = new List <PermissionType>(); } PermissionTypeFacadeCaching.SetUserGroupPermissionTypes(userToken, entityToken, thisPermissionTypes); // Local defined permission overrules all other permissions return(thisPermissionTypes); } // Call resursively on all parents List <EntityToken> parentEntityTokens = ParentsFacade.GetAllParents(entityToken); var parentsPermissionTypes = Enumerable.Empty <PermissionType>(); foreach (EntityToken parentEntityToken in parentEntityTokens) { var pair = new EntityTokenPair(entityToken, parentEntityToken); if (alreadyProcessedTokens.Contains(pair)) { continue; } alreadyProcessedTokens.Add(pair); var thisParentPermissionTypes = RecursiveUpdateCurrentUserGroupPermissionTypes(userToken, parentEntityToken, userGroupPermissionDefinitions, alreadyProcessedTokens); var filteredPermissionTypes = FilterParentPermissions(userToken, entityToken, thisParentPermissionTypes); parentsPermissionTypes = parentsPermissionTypes.Concat(filteredPermissionTypes); } List <PermissionType> permissionTypes = parentsPermissionTypes.Distinct().ToList(); PermissionTypeFacadeCaching.SetUserGroupPermissionTypes(userToken, entityToken, permissionTypes); return(permissionTypes); }