feat:完成后端数据权限过滤

This commit is contained in:
陈淳
2023-05-22 12:57:27 +08:00
parent ad6bd8f39b
commit 327a7b2a48
14 changed files with 167 additions and 15 deletions

View File

@@ -76,6 +76,10 @@ namespace Yi.Furion.Application.Rbac.Domain
var claims = new Dictionary<string, object>();
claims.Add(TokenTypeConst.Id, dto.User.Id);
claims.Add(TokenTypeConst.UserName, dto.User.UserName);
if (dto.User.DeptId is not null)
{
claims.Add(TokenTypeConst.DeptId, dto.User.DeptId);
}
if (dto.User.Email is not null)
{
claims.Add(TokenTypeConst.Email, dto.User.Email);

View File

@@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Yi.Furion.Core.Rbac.Dtos;
namespace Yi.Furion.Application.Rbac.Services
{
public interface IAccountService
{
}
}

View File

@@ -9,5 +9,6 @@ namespace Yi.Furion.Application.Rbac.Services
public interface IDeptService : ICrudAppService<DeptGetOutputDto, DeptGetListOutputDto, long, DeptGetListInputVo, DeptCreateInputVo, DeptUpdateInputVo>
{
Task<List<long>> GetChildListAsync(long deptId);
Task<List<DeptGetListOutputDto>> GetListRoleIdAsync([FromRoute] long roleId);
}
}

View File

@@ -23,7 +23,7 @@ using Yi.Furion.Sqlsugar.Core.Repositories;
namespace Yi.Furion.Application.Rbac.Services.Impl
{
public class AccountService : ApplicationService, ITransient, IDynamicApiController
public class AccountService : ApplicationService, IAccountService, ITransient, IDynamicApiController
{
public AccountService(IUserRepository userRepository, ICurrentUser currentUser, AccountManager accountManager, IRepository<MenuEntity> menuRepository, SmsAliyunManager smsAliyunManager, IOptions<SmsAliyunOptions> smsAliyunManagerOptions, SecurityCodeHelper securityCode, IMemoryCache memoryCache, IEventPublisher eventPublisher, IHttpContextAccessor httpContextAccessor) =>

View File

@@ -3,6 +3,7 @@ using Yi.Framework.Infrastructure.Ddd.Dtos;
using Yi.Framework.Infrastructure.Ddd.Services;
using Yi.Furion.Core.Rbac.Dtos.Dept;
using Yi.Furion.Core.Rbac.Entities;
using Yi.Furion.Sqlsugar.Core.Repositories;
namespace Yi.Furion.Application.Rbac.Services.Impl
{
@@ -12,11 +13,12 @@ namespace Yi.Furion.Application.Rbac.Services.Impl
public class DeptService : CrudAppService<DeptEntity, DeptGetOutputDto, DeptGetListOutputDto, long, DeptGetListInputVo, DeptCreateInputVo, DeptUpdateInputVo>,
IDeptService, ITransient, IDynamicApiController
{
private IDeptRepository _deptRepository;
public DeptService(IDeptRepository deptRepository) { _deptRepository = deptRepository; }
[NonAction]
public async Task<List<long>> GetChildListAsync(long deptId)
{
var entities= await _DbQueryable.ToChildListAsync(x=>x.ParentId,deptId);
return entities.Select(x => x.Id).ToList();
return await _deptRepository.GetChildListAsync(deptId);
}
/// <summary>
@@ -26,7 +28,7 @@ namespace Yi.Furion.Application.Rbac.Services.Impl
//[Route("{roleId}")]
public async Task<List<DeptGetListOutputDto>> GetListRoleIdAsync([FromRoute] long roleId)
{
var entities = await _DbQueryable.Where(d => SqlFunc.Subqueryable<RoleDeptEntity>().Where(rd => rd.RoleId == roleId && d.Id == rd.DeptId).Any()).ToListAsync();
var entities = await _deptRepository.GetListRoleIdAsync(roleId);
return await MapToGetListOutputDtosAsync(entities);
}

View File

@@ -24,14 +24,6 @@ namespace Yi.Furion.Application.Rbac.Services.Impl
private IRepository<RoleDeptEntity> _roleDeptRepository;
public async Task<List<long>> GetDeptIdsAsync(long roleId)
{
var entities = await _roleDeptRepository.GetListAsync(x => x.RoleId == roleId);
return entities.Select(x => x.DeptId).ToList();
}
[UnitOfWork]
public async Task UpdateDataScpoceAsync(UpdateDataScpoceInput input)
{