fix 优化role分配级别问题
This commit is contained in:
@@ -51,7 +51,7 @@ public class GainfosController : ControllerBase
|
||||
/// 获取归档人员数据
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet("/archive/pagination")]
|
||||
[HttpGet("archive/pagination")]
|
||||
public async Task<Pagination<GainfoOpenResponse>> GetGainfoLeavePageAsync([FromQuery] GainfoArchivePageRequest request)
|
||||
{
|
||||
return await _gainfoService.GetGainfoLeavePageAsync(request);
|
||||
|
||||
@@ -72,22 +72,36 @@ public class RoleService : IRoleService
|
||||
}
|
||||
}
|
||||
|
||||
private static readonly List<string> _roles = new() { "admin", "tenant-admin" };
|
||||
|
||||
public async Task AssignRoleAsync(RoleAssignRequest request)
|
||||
{
|
||||
var myUserId = _currentUser.GetIntSubjectId();
|
||||
if (request.UserId == 1)
|
||||
throw new UserFriendlyException("不允许分配给系统管理员");
|
||||
|
||||
//不能被其他人修改
|
||||
if (request.UserId == 1 && request.UserId != myUserId)
|
||||
{
|
||||
throw new UserFriendlyException("无法修改admin角色");
|
||||
}
|
||||
|
||||
var existsUser = await _dbContext.Queryable<UserEntity>().Where(x => x.Id == request.UserId).AnyAsync();
|
||||
existsUser.ThrowIfFalse("分配的用户不存在");
|
||||
var user = await _dbContext.Queryable<UserEntity>().Where(x => x.Id == request.UserId).AnyAsync();
|
||||
user.ThrowIfFalse("分配的用户不存在");
|
||||
|
||||
var userRole = await _dbContext.Queryable<UserRoleEntity>().Where(x => x.UserId == request.UserId).FirstAsync();
|
||||
|
||||
//操作的用户存在角色
|
||||
if (userRole != null)
|
||||
{
|
||||
var role = await _dbContext.Queryable<RoleEntity>().Where(x => x.Id == userRole.RoleId).FirstAsync();
|
||||
if (role != null)
|
||||
{
|
||||
var myRole = _currentUser.GetRole();
|
||||
var myi = _roles.IndexOf(myRole);
|
||||
|
||||
var ii = _roles.IndexOf(role.Name);
|
||||
if (ii <= myi)
|
||||
{
|
||||
throw new UserFriendlyException("不可操作当前用户");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (request.RoleId.HasValue)
|
||||
{
|
||||
var existsRole = await _dbContext.Queryable<RoleEntity>().Where(x => x.Id == request.RoleId).AnyAsync();
|
||||
|
||||
Reference in New Issue
Block a user