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)
|
public async Task<int> UpdateAsync(UserRoleDto dto, CancellationToken token)
|
||||||
{
|
{
|
||||||
var entity = Convert(dto);
|
|
||||||
await UpdatePermissionsAsync(dto, token);
|
await UpdatePermissionsAsync(dto, token);
|
||||||
await UpdateIncludedRolesAsync(dto, token);
|
await UpdateIncludedRolesAsync(dto, token);
|
||||||
|
|
||||||
|
var entity = Convert(dto);
|
||||||
var result = dbContext.UserRoles.Upsert(entity);
|
var result = dbContext.UserRoles.Upsert(entity);
|
||||||
await dbContext.SaveChangesAsync(token);
|
await dbContext.SaveChangesAsync(token);
|
||||||
DropCacheUserRole();
|
DropCacheUserRole();
|
||||||
@ -182,8 +182,15 @@ namespace AsbCloudInfrastructure.Repository
|
|||||||
if (dto?.Roles is null)
|
if (dto?.Roles is null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
var relations = (await GetCacheRelationUserRoleUserRoleAsync(token).ConfigureAwait(false))
|
var idsIncludeRole = dto.Roles.Select(x => x.Id);
|
||||||
.Where(r => r.Id == dto.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);
|
dbContext.RelationUserRoleUserRoles.RemoveRange(relations);
|
||||||
|
|
||||||
@ -201,9 +208,10 @@ namespace AsbCloudInfrastructure.Repository
|
|||||||
if (dto?.Permissions is null)
|
if (dto?.Permissions is null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
var relations = (await GetCacheRelationUserRolePermissionsAsync(token).ConfigureAwait(false))
|
var relations = await dbContext.RelationUserRolePermissions
|
||||||
.Where(r => r.IdUserRole == dto.Id);
|
.Where(r => r.IdUserRole == dto.Id)
|
||||||
|
.ToListAsync(token)
|
||||||
|
.ConfigureAwait(false);
|
||||||
dbContext.RelationUserRolePermissions.RemoveRange(relations);
|
dbContext.RelationUserRolePermissions.RemoveRange(relations);
|
||||||
|
|
||||||
if (dto.Permissions.Any())
|
if (dto.Permissions.Any())
|
||||||
|
Loading…
Reference in New Issue
Block a user