Fix UserService.GetNestedPermissions(). returns all permissions for all nested roles

This commit is contained in:
Фролов 2022-03-15 16:19:51 +05:00
parent fdc22f4f94
commit 007f7ac62e
3 changed files with 5 additions and 4 deletions

View File

@ -7,7 +7,7 @@ namespace AsbCloudApp.Services
{ {
IUserRoleService RoleService { get; } IUserRoleService RoleService { get; }
IEnumerable<PermissionDto> GetNestedPermissions(int idUser); IEnumerable<PermissionDto> GetNestedPermissions(int idUser);
IEnumerable<UserRoleDto> GetRolesByIdUser(int idUser); IEnumerable<UserRoleDto> GetRolesByIdUser(int idUser, int nestedLevel = 0);
bool HasAnyRoleOf(int idUser, IEnumerable<string> roleNames); bool HasAnyRoleOf(int idUser, IEnumerable<string> roleNames);
bool HasAnyRoleOf(int idUser, IEnumerable<int> roleIds); bool HasAnyRoleOf(int idUser, IEnumerable<int> roleIds);
public bool HasPermission(int idUser, string permissionName); public bool HasPermission(int idUser, string permissionName);

View File

@ -8,3 +8,4 @@ SELECT timescaledb_pre_restore();
SELECT timescaledb_post_restore(); SELECT timescaledb_post_restore();
select * from t_telemetry_message ttm where id_event = 206;

View File

@ -130,17 +130,17 @@ namespace AsbCloudInfrastructure.Services
?.Select(r => r.Caption) ?.Select(r => r.Caption)
.Distinct(); .Distinct();
public IEnumerable<UserRoleDto> GetRolesByIdUser(int idUser) public IEnumerable<UserRoleDto> GetRolesByIdUser(int idUser, int nestedLevel = 0)
{ {
var roles = cacheRelationUserToRoles.Where(r => r.IdUser == idUser); var roles = cacheRelationUserToRoles.Where(r => r.IdUser == idUser);
if (roles?.Any() != true) if (roles?.Any() != true)
return null; return null;
return roles.SelectMany(r => RoleService.GetNestedById(r.IdUserRole, 0)); return roles.SelectMany(r => RoleService.GetNestedById(r.IdUserRole, nestedLevel));
} }
public IEnumerable<PermissionDto> GetNestedPermissions(int idUser) public IEnumerable<PermissionDto> GetNestedPermissions(int idUser)
{ {
var roles = GetRolesByIdUser(idUser); var roles = GetRolesByIdUser(idUser, 7);
if(roles?.Any() != true) if(roles?.Any() != true)
return null; return null;
var permissions = roles var permissions = roles