From ba966452887f1ad4953e28d604e4013ad6fc8a4d Mon Sep 17 00:00:00 2001 From: "ai.astrakhantsev" Date: Tue, 29 Nov 2022 08:40:01 +0500 Subject: [PATCH 1/4] =?UTF-8?q?#7759269=20=D0=9F=D1=80=D0=BE=D0=B2=D0=B5?= =?UTF-8?q?=D1=80=D0=BA=D0=B0=20=D1=80=D0=BE=D0=BB=D0=B5=D0=B9=20=D0=BD?= =?UTF-8?q?=D0=B0=20=D0=B7=D0=B0=D1=86=D0=B8=D0=BA=D0=BB=D0=B8=D0=B2=D0=B0?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=20=D0=B2=D0=BA=D0=BB=D1=8E=D1=87=D0=B5=D0=BD?= =?UTF-8?q?=D0=BD=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()) From c9c60bce2b275778590389328860929043461cdd Mon Sep 17 00:00:00 2001 From: "ai.astrakhantsev" Date: Tue, 29 Nov 2022 11:22:09 +0500 Subject: [PATCH 2/4] =?UTF-8?q?#7759269=20=D0=9F=D1=80=D0=BE=D0=B2=D0=B5?= =?UTF-8?q?=D1=80=D0=BA=D0=B0=20=D1=80=D0=BE=D0=BB=D0=B5=D0=B9=20=D0=BD?= =?UTF-8?q?=D0=B0=20=D0=B7=D0=B0=D1=86=D0=B8=D0=BA=D0=BB=D0=B8=D0=B2=D0=B0?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=20=D0=B2=D0=BA=D0=BB=D1=8E=D1=87=D0=B5=D0=BD?= =?UTF-8?q?=D0=BD=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 | 29 +++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/AsbCloudInfrastructure/Repository/UserRoleRepository.cs b/AsbCloudInfrastructure/Repository/UserRoleRepository.cs index 52c087fa..e386bb7f 100644 --- a/AsbCloudInfrastructure/Repository/UserRoleRepository.cs +++ b/AsbCloudInfrastructure/Repository/UserRoleRepository.cs @@ -5,6 +5,7 @@ using AsbCloudApp.Repositories; using AsbCloudDb; using AsbCloudDb.Model; using AsbCloudInfrastructure.EfCache; +using DocumentFormat.OpenXml.Vml.Office; using Mapster; using Microsoft.EntityFrameworkCore; using System; @@ -177,14 +178,23 @@ namespace AsbCloudInfrastructure.Repository return false; } + private IEnumerable GetNestedByIds(IEnumerable ids, int recursionLevel = 7) + { + var roles = new List(); + foreach (var id in ids) + roles.AddRange(GetNestedById(id, recursionLevel)); + + return roles; + } + private async Task UpdateIncludedRolesAsync(UserRoleDto dto, CancellationToken token) { if (dto?.Roles is null) return; - var idsIncludeRole = dto.Roles.Select(x => x.Id); + var idsIncludeRole = GetNestedByIds(dto.Roles.Select(x => x.Id)).Select(x => x.Id); - if (idsIncludeRole.Any(x => x == dto.Id)) + if (idsIncludeRole is null || idsIncludeRole.Any(x => x == dto.Id)) throw new ArgumentInvalidException("Invalid include role", nameof(UserRoleDto)); var relations = await dbContext.RelationUserRoleUserRoles @@ -203,6 +213,21 @@ namespace AsbCloudInfrastructure.Repository DropCacheRelationUserRoleUserRole(); } + //private IEnumerable GetNestedRoleIds(UserRoleDto dto) + //{ + // var result = new List(); + // if (dto.Roles is not null) + // { + // foreach (var role in dto.Roles) + // { + // result.Add(role.Id); + // if (role.Roles is not null) + // GetNestedRoleIds(role); + // } + // } + // return result; + //} + private async Task UpdatePermissionsAsync(UserRoleDto dto, CancellationToken token) { if (dto?.Permissions is null) From a12906d5581bb779695f2af134b7b1e635425951 Mon Sep 17 00:00:00 2001 From: "ai.astrakhantsev" Date: Tue, 29 Nov 2022 11:22:34 +0500 Subject: [PATCH 3/4] =?UTF-8?q?#7759269=20=D0=9F=D1=80=D0=BE=D0=B2=D0=B5?= =?UTF-8?q?=D1=80=D0=BA=D0=B0=20=D1=80=D0=BE=D0=BB=D0=B5=D0=B9=20=D0=BD?= =?UTF-8?q?=D0=B0=20=D0=B7=D0=B0=D1=86=D0=B8=D0=BA=D0=BB=D0=B8=D0=B2=D0=B0?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=20=D0=B2=D0=BA=D0=BB=D1=8E=D1=87=D0=B5=D0=BD?= =?UTF-8?q?=D0=BD=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 | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/AsbCloudInfrastructure/Repository/UserRoleRepository.cs b/AsbCloudInfrastructure/Repository/UserRoleRepository.cs index e386bb7f..ccb736ea 100644 --- a/AsbCloudInfrastructure/Repository/UserRoleRepository.cs +++ b/AsbCloudInfrastructure/Repository/UserRoleRepository.cs @@ -213,21 +213,6 @@ namespace AsbCloudInfrastructure.Repository DropCacheRelationUserRoleUserRole(); } - //private IEnumerable GetNestedRoleIds(UserRoleDto dto) - //{ - // var result = new List(); - // if (dto.Roles is not null) - // { - // foreach (var role in dto.Roles) - // { - // result.Add(role.Id); - // if (role.Roles is not null) - // GetNestedRoleIds(role); - // } - // } - // return result; - //} - private async Task UpdatePermissionsAsync(UserRoleDto dto, CancellationToken token) { if (dto?.Permissions is null) From 4a547d82ae93ede0f2b76b6104c1fe8e8a88ffb7 Mon Sep 17 00:00:00 2001 From: "ai.astrakhantsev" Date: Tue, 29 Nov 2022 11:22:34 +0500 Subject: [PATCH 4/4] =?UTF-8?q?#7759269=20=D0=9F=D1=80=D0=BE=D0=B2=D0=B5?= =?UTF-8?q?=D1=80=D0=BA=D0=B0=20=D1=80=D0=BE=D0=BB=D0=B5=D0=B9=20=D0=BD?= =?UTF-8?q?=D0=B0=20=D0=B7=D0=B0=D1=86=D0=B8=D0=BA=D0=BB=D0=B8=D0=B2=D0=B0?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=20=D0=B2=D0=BA=D0=BB=D1=8E=D1=87=D0=B5=D0=BD?= =?UTF-8?q?=D0=BD=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 | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/AsbCloudInfrastructure/Repository/UserRoleRepository.cs b/AsbCloudInfrastructure/Repository/UserRoleRepository.cs index e386bb7f..56daca96 100644 --- a/AsbCloudInfrastructure/Repository/UserRoleRepository.cs +++ b/AsbCloudInfrastructure/Repository/UserRoleRepository.cs @@ -5,7 +5,6 @@ using AsbCloudApp.Repositories; using AsbCloudDb; using AsbCloudDb.Model; using AsbCloudInfrastructure.EfCache; -using DocumentFormat.OpenXml.Vml.Office; using Mapster; using Microsoft.EntityFrameworkCore; using System; @@ -213,21 +212,6 @@ namespace AsbCloudInfrastructure.Repository DropCacheRelationUserRoleUserRole(); } - //private IEnumerable GetNestedRoleIds(UserRoleDto dto) - //{ - // var result = new List(); - // if (dto.Roles is not null) - // { - // foreach (var role in dto.Roles) - // { - // result.Add(role.Id); - // if (role.Roles is not null) - // GetNestedRoleIds(role); - // } - // } - // return result; - //} - private async Task UpdatePermissionsAsync(UserRoleDto dto, CancellationToken token) { if (dto?.Permissions is null)