From c9c60bce2b275778590389328860929043461cdd Mon Sep 17 00:00:00 2001 From: "ai.astrakhantsev" Date: Tue, 29 Nov 2022 11:22:09 +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 | 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)