Added a new endpoint that returns a users permissions as objects sorted into two arrays
All checks were successful
continuous-integration/drone/pr Build is passing

ref #93
This commit is contained in:
2021-01-13 18:19:59 +01:00
parent cd7b15aadf
commit b01e1eb8a1
3 changed files with 56 additions and 2 deletions

View File

@@ -70,6 +70,7 @@ export class ResponseUser extends ResponsePrincipal {
/**
* The user's permissions.
* Directly granted or inherited converted to their string form and deduplicated.
*/
@IsArray()
@IsOptional()

View File

@@ -0,0 +1,40 @@
import {
IsArray,
IsOptional
} from "class-validator";
import { User } from '../entities/User';
import { ResponsePermission } from './ResponsePermission';
/**
* Defines the user permission response (get /api/users/:id/permissions).
*/
export class ResponseUserPermissions {
/**
* The permissions directly granted to the user.
*/
@IsArray()
@IsOptional()
directlyGranted: ResponsePermission[] = new Array<ResponsePermission>();
/**
* The permissions directly inherited the user.
*/
@IsArray()
@IsOptional()
inherited: ResponsePermission[] = new Array<ResponsePermission>();
/**
* Creates a ResponseUserPermissions object from a user.
* @param user The user the response shall be build for.
*/
public constructor(user: User) {
for (let permission of user.permissions) {
this.directlyGranted.push(permission.toResponse());
}
for (let permission of user.inheritedPermissions) {
this.inherited.push(permission.toResponse());
}
}
}