update:角色授权组织数据同时可以授权区域数据

This commit is contained in:
2021-04-27 17:44:55 +08:00
parent e0d5540ed9
commit cffb6d2f0c
4 changed files with 17 additions and 5 deletions

View File

@@ -83,5 +83,9 @@ namespace Ewide.Core.Service
public class GrantRoleDataInput : GrantRoleMenuInput
{
}
public class GrantAreaDataInput : GrantRoleMenuInput
{
}
}

View File

@@ -11,6 +11,6 @@ namespace Ewide.Core.Service.Role
Task DeleteRoleAreaListByAreaCodeList(List<string> areaCodeList);
Task DeleteRoleAreaListByRoleId(string roleId);
Task<List<string>> GetRoleAreaCodeList(List<string> roleIdList);
Task GrantArea(UpdateRoleInput input);
Task GrantArea(GrantAreaDataInput input);
}
}

View File

@@ -45,7 +45,7 @@ namespace Ewide.Core.Service.Role
}
public async Task GrantArea(UpdateRoleInput input)
public async Task GrantArea(GrantAreaDataInput input)
{
var dataScopes = await _sysRoleAreaRep.Where(u => u.SysRoleId == input.Id).ToListAsync();
dataScopes.ForEach(u =>

View File

@@ -1,6 +1,8 @@
using Furion.DatabaseAccessor;
using Ewide.Core.Service.Role;
using Furion.DatabaseAccessor;
using Furion.DatabaseAccessor.Extensions;
using Furion.DependencyInjection;
using Mapster;
using Microsoft.EntityFrameworkCore;
using System.Collections.Generic;
using System.Linq;
@@ -14,10 +16,11 @@ namespace Ewide.Core.Service
public class SysRoleDataScopeService : ISysRoleDataScopeService, ITransient
{
private readonly IRepository<SysRoleDataScope> _sysRoleDataScopeRep; // 角色数据范围表仓储
public SysRoleDataScopeService(IRepository<SysRoleDataScope> sysRoleDataScopeRep)
private readonly ISysRoleAreaService _sysRoleAreaService;
public SysRoleDataScopeService(IRepository<SysRoleDataScope> sysRoleDataScopeRep, ISysRoleAreaService sysRoleAreaService)
{
_sysRoleDataScopeRep = sysRoleDataScopeRep;
_sysRoleAreaService = sysRoleAreaService;
}
/// <summary>
@@ -28,6 +31,11 @@ namespace Ewide.Core.Service
[UnitOfWork]
public async Task GrantDataScope(GrantRoleDataInput input)
{
if (new[] { (int)DataScopeType.AREA, (int)DataScopeType.AREA_WITH_CHILD }.Contains(input.DataScopeType))
{
await _sysRoleAreaService.GrantArea(input.Adapt<GrantAreaDataInput>());
return;
}
var dataScopes = await _sysRoleDataScopeRep.DetachedEntities.Where(u => u.SysRoleId == input.Id).ToListAsync();
dataScopes.ForEach(u =>
{