fix 角色分配
This commit is contained in:
@@ -65,6 +65,11 @@ public class UserResponse
|
||||
public int AccessFailedCount { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 角色id
|
||||
/// </summary>
|
||||
public int RoleId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 角色
|
||||
/// </summary>
|
||||
|
||||
@@ -32,6 +32,7 @@ public class UserService : IUserService
|
||||
.Select((x, ur, r, c) => new UserResponse
|
||||
{
|
||||
Id = x.Id,
|
||||
RoleId = ur.RoleId,
|
||||
Role = r.Name,
|
||||
OperatorName = c.ClaimValue,
|
||||
|
||||
@@ -58,7 +59,21 @@ public class UserService : IUserService
|
||||
|
||||
public async Task<UserResponse> GetUserByIdAsync(int id)
|
||||
{
|
||||
var user = await _dbContext.Queryable<UserEntity>().Where(x => x.Id == id).Select<UserResponse>().FirstAsync();
|
||||
var user = await _dbContext.Queryable<UserEntity>()
|
||||
.LeftJoin<UserRoleEntity>((x, ur) => x.Id == ur.UserId)
|
||||
.LeftJoin<RoleEntity>((x, ur, r) => ur.RoleId == r.Id)
|
||||
.LeftJoin<UserClaimEntity>((x, ur, r, c) => x.Id == c.UserId && c.ClaimType == "preferred_username")
|
||||
.Where(x => x.Id == id)
|
||||
.Select((x, ur, r, c) => new UserResponse
|
||||
{
|
||||
Id = x.Id,
|
||||
RoleId = ur.RoleId,
|
||||
Role = r.Name,
|
||||
OperatorName = c.ClaimValue,
|
||||
|
||||
}, true)
|
||||
.FirstAsync();
|
||||
|
||||
return user;
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,6 @@ using Dlhis.Entity.Sys.Enums;
|
||||
using Dlhis.Sys.Identity.Services;
|
||||
using Dlhis.Sys.Menu.Request;
|
||||
using Dlhis.Sys.Menu.Response;
|
||||
using Kurisu.AspNetCore.Scope;
|
||||
using Kurisu.AspNetCore.Utils.Extensions;
|
||||
using Kurisu.Core.User.Abstractions;
|
||||
using Kurisu.SqlSugar.Services;
|
||||
@@ -15,11 +14,13 @@ public class MenuService : IMenuService
|
||||
{
|
||||
private readonly IDbContext _dbContext;
|
||||
private readonly ICurrentUser _currentUser;
|
||||
private readonly IUserService _userService;
|
||||
|
||||
public MenuService(IDbContext dbContext, ICurrentUser currentUser)
|
||||
public MenuService(IDbContext dbContext, ICurrentUser currentUser, IUserService userService)
|
||||
{
|
||||
_dbContext = dbContext;
|
||||
_currentUser = currentUser;
|
||||
_userService = userService;
|
||||
}
|
||||
|
||||
public async Task<List<MenuResponse>> GetListAsync(PlatformEnumType platform)
|
||||
@@ -64,18 +65,15 @@ public class MenuService : IMenuService
|
||||
|
||||
public async Task AssignmentAsync(MenuPermissionAssignmentRequest request)
|
||||
{
|
||||
(request.UniqueType == AssignTypeEnumType.Role).ThrowIfTrue("暂不支持角色分配");
|
||||
|
||||
//清空覆盖
|
||||
var permissionsToDelete = await _dbContext.Queryable<MenuPermissionEntity>()
|
||||
.Where(x => x.UniqueType == request.UniqueType)
|
||||
.Where(x => x.UniqueValue == request.UniqueValue)
|
||||
.ToListAsync();
|
||||
|
||||
//触发日志记录
|
||||
await _dbContext.DeleteAsync(permissionsToDelete);
|
||||
await _dbContext.DeleteReallyAsync(permissionsToDelete);
|
||||
|
||||
var permissions = request.Codes.Select(x => new MenuPermissionEntity
|
||||
var permissions = request.Codes.Distinct().Select(x => new MenuPermissionEntity
|
||||
{
|
||||
Code = x,
|
||||
UniqueType = request.UniqueType,
|
||||
@@ -83,7 +81,6 @@ public class MenuService : IMenuService
|
||||
|
||||
}).ToList();
|
||||
|
||||
|
||||
await _dbContext.InsertAsync(permissions);
|
||||
}
|
||||
|
||||
@@ -147,6 +144,7 @@ public class MenuService : IMenuService
|
||||
var allCodes = await GetAllAssignmentCodesAsync();
|
||||
if (!allCodes.Any())
|
||||
{
|
||||
//todo 管理员
|
||||
var userId = _currentUser.GetIntSubjectId();
|
||||
if (userId == 1)
|
||||
{
|
||||
@@ -284,18 +282,15 @@ public class MenuService : IMenuService
|
||||
|
||||
private async Task<List<string>> GetAllAssignmentCodesAsync()
|
||||
{
|
||||
var user = await Scoped.Request.Value.CreateAsync(sp =>
|
||||
{
|
||||
return sp.GetService<IUserService>().GetUserByIdAsync(_currentUser.GetIntSubjectId());
|
||||
});
|
||||
|
||||
// var groupCodes = await GetAssignmentCodesAsync(MenuPermissionTypeEnumType.Group, manager.usergrp);
|
||||
var user = await _userService.GetUserByIdAsync(_currentUser.GetIntSubjectId());
|
||||
|
||||
//user
|
||||
var userCodes = await GetAssignmentCodesAsync(AssignTypeEnumType.User, user.Id.ToString());
|
||||
var all = userCodes;// gP.Concat(uP).Distinct().ToList();
|
||||
|
||||
return all;
|
||||
//role
|
||||
var roleCodes = await GetAssignmentCodesAsync(AssignTypeEnumType.Role, user.RoleId.ToString());
|
||||
|
||||
return userCodes.Concat(roleCodes).Distinct().ToList();
|
||||
}
|
||||
|
||||
|
||||
@@ -315,6 +310,4 @@ public class MenuService : IMenuService
|
||||
await _dbContext.UpdateAsync(permissions);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user