From 950e7ad02a3309d03562b6f6a634825b1fc9ca5a Mon Sep 17 00:00:00 2001 From: "ai.astrakhantsev" Date: Thu, 27 Oct 2022 14:18:59 +0500 Subject: [PATCH] #7205798 fix --- .../Repositories/IUserRoleRepository.cs | 4 +-- .../Repository/UserRepository.cs | 16 +++++------ .../Repository/UserRoleRepository.cs | 28 +++++++++++-------- 3 files changed, 26 insertions(+), 22 deletions(-) diff --git a/AsbCloudApp/Repositories/IUserRoleRepository.cs b/AsbCloudApp/Repositories/IUserRoleRepository.cs index 177e4379..a2c25704 100644 --- a/AsbCloudApp/Repositories/IUserRoleRepository.cs +++ b/AsbCloudApp/Repositories/IUserRoleRepository.cs @@ -18,7 +18,7 @@ namespace AsbCloudApp.Repositories /// /// /// - Task?> GetByNamesAsync(IEnumerable names, CancellationToken token = default); + Task> GetByNamesAsync(IEnumerable names, CancellationToken token = default); /// /// получить все вложенные разрешения @@ -26,7 +26,7 @@ namespace AsbCloudApp.Repositories /// /// /// - IEnumerable? GetNestedById(int id, int counter = 10); + IEnumerable GetNestedById(int id, int counter = 10); /// /// определяет содержится ли разрешение в одной из указанных ролей diff --git a/AsbCloudInfrastructure/Repository/UserRepository.cs b/AsbCloudInfrastructure/Repository/UserRepository.cs index 1ba7f006..5c3e990b 100644 --- a/AsbCloudInfrastructure/Repository/UserRepository.cs +++ b/AsbCloudInfrastructure/Repository/UserRepository.cs @@ -1,7 +1,6 @@ using AsbCloudApp.Data; using AsbCloudApp.Exceptions; using AsbCloudApp.Repositories; -using AsbCloudApp.Services; using AsbCloudDb; using AsbCloudDb.Model; using AsbCloudInfrastructure.EfCache; @@ -136,20 +135,20 @@ namespace AsbCloudInfrastructure.Repository return count; } - public IEnumerable? GetRolesByIdUser(int idUser, int nestedLevel = 0) + public IEnumerable GetRolesByIdUser(int idUser, int nestedLevel = 0) { var roles = GetCachRelationUserUserRoleCacheTag().Where(r => r.IdUser == idUser); if (roles is null) - return null; + return Enumerable.Empty(); return roles.SelectMany(r => userRoleRepository.GetNestedById(r.IdUserRole, nestedLevel)); } - public IEnumerable? GetNestedPermissions(int idUser) + public IEnumerable GetNestedPermissions(int idUser) { var roles = GetRolesByIdUser(idUser, 7); if (roles is null) - return null; + return Enumerable.Empty(); ; var permissions = roles .Where(r => r.Permissions is not null) .SelectMany(r => r.Permissions); @@ -162,12 +161,13 @@ namespace AsbCloudInfrastructure.Repository if (idUser == 1) return true; - var relationsToRoles = GetCachRelationUserUserRoleCacheTag().Where(r => r.IdUser == idUser); + var relationsToRoles = GetCachRelationUserUserRoleCacheTag() + .Where(r => r.IdUser == idUser); if (relationsToRoles is null) return false; - return userRoleRepository.HasPermission(relationsToRoles.Select(r => r.IdUserRole), - permissionName); + return userRoleRepository.HasPermission(relationsToRoles + .Select(r => r.IdUserRole), permissionName); } private IEnumerable? GetRolesNamesByIdUser(int idUser) diff --git a/AsbCloudInfrastructure/Repository/UserRoleRepository.cs b/AsbCloudInfrastructure/Repository/UserRoleRepository.cs index 596ecfca..1c34f14a 100644 --- a/AsbCloudInfrastructure/Repository/UserRoleRepository.cs +++ b/AsbCloudInfrastructure/Repository/UserRoleRepository.cs @@ -53,13 +53,12 @@ namespace AsbCloudInfrastructure.Repository var entities = await GetCacheUserRoleAsync(token) .ConfigureAwait(false); - if (entities is not null) - { - var dtos = entities.Select(Convert); - return dtos; - } - else - return new List(); + if (entities is null) + return Enumerable.Empty(); + + var dtos = entities.Select(Convert); + return dtos; + } public UserRoleDto? GetOrDefault(int id) @@ -81,13 +80,17 @@ namespace AsbCloudInfrastructure.Repository return dto; } - public async Task?> GetByNamesAsync(IEnumerable names, CancellationToken token) + public async Task> GetByNamesAsync(IEnumerable names, CancellationToken token) { if (names?.Any() != true) - return null; - var entities = (await GetCacheUserRoleAsync(token)).Where(r => names.Contains(r.Caption)); + return Enumerable.Empty(); + + var entities = (await GetCacheUserRoleAsync(token)) + .Where(r => names.Contains(r.Caption)); + if (entities?.Count() != names.Count()) throw new ArgumentInvalidException("Invalid role names", nameof(names)); + var dtos = entities.Select(Convert); return dtos; } @@ -104,11 +107,12 @@ namespace AsbCloudInfrastructure.Repository return result?.Entity?.Id ?? 0; } - public IEnumerable? GetNestedById(int id, int recursionLevel = 7) + public IEnumerable GetNestedById(int id, int recursionLevel = 7) { var role = GetCacheUserRole().FirstOrDefault(r => r.Id == id); if (role is null) - return null; + return Enumerable.Empty(); + var dto = Convert(role); var roles = new SortedSet(ComparerIId.GetInstance()) { dto };