parent
37fc167002
commit
cd7b15aadf
|
@ -3,6 +3,7 @@ import { ChildEntity, Column, JoinTable, ManyToMany, OneToMany } from "typeorm";
|
|||
import { config } from '../../config';
|
||||
import { ResponsePrincipal } from '../responses/ResponsePrincipal';
|
||||
import { ResponseUser } from '../responses/ResponseUser';
|
||||
import { Permission } from './Permission';
|
||||
import { Principal } from './Principal';
|
||||
import { UserAction } from './UserAction';
|
||||
import { UserGroup } from './UserGroup';
|
||||
|
@ -129,8 +130,24 @@ export class User extends Principal {
|
|||
@OneToMany(() => UserAction, action => action.user, { nullable: true })
|
||||
actions: UserAction[]
|
||||
|
||||
/**
|
||||
* Resolves all permissions granted to this user through groups.
|
||||
*/
|
||||
public get inheritedPermissions(): Permission[] {
|
||||
let returnPermissions: Permission[] = new Array<Permission>();
|
||||
|
||||
if (!this.groups) { return returnPermissions; }
|
||||
for (let group of this.groups) {
|
||||
for (let permission of group.permissions) {
|
||||
returnPermissions.push(permission);
|
||||
}
|
||||
}
|
||||
return returnPermissions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolves all permissions granted to this user through groups or directly to the string enum format.
|
||||
* Also deduplicates the array.
|
||||
*/
|
||||
public get allPermissions(): string[] {
|
||||
let returnPermissions: string[] = new Array<string>();
|
||||
|
|
Loading…
Reference in New Issue