forked from ddrilling/AsbCloudServer
#7759269 Проверка ролей на зацикливание включенных ролей
This commit is contained in:
parent
daaad5b8d1
commit
ba96645288
@ -90,10 +90,10 @@ namespace AsbCloudInfrastructure.Repository
|
||||
|
||||
public async Task<int> UpdateAsync(UserRoleDto dto, CancellationToken token)
|
||||
{
|
||||
var entity = Convert(dto);
|
||||
await UpdatePermissionsAsync(dto, token);
|
||||
await UpdateIncludedRolesAsync(dto, token);
|
||||
|
||||
var entity = Convert(dto);
|
||||
var result = dbContext.UserRoles.Upsert(entity);
|
||||
await dbContext.SaveChangesAsync(token);
|
||||
DropCacheUserRole();
|
||||
@ -182,8 +182,15 @@ namespace AsbCloudInfrastructure.Repository
|
||||
if (dto?.Roles is null)
|
||||
return;
|
||||
|
||||
var relations = (await GetCacheRelationUserRoleUserRoleAsync(token).ConfigureAwait(false))
|
||||
.Where(r => r.Id == dto.Id);
|
||||
var idsIncludeRole = dto.Roles.Select(x => x.Id);
|
||||
|
||||
if (idsIncludeRole.Any(x => x == dto.Id))
|
||||
throw new ArgumentInvalidException("Invalid include role", nameof(UserRoleDto));
|
||||
|
||||
var relations = await dbContext.RelationUserRoleUserRoles
|
||||
.Where(r => r.Id == dto.Id)
|
||||
.ToListAsync(token)
|
||||
.ConfigureAwait(false);
|
||||
|
||||
dbContext.RelationUserRoleUserRoles.RemoveRange(relations);
|
||||
|
||||
@ -201,9 +208,10 @@ namespace AsbCloudInfrastructure.Repository
|
||||
if (dto?.Permissions is null)
|
||||
return;
|
||||
|
||||
var relations = (await GetCacheRelationUserRolePermissionsAsync(token).ConfigureAwait(false))
|
||||
.Where(r => r.IdUserRole == dto.Id);
|
||||
|
||||
var relations = await dbContext.RelationUserRolePermissions
|
||||
.Where(r => r.IdUserRole == dto.Id)
|
||||
.ToListAsync(token)
|
||||
.ConfigureAwait(false);
|
||||
dbContext.RelationUserRolePermissions.RemoveRange(relations);
|
||||
|
||||
if (dto.Permissions.Any())
|
||||
|
Loading…
Reference in New Issue
Block a user