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="names"></param>
|
||||||
/// <param name="token"></param>
|
/// <param name="token"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
Task<IEnumerable<UserRoleDto>?> GetByNamesAsync(IEnumerable<string> names, CancellationToken token = default);
|
Task<IEnumerable<UserRoleDto>> GetByNamesAsync(IEnumerable<string> names, CancellationToken token = default);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// получить все вложенные разрешения
|
/// получить все вложенные разрешения
|
||||||
@ -26,7 +26,7 @@ namespace AsbCloudApp.Repositories
|
|||||||
/// <param name="id"></param>
|
/// <param name="id"></param>
|
||||||
/// <param name="counter"></param>
|
/// <param name="counter"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
IEnumerable<UserRoleDto>? GetNestedById(int id, int counter = 10);
|
IEnumerable<UserRoleDto> GetNestedById(int id, int counter = 10);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// определяет содержится ли разрешение в одной из указанных ролей
|
/// определяет содержится ли разрешение в одной из указанных ролей
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
using AsbCloudApp.Data;
|
using AsbCloudApp.Data;
|
||||||
using AsbCloudApp.Exceptions;
|
using AsbCloudApp.Exceptions;
|
||||||
using AsbCloudApp.Repositories;
|
using AsbCloudApp.Repositories;
|
||||||
using AsbCloudApp.Services;
|
|
||||||
using AsbCloudDb;
|
using AsbCloudDb;
|
||||||
using AsbCloudDb.Model;
|
using AsbCloudDb.Model;
|
||||||
using AsbCloudInfrastructure.EfCache;
|
using AsbCloudInfrastructure.EfCache;
|
||||||
@ -136,20 +135,20 @@ namespace AsbCloudInfrastructure.Repository
|
|||||||
return count;
|
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);
|
var roles = GetCachRelationUserUserRoleCacheTag().Where(r => r.IdUser == idUser);
|
||||||
if (roles is null)
|
if (roles is null)
|
||||||
return null;
|
return Enumerable.Empty<UserRoleDto>();
|
||||||
|
|
||||||
return roles.SelectMany(r => userRoleRepository.GetNestedById(r.IdUserRole, nestedLevel));
|
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);
|
var roles = GetRolesByIdUser(idUser, 7);
|
||||||
if (roles is null)
|
if (roles is null)
|
||||||
return null;
|
return Enumerable.Empty<PermissionDto>(); ;
|
||||||
var permissions = roles
|
var permissions = roles
|
||||||
.Where(r => r.Permissions is not null)
|
.Where(r => r.Permissions is not null)
|
||||||
.SelectMany(r => r.Permissions);
|
.SelectMany(r => r.Permissions);
|
||||||
@ -162,12 +161,13 @@ namespace AsbCloudInfrastructure.Repository
|
|||||||
if (idUser == 1)
|
if (idUser == 1)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
var relationsToRoles = GetCachRelationUserUserRoleCacheTag().Where(r => r.IdUser == idUser);
|
var relationsToRoles = GetCachRelationUserUserRoleCacheTag()
|
||||||
|
.Where(r => r.IdUser == idUser);
|
||||||
if (relationsToRoles is null)
|
if (relationsToRoles is null)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return userRoleRepository.HasPermission(relationsToRoles.Select(r => r.IdUserRole),
|
return userRoleRepository.HasPermission(relationsToRoles
|
||||||
permissionName);
|
.Select(r => r.IdUserRole), permissionName);
|
||||||
}
|
}
|
||||||
|
|
||||||
private IEnumerable<string>? GetRolesNamesByIdUser(int idUser)
|
private IEnumerable<string>? GetRolesNamesByIdUser(int idUser)
|
||||||
|
@ -53,13 +53,12 @@ namespace AsbCloudInfrastructure.Repository
|
|||||||
var entities = await GetCacheUserRoleAsync(token)
|
var entities = await GetCacheUserRoleAsync(token)
|
||||||
.ConfigureAwait(false);
|
.ConfigureAwait(false);
|
||||||
|
|
||||||
if (entities is not null)
|
if (entities is null)
|
||||||
{
|
return Enumerable.Empty<UserRoleDto>();
|
||||||
var dtos = entities.Select(Convert);
|
|
||||||
return dtos;
|
var dtos = entities.Select(Convert);
|
||||||
}
|
return dtos;
|
||||||
else
|
|
||||||
return new List<UserRoleDto>();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public UserRoleDto? GetOrDefault(int id)
|
public UserRoleDto? GetOrDefault(int id)
|
||||||
@ -81,13 +80,17 @@ namespace AsbCloudInfrastructure.Repository
|
|||||||
return dto;
|
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)
|
if (names?.Any() != true)
|
||||||
return null;
|
return Enumerable.Empty<UserRoleDto>();
|
||||||
var entities = (await GetCacheUserRoleAsync(token)).Where(r => names.Contains(r.Caption));
|
|
||||||
|
var entities = (await GetCacheUserRoleAsync(token))
|
||||||
|
.Where(r => names.Contains(r.Caption));
|
||||||
|
|
||||||
if (entities?.Count() != names.Count())
|
if (entities?.Count() != names.Count())
|
||||||
throw new ArgumentInvalidException("Invalid role names", nameof(names));
|
throw new ArgumentInvalidException("Invalid role names", nameof(names));
|
||||||
|
|
||||||
var dtos = entities.Select(Convert);
|
var dtos = entities.Select(Convert);
|
||||||
return dtos;
|
return dtos;
|
||||||
}
|
}
|
||||||
@ -104,11 +107,12 @@ namespace AsbCloudInfrastructure.Repository
|
|||||||
return result?.Entity?.Id ?? 0;
|
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);
|
var role = GetCacheUserRole().FirstOrDefault(r => r.Id == id);
|
||||||
if (role is null)
|
if (role is null)
|
||||||
return null;
|
return Enumerable.Empty<UserRoleDto>();
|
||||||
|
|
||||||
var dto = Convert(role);
|
var dto = Convert(role);
|
||||||
var roles = new SortedSet<UserRoleDto>(ComparerIId.GetInstance()) { dto };
|
var roles = new SortedSet<UserRoleDto>(ComparerIId.GetInstance()) { dto };
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user