diff --git a/Api/Ewide.Application/Service/HouseSafety/HouseMember/HouseMemberService.cs b/Api/Ewide.Application/Service/HouseSafety/HouseMember/HouseMemberService.cs index a1956b6..309d93b 100644 --- a/Api/Ewide.Application/Service/HouseSafety/HouseMember/HouseMemberService.cs +++ b/Api/Ewide.Application/Service/HouseSafety/HouseMember/HouseMemberService.cs @@ -50,7 +50,7 @@ namespace Ewide.Application.Service [HttpPost("/houseMember/page")] public async Task QueryMemberPageList([FromBody] UserInput input) { - var dataScopes = await _sysUserService.GetUserDataScopeIdList(); + var dataScopes = await _userManager.GetUserAllDataScopeList(); var sql = @"SELECT SU.*, diff --git a/Api/Ewide.Application/Service/HouseSafety/HouseZone/HouseZoneService.cs b/Api/Ewide.Application/Service/HouseSafety/HouseZone/HouseZoneService.cs index 4b9d3f8..e5aac58 100644 --- a/Api/Ewide.Application/Service/HouseSafety/HouseZone/HouseZoneService.cs +++ b/Api/Ewide.Application/Service/HouseSafety/HouseZone/HouseZoneService.cs @@ -72,7 +72,7 @@ namespace Ewide.Application.Service [HttpPost("/houseZone/page")] public async Task QueryZonePageList([FromBody] PageOrgInput input) { - var dataScopeList = _sysOrgService.GetDataScopeList(await _sysOrgService.GetUserDataScopeIdList()); + var dataScopeList = _sysOrgService.GetDataScopeList(await _userManager.GetUserAllDataScopeList()); var name = !string.IsNullOrEmpty(input.Name?.Trim()); var id = !string.IsNullOrEmpty(input.Id?.Trim()); diff --git a/Api/Ewide.Core/Controller/AreaCodeController.cs b/Api/Ewide.Core/Controller/AreaCodeController.cs index ce916f6..57908a7 100644 --- a/Api/Ewide.Core/Controller/AreaCodeController.cs +++ b/Api/Ewide.Core/Controller/AreaCodeController.cs @@ -88,8 +88,7 @@ namespace Ewide.Core.Controller List areaCodeList = null; if (!_userManager.SuperAdmin) { - var orgIdList = await _sysUserService.GetUserDataScopeIdList(); - areaCodeList = await _areaCodeService.GetAreaCodeListByOrgId(orgIdList); + areaCodeList = await _userManager.GetUserAllAreaList(); } return await _areaCodeService.GetAreaCodeTree(level, areaCodeList); } diff --git a/Api/Ewide.Core/Ewide.Core.xml b/Api/Ewide.Core/Ewide.Core.xml index daef599..8e83b57 100644 --- a/Api/Ewide.Core/Ewide.Core.xml +++ b/Api/Ewide.Core/Ewide.Core.xml @@ -2834,6 +2834,12 @@ + + + 获取用户可以访问的区域权限 + + + OAuth配置---此结构方便拓展 @@ -5829,12 +5835,6 @@ - - - 获取用户数据范围(机构Id集合) - - - 职位参数 @@ -6156,14 +6156,6 @@ - - - 根据角色Id集合获取数据范围Id集合 - - - - - 根据角色Id获取角色名称 @@ -6185,6 +6177,13 @@ + + + 获取角色拥有区域Id集合 + + + + 租户参数 @@ -6946,13 +6945,6 @@ - - - 获取用户的数据范围Id集合 - - - - 根据机构Id集合删除对应的用户-数据范围关联信息 @@ -6986,14 +6978,6 @@ - - - 获取用户所有角色的数据范围(组织机构Id集合) - - - - - 根据角色Id删除对应的用户-角色表关联信息 @@ -7147,19 +7131,6 @@ - - - 获取用户数据范围(机构Id集合)并缓存 - - - - - - - 获取用户数据范围(机构Id集合) - - - 检查普通用户数据范围 diff --git a/Api/Ewide.Core/Service/Auth/AuthService.cs b/Api/Ewide.Core/Service/Auth/AuthService.cs index fba2662..0571c5f 100644 --- a/Api/Ewide.Core/Service/Auth/AuthService.cs +++ b/Api/Ewide.Core/Service/Auth/AuthService.cs @@ -169,7 +169,7 @@ namespace Ewide.Core.Service loginOutput.Permissions = await _sysMenuService.GetLoginPermissionList(userId); // 数据范围信息(机构Id集合) - loginOutput.DataScopes = await _sysUserService.GetUserDataScopeIdList(userId); + loginOutput.DataScopes = await _userManager.GetUserAllDataScopeList(); // 具备应用信息(多系统,默认激活一个,可根据系统切换菜单),返回的结果中第一个为激活的系统 loginOutput.Apps = await _sysAppService.GetLoginApps(userId); diff --git a/Api/Ewide.Core/Service/Org/ISysOrgService.cs b/Api/Ewide.Core/Service/Org/ISysOrgService.cs index e77023c..3917eb7 100644 --- a/Api/Ewide.Core/Service/Org/ISysOrgService.cs +++ b/Api/Ewide.Core/Service/Org/ISysOrgService.cs @@ -15,7 +15,6 @@ namespace Ewide.Core.Service Task GetOrgTree([FromQuery] OrgInput input); Task QueryOrgPageList([FromQuery] PageOrgInput input); Task UpdateOrg(UpdateOrgInput input); - Task> GetUserDataScopeIdList(); /// /// 根据区域信息获取单位id /// diff --git a/Api/Ewide.Core/Service/Org/SysOrgService.cs b/Api/Ewide.Core/Service/Org/SysOrgService.cs index da61185..7c15c46 100644 --- a/Api/Ewide.Core/Service/Org/SysOrgService.cs +++ b/Api/Ewide.Core/Service/Org/SysOrgService.cs @@ -51,7 +51,7 @@ namespace Ewide.Core.Service [HttpPost("/sysOrg/page")] public async Task QueryOrgPageList([FromBody] PageOrgInput input) { - var dataScopeList = GetDataScopeList(await GetUserDataScopeIdList()); + var dataScopeList = GetDataScopeList(await _userManager.GetUserAllDataScopeList()); var name = !string.IsNullOrEmpty(input.Name?.Trim()); var id = !string.IsNullOrEmpty(input.Id?.Trim()); @@ -107,7 +107,7 @@ namespace Ewide.Core.Service [HttpGet("/sysOrg/list")] public async Task> GetOrgList([FromQuery] OrgInput input) { - var dataScopeList = GetDataScopeList(await GetUserDataScopeIdList()); + var dataScopeList = GetDataScopeList(await _userManager.GetUserAllDataScopeList()); var pId = !string.IsNullOrEmpty(input.Pid?.Trim()); var orgs = await _sysOrgRep.DetachedEntities @@ -136,7 +136,7 @@ namespace Ewide.Core.Service if (input.Pid != "0" && !string.IsNullOrEmpty(input.Pid)) { // 新增组织机构的父机构不在自己的数据范围内 - var dataScopes = await GetUserDataScopeIdList(); + var dataScopes = await _userManager.GetUserAllDataScopeList(); if (dataScopes.Count < 1 || !dataScopes.Contains(input.Pid)) throw Oops.Oh(ErrorCode.D2003); } @@ -179,7 +179,7 @@ namespace Ewide.Core.Service var sysOrg = await _sysOrgRep.DetachedEntities.FirstOrDefaultAsync(u => u.Id == input.Id); // 检测数据范围能不能操作这个机构 - var dataScopes = await GetUserDataScopeIdList(); + var dataScopes = await _userManager.GetUserAllDataScopeList(); if (!_userManager.SuperAdmin && (dataScopes.Count < 1 || !dataScopes.Contains(sysOrg.Id))) throw Oops.Oh(ErrorCode.D2003); @@ -233,7 +233,7 @@ namespace Ewide.Core.Service var sysOrg = await _sysOrgRep.DetachedEntities.FirstOrDefaultAsync(u => u.Id == input.Id); // 检测数据范围能不能操作这个机构 - var dataScopes = await GetUserDataScopeIdList(); + var dataScopes = await _userManager.GetUserAllDataScopeList(); if (!_userManager.SuperAdmin && (dataScopes.Count < 1 || !dataScopes.Contains(sysOrg.Id))) throw Oops.Oh(ErrorCode.D2003); @@ -293,7 +293,7 @@ namespace Ewide.Core.Service var dataScopeList = new List(); if (!_userManager.SuperAdmin) { - var dataScopes = await GetUserDataScopeIdList(); + var dataScopes = await _userManager.GetUserAllDataScopeList(); if (dataScopes.Count < 1) return dataScopeList; dataScopeList = GetDataScopeList(dataScopes); @@ -344,17 +344,6 @@ namespace Ewide.Core.Service } return orgIdList; } - - /// - /// 获取用户数据范围(机构Id集合) - /// - /// - [NonAction] - public async Task> GetUserDataScopeIdList() - { - return await App.GetService().GetUserDataScopeIdList(); - } - public async Task> GetAreaDataScopeIdList(int dataScopeType, string orgId) { var org = await _sysOrgRep.FirstOrDefaultAsync(o => o.Id == orgId); diff --git a/Api/Ewide.Core/Service/Role/ISysRoleService.cs b/Api/Ewide.Core/Service/Role/ISysRoleService.cs index 591dc89..c05d5e2 100644 --- a/Api/Ewide.Core/Service/Role/ISysRoleService.cs +++ b/Api/Ewide.Core/Service/Role/ISysRoleService.cs @@ -12,7 +12,6 @@ namespace Ewide.Core.Service Task GetRoleDropDown(); Task GetRoleInfo([FromQuery] QueryRoleInput input); Task GetRoleList([FromQuery] RoleInput input); - Task> GetUserDataScopeIdList(List roleIdList, string orgId); Task> GetUserRoleList(string userId); Task GrantData(GrantRoleDataInput input); Task GrantMenu(GrantRoleMenuInput input); diff --git a/Api/Ewide.Core/Service/Role/SysRoleService.cs b/Api/Ewide.Core/Service/Role/SysRoleService.cs index cdfd55b..9df38fd 100644 --- a/Api/Ewide.Core/Service/Role/SysRoleService.cs +++ b/Api/Ewide.Core/Service/Role/SysRoleService.cs @@ -218,7 +218,7 @@ namespace Ewide.Core.Service //如果授权的角色数据范围类型为自定义,则要判断授权的数据范围是否在自己的数据范围内 if ((int)DataScopeType.DEFINE == dataScopeType) { - var dataScopes = await _sysOrgService.GetUserDataScopeIdList(); + var dataScopes = await _userManager.GetUserAllDataScopeList(); var grantOrgIdList = input.GrantOrgIdList; //要授权的数据范围列表 if (grantOrgIdList.Count > 0) { @@ -233,46 +233,6 @@ namespace Ewide.Core.Service await _sysRoleDataScopeService.GrantDataScope(input); } - /// - /// 根据角色Id集合获取数据范围Id集合 - /// - /// - /// - /// - [NonAction] - public async Task> GetUserDataScopeIdList(List roleIdList, string orgId) - { - // 定义角色中最大数据范围的类型,目前按最大范围策略来,如果你同时拥有ALL和SELF的权限,最后按ALL返回 - int strongerDataScopeType = (int)DataScopeType.SELF; - int strongerAreaType = (int)DataScopeType.SELF; - - var customDataScopeRoleIdList = new List(); - if (roleIdList != null && roleIdList.Count > 0) - { - var roles = await _sysRoleRep.DetachedEntities.Where(u => roleIdList.Contains(u.Id)).ToListAsync(); - roles.ForEach(u => - { - if (u.DataScopeType == (int)DataScopeType.DEFINE) - customDataScopeRoleIdList.Add(u.Id); - if ((u.DataScopeType == (int)DataScopeType.AREA || u.DataScopeType == (int)DataScopeType.AREA_WITH_CHILD) && strongerAreaType < u.DataScopeType) - { - strongerAreaType = u.DataScopeType; - } - else if (u.DataScopeType <= strongerDataScopeType) - strongerDataScopeType = u.DataScopeType; - }); - } - - // 自定义数据范围的角色对应的数据范围 - var roleDataScopeIdList = await _sysRoleDataScopeService.GetRoleDataScopeIdList(customDataScopeRoleIdList); - - // 角色中拥有最大数据范围类型的数据范围 - var dataScopeIdList = await _sysOrgService.GetDataScopeListByDataScopeType(strongerDataScopeType, orgId); - //角色区域数据范围 - var areaOrgIdList = await _sysOrgService.GetAreaDataScopeIdList(strongerAreaType, orgId); - return roleDataScopeIdList.Concat(dataScopeIdList).Concat(areaOrgIdList).Distinct().ToList(); //并集 - } - /// /// 根据角色Id获取角色名称 /// diff --git a/Api/Ewide.Core/Service/User/ISysUserDataScopeService.cs b/Api/Ewide.Core/Service/User/ISysUserDataScopeService.cs index e311601..975ac65 100644 --- a/Api/Ewide.Core/Service/User/ISysUserDataScopeService.cs +++ b/Api/Ewide.Core/Service/User/ISysUserDataScopeService.cs @@ -7,7 +7,6 @@ namespace Ewide.Core.Service { Task DeleteUserDataScopeListByOrgIdList(List orgIdList); Task DeleteUserDataScopeListByUserId(string userId); - Task> GetUserDataScopeIdList(string userId); Task GrantData(UpdateUserInput input); } } \ No newline at end of file diff --git a/Api/Ewide.Core/Service/User/ISysUserRoleService.cs b/Api/Ewide.Core/Service/User/ISysUserRoleService.cs index 1c35421..203fce4 100644 --- a/Api/Ewide.Core/Service/User/ISysUserRoleService.cs +++ b/Api/Ewide.Core/Service/User/ISysUserRoleService.cs @@ -7,7 +7,6 @@ namespace Ewide.Core.Service { Task DeleteUserRoleListByRoleId(string roleId); Task DeleteUserRoleListByUserId(string userId); - Task> GetUserRoleDataScopeIdList(string userId, string orgId); Task> GetUserRoleIdList(string userId); Task GrantRole(UpdateUserInput input); } diff --git a/Api/Ewide.Core/Service/User/ISysUserService.cs b/Api/Ewide.Core/Service/User/ISysUserService.cs index 7e6240e..a021e77 100644 --- a/Api/Ewide.Core/Service/User/ISysUserService.cs +++ b/Api/Ewide.Core/Service/User/ISysUserService.cs @@ -13,8 +13,6 @@ namespace Ewide.Core.Service Task ExportUser([FromQuery] UserInput input); Task GetUser([FromQuery] QueryUserInput input); Task GetUserById(string userId); - Task> GetUserDataScopeIdList(); - Task> GetUserDataScopeIdList(string userId); Task GetUserOwnData([FromQuery] QueryUserInput input); Task GetUserOwnArea([FromQuery] QueryUserInput input); Task GetUserOwnRole([FromQuery] QueryUserInput input); diff --git a/Api/Ewide.Core/Service/User/SysUserDataScopeService.cs b/Api/Ewide.Core/Service/User/SysUserDataScopeService.cs index db02381..5742c62 100644 --- a/Api/Ewide.Core/Service/User/SysUserDataScopeService.cs +++ b/Api/Ewide.Core/Service/User/SysUserDataScopeService.cs @@ -63,26 +63,6 @@ namespace Ewide.Core.Service } - /// - /// 获取用户的数据范围Id集合 - /// - /// - /// - public async Task> GetUserDataScopeIdList(string userId) - { - var areaList = await _sysUserAreaRep.DetachedEntities.Where(u => u.SysUserId == userId).Select(u => u.AreaCode).ToListAsync(); - //用户自定义的区域权限所对应的全部组织机构id - List areaDataScopeIdList = new List(); - foreach (var areaNumberCode in areaList) - { - areaDataScopeIdList.AddRange(await _sysOrgRep.DetachedEntities.Where(p => p.AreaCode.StartsWith(areaNumberCode)).Select(p => p.Id).ToListAsync()); - } //用户自定义的组织权限 - var orgIdList = await _sysUserDataScopeRep.DetachedEntities - .Where(u => u.SysUserId == userId) - .Select(u => u.SysOrgId).ToListAsync(); - return areaDataScopeIdList.Concat(orgIdList).Distinct().ToList(); - } - /// /// 根据机构Id集合删除对应的用户-数据范围关联信息 /// diff --git a/Api/Ewide.Core/Service/User/SysUserRoleService.cs b/Api/Ewide.Core/Service/User/SysUserRoleService.cs index 4d34c90..a5a22f4 100644 --- a/Api/Ewide.Core/Service/User/SysUserRoleService.cs +++ b/Api/Ewide.Core/Service/User/SysUserRoleService.cs @@ -57,23 +57,6 @@ namespace Ewide.Core.Service }); } - /// - /// 获取用户所有角色的数据范围(组织机构Id集合) - /// - /// - /// - /// - public async Task> GetUserRoleDataScopeIdList(string userId, string orgId) - { - var roleIdList = await GetUserRoleIdList(userId); - - // 获取这些角色对应的数据范围 - if (roleIdList.Count > 0) - return await _sysRoleService.GetUserDataScopeIdList(roleIdList, orgId); - - return roleIdList; - } - /// /// 根据角色Id删除对应的用户-角色表关联信息 /// diff --git a/Api/Ewide.Core/Service/User/SysUserService.cs b/Api/Ewide.Core/Service/User/SysUserService.cs index 4f6ed52..d028ee9 100644 --- a/Api/Ewide.Core/Service/User/SysUserService.cs +++ b/Api/Ewide.Core/Service/User/SysUserService.cs @@ -72,7 +72,7 @@ namespace Ewide.Core.Service var pid = input.SysEmpParam.OrgId; var sysEmpRep = Db.GetRepository(); - var dataScopes = await GetUserDataScopeIdList(_userManager.UserId); + var dataScopes = await _userManager.GetUserAllDataScopeList(); var users = await _sysUserRep.DetachedEntities .Join(sysEmpRep.DetachedEntities, u => u.Id, e => e.Id, (u, e) => new { u, e }) .Join(_sysOrgRep.DetachedEntities, n => n.e.OrgId, o => o.Id, (n, o) => new { n, o }) @@ -411,47 +411,6 @@ namespace Ewide.Core.Service await user.InsertAsync(); } - /// - /// 获取用户数据范围(机构Id集合)并缓存 - /// - /// - /// - [NonAction] - [UnitOfWork] - public async Task> GetUserDataScopeIdList(string userId) - { - var dataScopes = await _sysCacheService.GetDataScope(userId); // 先从缓存里面读取 - if (dataScopes == null || dataScopes.Count < 1) - { - var orgId = await _sysEmpService.GetEmpOrgId(userId); - - // 获取该用户对应的数据范围集合 - var userDataScopeIdListForUser = await _sysUserDataScopeService.GetUserDataScopeIdList(userId); - - // 获取该用户的角色对应的数据范围集合 - var userDataScopeIdListForRole = await _sysUserRoleService.GetUserRoleDataScopeIdList(userId, orgId); - - dataScopes = userDataScopeIdListForUser.Concat(userDataScopeIdListForRole).Distinct().ToList(); // 并集 - -#if DEBUG -#else - await _sysCacheService.SetDataScope(userId, dataScopes); // 缓存结果 -#endif - } - return dataScopes; - } - - /// - /// 获取用户数据范围(机构Id集合) - /// - /// - [NonAction] - public async Task> GetUserDataScopeIdList() - { - var userId = _userManager.UserId; - var dataScopes = await GetUserDataScopeIdList(userId); - return dataScopes; - } /// /// 检查普通用户数据范围 @@ -463,7 +422,7 @@ namespace Ewide.Core.Service // 如果当前用户不是超级管理员,则进行数据范围校验 if (!_userManager.SuperAdmin) { - var dataScopes = await GetUserDataScopeIdList(_userManager.UserId); + var dataScopes = await _userManager.GetUserAllDataScopeList(); if (dataScopes == null || (userParam.SysEmpParam.OrgId != null && !dataScopes.Contains(userParam.SysEmpParam.OrgId))) throw Oops.Oh(ErrorCode.D1013); }