feat 数据敏感分配角色可见,切换基地,定时任务lock
This commit is contained in:
@@ -17,4 +17,8 @@ public interface IRoleService : IScopeDependency
|
||||
Task RemoveRoleAsync(IdRequest request);
|
||||
|
||||
Task AssignRoleAsync(RoleAssignRequest request);
|
||||
}
|
||||
|
||||
Task SaveRoleObfuscateAsync(RoleObfuscateRequest request);
|
||||
|
||||
Task<bool> GetRoleObfuscateAsync(int id);
|
||||
}
|
||||
@@ -20,4 +20,6 @@ public interface IUserService : IScopeDependency
|
||||
Task<List<UserResponse>> GetUserByIdsAsync(List<int> ids);
|
||||
|
||||
Task CreateUserAsync(UserCreateRequest request);
|
||||
|
||||
Task ResetLoginTenantAsync(UserResetLoginTenantRequest request);
|
||||
}
|
||||
@@ -6,6 +6,7 @@ using Kurisu.AspNetCore.CustomClass;
|
||||
using Kurisu.AspNetCore.DataAccess.Dto;
|
||||
using Kurisu.AspNetCore.DataAccess.SqlSugar.Extensions;
|
||||
using Kurisu.AspNetCore.DataAccess.SqlSugar.Services;
|
||||
using Kurisu.AspNetCore.Utils;
|
||||
using Kurisu.AspNetCore.Utils.Extensions;
|
||||
|
||||
namespace Dlhis.Sys.Identity.Services.Implements;
|
||||
@@ -13,11 +14,13 @@ namespace Dlhis.Sys.Identity.Services.Implements;
|
||||
public class RoleService : IRoleService
|
||||
{
|
||||
private readonly ICurrentUser _currentUser;
|
||||
private readonly RedisCache _redisCache;
|
||||
private readonly IDbContext _dbContext;
|
||||
|
||||
public RoleService(ICurrentUser currentUser, IDbContext dbContext)
|
||||
public RoleService(ICurrentUser currentUser, IDbContext dbContext, RedisCache redisCache)
|
||||
{
|
||||
_currentUser = currentUser;
|
||||
_redisCache = redisCache;
|
||||
_dbContext = dbContext.ChangeDb("identity");
|
||||
}
|
||||
|
||||
@@ -112,6 +115,33 @@ public class RoleService : IRoleService
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task SaveRoleObfuscateAsync(RoleObfuscateRequest request)
|
||||
{
|
||||
var role = await _dbContext.Queryable<RoleEntity>().FirstAsync(x => x.Id == request.Id);
|
||||
role.ThrowIfNull("角色不存在");
|
||||
|
||||
var key = "datapermission:role";
|
||||
if (request.IsShow)
|
||||
{
|
||||
await _redisCache.ListLeftPushAsync(key, role.Name);
|
||||
}
|
||||
else
|
||||
{
|
||||
await _redisCache.ListRemoveAsync(key, role.Name);
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<bool> GetRoleObfuscateAsync(int id)
|
||||
{
|
||||
var role = await _dbContext.Queryable<RoleEntity>().FirstAsync(x => x.Id == id);
|
||||
var key = "datapermission:role";
|
||||
var range = await _redisCache.ListRangeAsync(key);
|
||||
|
||||
return range.Any(x => (string)x == role.Name);
|
||||
}
|
||||
|
||||
public async Task RemoveRoleAsync(IdRequest request)
|
||||
{
|
||||
var role = await _dbContext.Queryable<RoleEntity>().FirstAsync(x => x.Id == request.Id);
|
||||
|
||||
@@ -16,12 +16,14 @@ public class UserService : IUserService
|
||||
{
|
||||
private readonly IDbContext _dbContext;
|
||||
private readonly ICurrentUser _currentUser;
|
||||
private readonly ITenantService _tenantService;
|
||||
private readonly IDbContext _identityDbContext;
|
||||
|
||||
public UserService(IDbContext dbContext, ICurrentUser currentUser)
|
||||
public UserService(IDbContext dbContext, ICurrentUser currentUser, ITenantService tenantService)
|
||||
{
|
||||
_dbContext = dbContext;
|
||||
_currentUser = currentUser;
|
||||
_tenantService = tenantService;
|
||||
_identityDbContext = dbContext.ChangeDb("identity");
|
||||
}
|
||||
|
||||
@@ -135,4 +137,25 @@ public class UserService : IUserService
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public async Task ResetLoginTenantAsync(UserResetLoginTenantRequest request)
|
||||
{
|
||||
var tenants = await _tenantService.GetMyTenantsAsync();
|
||||
tenants.All(x => x.Code != request.Tenant).ThrowIfTrue($"不可切换登陆:{request.Tenant}");
|
||||
|
||||
var userId = _currentUser.GetIntSubjectId();
|
||||
|
||||
await _dbContext.Updateable<UserClaimEntity>()
|
||||
.SetColumns(x => x.ClaimValue == request.Tenant)
|
||||
.Where(x => x.UserId == userId)
|
||||
.Where(x => x.ClaimType == "tenant")
|
||||
.ExecuteCommandAsync();
|
||||
|
||||
var tenantStr = tenants.Select(x => x.Code).Join(",");
|
||||
await _dbContext.Updateable<UserClaimEntity>()
|
||||
.SetColumns(x => x.ClaimValue == tenantStr)
|
||||
.Where(x => x.UserId == userId)
|
||||
.Where(x => x.ClaimType == "tenants")
|
||||
.ExecuteCommandAsync();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user