Example #1
0
        public List <Sys_Permission> GetList(Guid userId)
        {
            //a.根据用户ID查询角色ID集合 (一对多关系)
            var listRoleIds = _userRoleRelationRepository.GetList(userId).Select(c => c.RoleId).ToList();
            //b.根据角色ID查询权限ID集合 (多对多关系)
            var listModuleIds = _roleAuthorizeRepository.GetList().Where(c => listRoleIds.Contains(c.RoleId)).Select(c => c.ModuleId).ToList();

            //c.根据权限ID集合查询所有权限实体。
            return(_permissionRepository.GetList().Where(c => listModuleIds.Contains(c.Id) && c.IsEnable == true).ToList());
        }
Example #2
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 = QueryManager.Create <UserRoleQuery>(c => userIds.Contains(c.UserSysNo));

            //角色授权
            IQuery roleAuthBindQuery = QueryManager.Create <RoleAuthorizeQuery>();
            roleAuthBindQuery.EqualInnerJoin(userRoleBindQuery);

            List <long> roleAuthorityIds = roleAuthRepository.GetList(roleAuthBindQuery).Select(c => c.Item2.SysNo).ToList();

            #endregion

            //移除当前存在的授权数据
            userAuthRepository.Remove(userAuthorizes, new ActivationOption()
            {
                ForceExecute = true
            });
            var saveUserAuthorizes = new List <UserAuthorize>();
            //角色拥有但是用户显示禁用掉的授权
            var disableAuthorizes = userAuthorizes.Where(c => c.Disable && roleAuthorityIds.Contains(c.Authority.SysNo)).ToList();
            if (!disableAuthorizes.IsNullOrEmpty())
            {
                saveUserAuthorizes.AddRange(disableAuthorizes);
            }
            //用户单独授权的权限
            var enableAuthorizes = userAuthorizes.Where(c => !c.Disable && !roleAuthorityIds.Contains(c.Authority.SysNo)).ToList();
            if (!enableAuthorizes.IsNullOrEmpty())
            {
                saveUserAuthorizes.AddRange(enableAuthorizes);
            }
            if (!saveUserAuthorizes.IsNullOrEmpty())
            {
                userAuthRepository.Save(saveUserAuthorizes.ToArray());
            }
            return(Result.SuccessResult("修改成功"));
        }
Example #3
0
 public List <RoleAuthorizeEntity> GetList(string ObjectId)
 {
     return(service.GetList(t => t.F_ObjectId == ObjectId).ToList());
 }
 public List <Sys_RoleAuthorize> GetList(string roleId)
 {
     return(_roleAuthorizeRepository.GetList(roleId));
 }