Пример #1
0
 /// <exclude />
 public static IEnumerable <string> GetSerializedEntityTokens(string username)
 {
     foreach (Guid userGroupId in UserGroupFacade.GetUserGroupIds(username))
     {
         foreach (string serializedEntityToken in GetSerializedEntityTokens(userGroupId))
         {
             yield return(serializedEntityToken);
         }
     }
 }
Пример #2
0
        /// <exclude />
        public static IEnumerable <UserGroupPermissionDefinition> GetUserGroupPermissionDefinitions(string username)
        {
            List <Guid> userGroupIds = UserGroupFacade.GetUserGroupIds(username);

            foreach (Guid userGroupId in userGroupIds)
            {
                foreach (UserGroupPermissionDefinition userGroupPermissionDefinition in GetUserGroupPermissionDefinitions(userGroupId))
                {
                    yield return(userGroupPermissionDefinition);
                }
            }
        }
Пример #3
0
        /// <exclude />
        public static IEnumerable <PermissionType> GetLocallyDefinedUserGroupPermissionTypes(string username, EntityToken entityToken)
        {
            List <Guid> userGroupIds = UserGroupFacade.GetUserGroupIds(username);

            IEnumerable <PermissionType> permissionTypes = new List <PermissionType>();

            foreach (Guid userGroupId in userGroupIds)
            {
                IEnumerable <PermissionType> localPermissionTypes = GetLocallyDefinedUserGroupPermissionTypes(userGroupId, entityToken);
                permissionTypes = permissionTypes.Concat(localPermissionTypes);
            }

            return(permissionTypes.Distinct());
        }
Пример #4
0
        /// <summary>
        /// This returns a merged result of user permissions and user group permissions
        /// </summary>
        /// <param name="userToken"></param>
        /// <param name="entityToken"></param>
        /// <param name="presetUserGroupPermissions">
        /// This is used for simulating that local defined user group permissions has been set
        /// </param>
        /// <returns></returns>
        public static IEnumerable <PermissionType> GetInheritedPermissionsTypes(UserToken userToken, EntityToken entityToken, Dictionary <Guid, IEnumerable <PermissionType> > presetUserGroupPermissions)
        {
            if (userToken == null)
            {
                throw new ArgumentNullException("userToken");
            }
            if (entityToken == null)
            {
                throw new ArgumentNullException("entityToken");
            }

            IEnumerable <PermissionType> permissionTypes = PermissionTypeFacadeCaching.GetInheritedPermissionsTypes(userToken, entityToken);

            if (permissionTypes != null)
            {
                return(permissionTypes);
            }

            if (presetUserGroupPermissions == null || presetUserGroupPermissions.Count == 0)
            {
                ICollection <PermissionType> localDefinedUserGroupPermissionTypes = GetLocallyDefinedUserGroupPermissionTypes(userToken.Username, entityToken).Evaluate();
                if (localDefinedUserGroupPermissionTypes.Count > 0)
                {
                    PermissionTypeFacadeCaching.SetInheritedPermissionsTypes(userToken, entityToken, localDefinedUserGroupPermissionTypes.ToList());
                    return(localDefinedUserGroupPermissionTypes);
                }
            }
            else
            {
                List <Guid> userGroupIds = UserGroupFacade.GetUserGroupIds(userToken.Username);

                var localDefinedUserGroupPermissionTypes = new List <PermissionType>();
                foreach (Guid userGroupId in userGroupIds)
                {
                    IEnumerable <PermissionType> groupPermissionTypes;
                    if (presetUserGroupPermissions.TryGetValue(userGroupId, out groupPermissionTypes))
                    {
                        localDefinedUserGroupPermissionTypes.AddRange(groupPermissionTypes);
                    }
                }

                if (localDefinedUserGroupPermissionTypes.Contains(PermissionType.ClearPermissions))
                {
                    return(new PermissionType[0]);
                }

                return(localDefinedUserGroupPermissionTypes.Distinct());
            }

            ICollection <UserPermissionDefinition>      userPermissionDefinitions      = GetUserPermissionDefinitions(userToken.Username).Evaluate();
            ICollection <UserGroupPermissionDefinition> userGroupPermissionDefinitions = GetUserGroupPermissionDefinitions(userToken.Username).Evaluate();

            List <EntityToken> parentEntityTokens = ParentsFacade.GetAllParents(entityToken);

            foreach (EntityToken parentEntityToken in parentEntityTokens)
            {
                RecursiveUpdateCurrentUserPermissionTypes(userToken, parentEntityToken, userPermissionDefinitions, new HashSet <EntityTokenPair>());
                RecursiveUpdateCurrentUserGroupPermissionTypes(userToken, parentEntityToken, userGroupPermissionDefinitions, new HashSet <EntityTokenPair>());
            }


            if (!PermissionTypeFacadeCaching.CachingWorking)
            {
                throw new InvalidOperationException("RequestLifetimeCache is not operational");
            }


            permissionTypes = new List <PermissionType>();
            foreach (EntityToken parentEntityToken in parentEntityTokens)
            {
                IEnumerable <PermissionType> parentUserPermissionTypes = PermissionTypeFacadeCaching.GetUserPermissionTypes(userToken, parentEntityToken);
                if (parentUserPermissionTypes != null)
                {
                    permissionTypes = permissionTypes.Concat(parentUserPermissionTypes);
                }

                IEnumerable <PermissionType> parentUserGroupPermissionTypes = PermissionTypeFacadeCaching.GetUserGroupPermissionTypes(userToken, parentEntityToken);
                if (parentUserGroupPermissionTypes != null)
                {
                    permissionTypes = permissionTypes.Concat(parentUserGroupPermissionTypes);
                }
            }

            var distinctPermissionTypes = permissionTypes.Distinct().ToList();

            PermissionTypeFacadeCaching.SetInheritedPermissionsTypes(userToken, entityToken, distinctPermissionTypes);

            return(distinctPermissionTypes);
        }