forked from ddrilling/AsbCloudServer
Fix UserRole multiple permissions
This commit is contained in:
parent
6924a6bac7
commit
40145f7d5b
@ -15,13 +15,13 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
{
|
{
|
||||||
private readonly CacheTable<UserRole> cacheUserRoles;
|
private readonly CacheTable<UserRole> cacheUserRoles;
|
||||||
private readonly CacheTable<RelationUserRolePermission> cacheUserRolePermissions;
|
private readonly CacheTable<RelationUserRolePermission> cacheUserRolePermissions;
|
||||||
|
|
||||||
public List<string> Includes { get; }
|
public ISet<string> Includes { get; } = new SortedSet<string>();
|
||||||
|
|
||||||
public UserRoleService(IAsbCloudDbContext context, CacheDb cacheDb)
|
public UserRoleService(IAsbCloudDbContext context, CacheDb cacheDb)
|
||||||
{
|
{
|
||||||
cacheUserRoles = cacheDb.GetCachedTable<UserRole>((AsbCloudDbContext)context, new [] { nameof(UserRole.RelationUserRolePermissions) });
|
cacheUserRoles = cacheDb.GetCachedTable<UserRole>((AsbCloudDbContext)context, nameof(UserRole.RelationUserRolePermissions));
|
||||||
cacheUserRolePermissions = cacheDb.GetCachedTable<RelationUserRolePermission>((AsbCloudDbContext)context, new[] { nameof(RelationUserRolePermission.Permission) });
|
cacheUserRolePermissions = cacheDb.GetCachedTable<RelationUserRolePermission>((AsbCloudDbContext)context, nameof(RelationUserRolePermission.Permission));
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<int> InsertAsync(UserRoleDto dto, CancellationToken token = default)
|
public async Task<int> InsertAsync(UserRoleDto dto, CancellationToken token = default)
|
||||||
@ -129,8 +129,6 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
.ConfigureAwait(false);
|
.ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public Task<int> DeleteAsync(int id, CancellationToken token = default)
|
public Task<int> DeleteAsync(int id, CancellationToken token = default)
|
||||||
=> cacheUserRoles.RemoveAsync(r => r.Id == id, token);
|
=> cacheUserRoles.RemoveAsync(r => r.Id == id, token);
|
||||||
|
|
||||||
@ -177,9 +175,8 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
var dto = entity.Adapt<UserRoleDto>();
|
var dto = entity.Adapt<UserRoleDto>();
|
||||||
if(entity.RelationUserRolePermissions?.Any() == true)
|
if(entity.RelationUserRolePermissions?.Any() == true)
|
||||||
{
|
{
|
||||||
var permissionsIds = entity.RelationUserRolePermissions.Select(r => r.IdPermission);
|
|
||||||
dto.Permissions = cacheUserRolePermissions
|
dto.Permissions = cacheUserRolePermissions
|
||||||
.Where(r => permissionsIds.Contains(r.IdPermission))
|
.Where(r => entity.Id == r.IdUserRole)
|
||||||
.Select(r => Convert(r.Permission));
|
.Select(r => Convert(r.Permission));
|
||||||
}
|
}
|
||||||
return dto;
|
return dto;
|
||||||
|
Loading…
Reference in New Issue
Block a user