From 40145f7d5b3abbb1b1383e46239bbcd5ba669556 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A4=D1=80=D0=BE=D0=BB=D0=BE=D0=B2?= Date: Wed, 22 Dec 2021 11:35:36 +0500 Subject: [PATCH] Fix UserRole multiple permissions --- AsbCloudInfrastructure/Services/UserRoleService.cs | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/AsbCloudInfrastructure/Services/UserRoleService.cs b/AsbCloudInfrastructure/Services/UserRoleService.cs index 6675757e..5e41ad83 100644 --- a/AsbCloudInfrastructure/Services/UserRoleService.cs +++ b/AsbCloudInfrastructure/Services/UserRoleService.cs @@ -15,13 +15,13 @@ namespace AsbCloudInfrastructure.Services { private readonly CacheTable cacheUserRoles; private readonly CacheTable cacheUserRolePermissions; - - public List Includes { get; } + + public ISet Includes { get; } = new SortedSet(); public UserRoleService(IAsbCloudDbContext context, CacheDb cacheDb) { - cacheUserRoles = cacheDb.GetCachedTable((AsbCloudDbContext)context, new [] { nameof(UserRole.RelationUserRolePermissions) }); - cacheUserRolePermissions = cacheDb.GetCachedTable((AsbCloudDbContext)context, new[] { nameof(RelationUserRolePermission.Permission) }); + cacheUserRoles = cacheDb.GetCachedTable((AsbCloudDbContext)context, nameof(UserRole.RelationUserRolePermissions)); + cacheUserRolePermissions = cacheDb.GetCachedTable((AsbCloudDbContext)context, nameof(RelationUserRolePermission.Permission)); } public async Task InsertAsync(UserRoleDto dto, CancellationToken token = default) @@ -129,8 +129,6 @@ namespace AsbCloudInfrastructure.Services .ConfigureAwait(false); } - - public Task DeleteAsync(int id, CancellationToken token = default) => cacheUserRoles.RemoveAsync(r => r.Id == id, token); @@ -177,9 +175,8 @@ namespace AsbCloudInfrastructure.Services var dto = entity.Adapt(); if(entity.RelationUserRolePermissions?.Any() == true) { - var permissionsIds = entity.RelationUserRolePermissions.Select(r => r.IdPermission); dto.Permissions = cacheUserRolePermissions - .Where(r => permissionsIds.Contains(r.IdPermission)) + .Where(r => entity.Id == r.IdUserRole) .Select(r => Convert(r.Permission)); } return dto;