Пример #1
0
        private bool IsValidRole(SecurityPermission permission, ISecurityQuery query)
        {
            if (query.CreatorRole.HasValue && query.Page.HasValue)
            {
                var rule = permission.Rules.First(x => x.Page == query.Page);
                return(rule.IsEditable && (query.Member.CurrentRole == query.CreatorRole.Value || rule.EditRoleList.Contains(query.Member.CurrentRole)));
            }

            return(permission.Rules.Any(x => x.ViewRoleList.Contains(query.Member.CurrentRole)));
        }
Пример #2
0
 private bool IsAllowedPermission(SecurityPermission permission, ISecurityQuery query)
 {
     return(IsValidMember(query.Member) &&
            IsValidWeek(query.DayAssignDate) &&
            IsValidDayAssignStatus(query.DayAssignStatus) &&
            IsValidUserRoleList(permission, query) &&
            IsValidUserPlatform(permission, query) &&
            IsValidRole(permission, query) &&
            IsValidTab(permission, query) &&
            IsValidForGroupedTask(permission, query));
 }
Пример #3
0
        private bool HasAccess(ISecurityQuery query, SecurityPermission permission)
        {
            if (permission == null)
            {
                return(false);
            }

            var result = IsAllowedPermission(permission, query);

            return(result);
        }
Пример #4
0
        private bool IsValidForGroupedTask(SecurityPermission permission, ISecurityQuery query)
        {
            var rule = permission.Rules.FirstOrDefault(x => x.Page == query.Page);

            if (rule == null || !rule.IsDisabledForGroupingTask)
            {
                return(true);
            }

            return(!query.IsGroupedTask);
        }
Пример #5
0
        private bool IsValidTab(SecurityPermission permission, ISecurityQuery query)
        {
            if (!query.Page.HasValue)
            {
                return(true);
            }

            var rule = permission.Rules.First(x => x.Page == query.Page);

            return(rule.ViewRoleList.Contains(query.Member.CurrentRole));
        }
Пример #6
0
        private bool IsValidUserPlatform(SecurityPermission permission, ISecurityQuery query)
        {
            if (permission.Rules.All(x => x.AllowedPlatformList.Count == 0) || !query.CurrentPlatformType.HasValue)
            {
                return(true);
            }

            bool result = permission.Rules.Any(x => x.AllowedPlatformList.Contains(query.CurrentPlatformType.Value));

            return(result);
        }
Пример #7
0
        private bool IsValidUserRoleList(SecurityPermission permission, ISecurityQuery query)
        {
            if (!permission.Rules.Any(x => x.IsUserShouldHaveAllRoles))
            {
                return(true);
            }

            Rule rule   = permission.Rules.First(x => x.IsUserShouldHaveAllRoles);
            bool result = rule.UserRoleList.All(s => query.Member.Roles.Contains(s));

            return(result);
        }
Пример #8
0
        public Dictionary <string, bool> HasAccessByGroupName(ISecurityQuery query)
        {
            var permissionList = Get(query.GroupName).ToList();

            return(permissionList.ToDictionary(permission => permission.Key, permission => HasAccess(query, permission)));
        }