Ejemplo n.º 1
0
        /// <summary>
        /// 获取可以访问的域
        /// </summary>
        /// <param name="userPermissions"></param>
        /// <returns></returns>
        public List <UserScopeAccessAuthority> GetUserScopeAccessAuthorities(IEnumerable <Permission> userPermissions)
        {
            Expression <Func <ApiScope, object> >[] propertySelectors = new Expression <Func <ApiScope, object> >[] {
                e => e.ApiManageScope,
                e => e.ApiManageScope.ApiScopePermissions,
                e => e.ApiQueryScope,
                e => e.ApiQueryScope.ApiScopePermissions
            };
            var apiScopes = ApiScopeRepository.GetAllIncluding(propertySelectors).ToList();

            List <UserScopeAccessAuthority> userScopeAccessAuthoritys = new List <UserScopeAccessAuthority>();
            List <int> permissionIds = userPermissions.Select(e => e.Id).ToList();

            foreach (var apiScope in apiScopes)
            {
                bool manageAuthority = apiScope.ApiManageScope.IsAllowAccess(userPermissions);
                bool queryAuthority  = apiScope.ApiQueryScope.IsAllowAccess(userPermissions);

                if (manageAuthority || queryAuthority)
                {
                    userScopeAccessAuthoritys.Add(new UserScopeAccessAuthority(apiScope.Name, manageAuthority, queryAuthority));
                }
            }

            return(userScopeAccessAuthoritys);
        }
Ejemplo n.º 2
0
        public void AddQueryPermission(int apiScopeId, int permissionId)
        {
            Expression <Func <ApiScope, object> >[] propertySelectors = new Expression <Func <ApiScope, object> >[] {
                e => e.ApiQueryScope
            };
            var apiScope = ApiScopeRepository.GetAllIncluding(propertySelectors).FirstOrDefault(e => e.Id == apiScopeId);

            if (apiScope == null)
            {
                throw new Exception("找不到Api域");
            }

            var permission = _permissionManager.PermissionRepository.FirstOrDefault(permissionId);

            if (permission == null)
            {
                throw new Exception("找不到要添加的权限");
            }

            apiScope.ApiQueryScope.AddPermission(permission);
        }
Ejemplo n.º 3
0
 public IQueryable <ApiScope> GetApiScopes(Expression <Func <ApiScope, object> >[] propertySelectors)
 {
     return(ApiScopeRepository.GetAllIncluding(propertySelectors));
 }