@@ -128,6 +128,24 @@ export class User extends Principal {
|
||||
@OneToMany(() => UserAction, action => action.user, { nullable: true })
|
||||
actions: UserAction[]
|
||||
|
||||
/**
|
||||
* Resolves all permissions granted to this user through groups or directly to the string enum format.
|
||||
*/
|
||||
public get allPermissions(): string[] {
|
||||
let allPermissions = new Array<string>();
|
||||
for (let permission in this.permissions) {
|
||||
allPermissions.push(permission.toString());
|
||||
}
|
||||
|
||||
for (let group of this.groups) {
|
||||
for (let permission in group.permissions) {
|
||||
allPermissions.push(permission.toString());
|
||||
}
|
||||
}
|
||||
console.log(allPermissions)
|
||||
return Array.from(new Set(allPermissions));
|
||||
}
|
||||
|
||||
/**
|
||||
* Turns this entity into it's response class.
|
||||
*/
|
||||
|
||||
@@ -5,7 +5,6 @@ import {
|
||||
IsOptional,
|
||||
IsString
|
||||
} from "class-validator";
|
||||
import { Permission } from '../entities/Permission';
|
||||
import { User } from '../entities/User';
|
||||
import { UserGroup } from '../entities/UserGroup';
|
||||
import { ResponsePrincipal } from './ResponsePrincipal';
|
||||
@@ -74,7 +73,7 @@ export class ResponseUser extends ResponsePrincipal {
|
||||
*/
|
||||
@IsArray()
|
||||
@IsOptional()
|
||||
permissions: Permission[];
|
||||
permissions: string[];
|
||||
|
||||
/**
|
||||
* Creates a ResponseUser object from a user.
|
||||
@@ -91,6 +90,6 @@ export class ResponseUser extends ResponsePrincipal {
|
||||
this.enabled = user.enabled;
|
||||
this.profilePic = user.profilePic;
|
||||
this.groups = user.groups;
|
||||
this.permissions = user.permissions;
|
||||
this.permissions = user.allPermissions;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user