41 lines
1.0 KiB
TypeScript
41 lines
1.0 KiB
TypeScript
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());
|
|
}
|
|
}
|
|
}
|