Ejemplo n.º 1
0
        /// <summary>
        /// 修改用户授权
        /// </summary>
        /// <param name="userAuthorizes">用户授权信息</param>
        /// <returns></returns>
        public Result ModifyUserAuthorize(IEnumerable <UserAuthorize> userAuthorizes)
        {
            if (userAuthorizes.IsNullOrEmpty())
            {
                return(Result.FailedResult("没有指定任何要修改的用户授权信息"));
            }

            #region 角色授权

            List <long> userIds           = userAuthorizes.Select(c => c.User?.SysNo ?? 0).Distinct().ToList();
            IQuery      userRoleBindQuery = QueryFactory.Create <UserRoleQuery>(c => userIds.Contains(c.UserSysNo));
            userRoleBindQuery.AddQueryFields <UserRoleQuery>(c => c.RoleSysNo);
            IQuery roleAuthBindQuery = QueryFactory.Create <RoleAuthorizeQuery>();
            roleAuthBindQuery.And <RoleAuthorizeQuery>(c => c.Role, CriteriaOperator.In, userRoleBindQuery);
            roleAuthBindQuery.AddQueryFields <RoleAuthorizeQuery>(c => c.Authority);
            IQuery authQuery = QueryFactory.Create <AuthorityQuery>();
            authQuery.And <AuthorityQuery>(c => c.Code, CriteriaOperator.In, roleAuthBindQuery);
            authQuery.AddQueryFields <AuthorityQuery>(c => c.Code);
            IEnumerable <Authority> roleAuthoritys     = authorityService.GetAuthorityList(authQuery);
            List <string>           roleAuthorityCodes = roleAuthoritys.Select(c => c.Code).ToList();

            #endregion

            List <UserAuthorize> saveUserAuthorizes = new List <UserAuthorize>();
            userAuthRepository.Remove(userAuthorizes.ToArray());                                                                                      //移除授权数据
            List <UserAuthorize> disableAuthorizes = userAuthorizes.Where(c => c.Disable && roleAuthorityCodes.Contains(c.Authority?.Code)).ToList(); //角色拥有但是用户显示禁用掉的授权
            if (!disableAuthorizes.IsNullOrEmpty())
            {
                saveUserAuthorizes.AddRange(disableAuthorizes);
            }
            List <UserAuthorize> enableAuthorizes = userAuthorizes.Where(c => !c.Disable && !roleAuthorityCodes.Contains(c.Authority?.Code)).ToList();//用户单独授权的权限
            if (!enableAuthorizes.IsNullOrEmpty())
            {
                saveUserAuthorizes.AddRange(enableAuthorizes);
            }
            if (!saveUserAuthorizes.IsNullOrEmpty())
            {
                userAuthRepository.Save(saveUserAuthorizes.ToArray());
            }
            return(Result.SuccessResult("修改成功"));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 获取权限列表
        /// </summary>
        /// <param name="filter">查询对象</param>
        /// <returns></returns>
        public List <AuthorityDto> GetAuthorityList(AuthorityFilterDto filter)
        {
            var authorityList = authorityService.GetAuthorityList(CreateAuthorityQueryObject(filter));

            return(authorityList.Select(c => c.MapTo <AuthorityDto>()).ToList());
        }