forked from ddrilling/AsbCloudServer
#7205798 fix
This commit is contained in:
parent
211f300973
commit
950e7ad02a
@ -18,7 +18,7 @@ namespace AsbCloudApp.Repositories
|
||||
/// <param name="names"></param>
|
||||
/// <param name="token"></param>
|
||||
/// <returns></returns>
|
||||
Task<IEnumerable<UserRoleDto>?> GetByNamesAsync(IEnumerable<string> names, CancellationToken token = default);
|
||||
Task<IEnumerable<UserRoleDto>> GetByNamesAsync(IEnumerable<string> names, CancellationToken token = default);
|
||||
|
||||
/// <summary>
|
||||
/// получить все вложенные разрешения
|
||||
@ -26,7 +26,7 @@ namespace AsbCloudApp.Repositories
|
||||
/// <param name="id"></param>
|
||||
/// <param name="counter"></param>
|
||||
/// <returns></returns>
|
||||
IEnumerable<UserRoleDto>? GetNestedById(int id, int counter = 10);
|
||||
IEnumerable<UserRoleDto> GetNestedById(int id, int counter = 10);
|
||||
|
||||
/// <summary>
|
||||
/// определяет содержится ли разрешение в одной из указанных ролей
|
||||
|
@ -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<UserRoleDto>? GetRolesByIdUser(int idUser, int nestedLevel = 0)
|
||||
public IEnumerable<UserRoleDto> GetRolesByIdUser(int idUser, int nestedLevel = 0)
|
||||
{
|
||||
var roles = GetCachRelationUserUserRoleCacheTag().Where(r => r.IdUser == idUser);
|
||||
if (roles is null)
|
||||
return null;
|
||||
return Enumerable.Empty<UserRoleDto>();
|
||||
|
||||
return roles.SelectMany(r => userRoleRepository.GetNestedById(r.IdUserRole, nestedLevel));
|
||||
}
|
||||
|
||||
public IEnumerable<PermissionDto>? GetNestedPermissions(int idUser)
|
||||
public IEnumerable<PermissionDto> GetNestedPermissions(int idUser)
|
||||
{
|
||||
var roles = GetRolesByIdUser(idUser, 7);
|
||||
if (roles is null)
|
||||
return null;
|
||||
return Enumerable.Empty<PermissionDto>(); ;
|
||||
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<string>? GetRolesNamesByIdUser(int idUser)
|
||||
|
@ -53,13 +53,12 @@ namespace AsbCloudInfrastructure.Repository
|
||||
var entities = await GetCacheUserRoleAsync(token)
|
||||
.ConfigureAwait(false);
|
||||
|
||||
if (entities is not null)
|
||||
{
|
||||
if (entities is null)
|
||||
return Enumerable.Empty<UserRoleDto>();
|
||||
|
||||
var dtos = entities.Select(Convert);
|
||||
return dtos;
|
||||
}
|
||||
else
|
||||
return new List<UserRoleDto>();
|
||||
|
||||
}
|
||||
|
||||
public UserRoleDto? GetOrDefault(int id)
|
||||
@ -81,13 +80,17 @@ namespace AsbCloudInfrastructure.Repository
|
||||
return dto;
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<UserRoleDto>?> GetByNamesAsync(IEnumerable<string> names, CancellationToken token)
|
||||
public async Task<IEnumerable<UserRoleDto>> GetByNamesAsync(IEnumerable<string> names, CancellationToken token)
|
||||
{
|
||||
if (names?.Any() != true)
|
||||
return null;
|
||||
var entities = (await GetCacheUserRoleAsync(token)).Where(r => names.Contains(r.Caption));
|
||||
return Enumerable.Empty<UserRoleDto>();
|
||||
|
||||
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<UserRoleDto>? GetNestedById(int id, int recursionLevel = 7)
|
||||
public IEnumerable<UserRoleDto> GetNestedById(int id, int recursionLevel = 7)
|
||||
{
|
||||
var role = GetCacheUserRole().FirstOrDefault(r => r.Id == id);
|
||||
if (role is null)
|
||||
return null;
|
||||
return Enumerable.Empty<UserRoleDto>();
|
||||
|
||||
var dto = Convert(role);
|
||||
var roles = new SortedSet<UserRoleDto>(ComparerIId.GetInstance()) { dto };
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user