From ba966452887f1ad4953e28d604e4013ad6fc8a4d Mon Sep 17 00:00:00 2001 From: "ai.astrakhantsev" Date: Tue, 29 Nov 2022 08:40:01 +0500 Subject: [PATCH] =?UTF-8?q?#7759269=20=D0=9F=D1=80=D0=BE=D0=B2=D0=B5=D1=80?= =?UTF-8?q?=D0=BA=D0=B0=20=D1=80=D0=BE=D0=BB=D0=B5=D0=B9=20=D0=BD=D0=B0=20?= =?UTF-8?q?=D0=B7=D0=B0=D1=86=D0=B8=D0=BA=D0=BB=D0=B8=D0=B2=D0=B0=D0=BD?= =?UTF-8?q?=D0=B8=D0=B5=20=D0=B2=D0=BA=D0=BB=D1=8E=D1=87=D0=B5=D0=BD=D0=BD?= =?UTF-8?q?=D1=8B=D1=85=20=D1=80=D0=BE=D0=BB=D0=B5=D0=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Repository/UserRoleRepository.cs | 20 +++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/AsbCloudInfrastructure/Repository/UserRoleRepository.cs b/AsbCloudInfrastructure/Repository/UserRoleRepository.cs index 2ca837d3..52c087fa 100644 --- a/AsbCloudInfrastructure/Repository/UserRoleRepository.cs +++ b/AsbCloudInfrastructure/Repository/UserRoleRepository.cs @@ -90,10 +90,10 @@ namespace AsbCloudInfrastructure.Repository public async Task 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())