Fix UserRole multiple permissions

This commit is contained in:
Фролов 2021-12-22 11:35:36 +05:00
parent 6924a6bac7
commit 40145f7d5b

View File

@ -16,12 +16,12 @@ namespace AsbCloudInfrastructure.Services
private readonly CacheTable<UserRole> cacheUserRoles;
private readonly CacheTable<RelationUserRolePermission> cacheUserRolePermissions;
public List<string> Includes { get; }
public ISet<string> Includes { get; } = new SortedSet<string>();
public UserRoleService(IAsbCloudDbContext context, CacheDb cacheDb)
{
cacheUserRoles = cacheDb.GetCachedTable<UserRole>((AsbCloudDbContext)context, new [] { nameof(UserRole.RelationUserRolePermissions) });
cacheUserRolePermissions = cacheDb.GetCachedTable<RelationUserRolePermission>((AsbCloudDbContext)context, new[] { nameof(RelationUserRolePermission.Permission) });
cacheUserRoles = cacheDb.GetCachedTable<UserRole>((AsbCloudDbContext)context, nameof(UserRole.RelationUserRolePermissions));
cacheUserRolePermissions = cacheDb.GetCachedTable<RelationUserRolePermission>((AsbCloudDbContext)context, nameof(RelationUserRolePermission.Permission));
}
public async Task<int> InsertAsync(UserRoleDto dto, CancellationToken token = default)
@ -129,8 +129,6 @@ namespace AsbCloudInfrastructure.Services
.ConfigureAwait(false);
}
public Task<int> DeleteAsync(int id, CancellationToken token = default)
=> cacheUserRoles.RemoveAsync(r => r.Id == id, token);
@ -177,9 +175,8 @@ namespace AsbCloudInfrastructure.Services
var dto = entity.Adapt<UserRoleDto>();
if(entity.RelationUserRolePermissions?.Any() == true)
{
var permissionsIds = entity.RelationUserRolePermissions.Select(r => r.IdPermission);
dto.Permissions = cacheUserRolePermissions
.Where(r => permissionsIds.Contains(r.IdPermission))
.Where(r => entity.Id == r.IdUserRole)
.Select(r => Convert(r.Permission));
}
return dto;