@@ -8,7 +8,9 @@ import { PermissionAction } from '../enums/PermissionAction';
|
||||
import { PermissionTarget } from '../enums/PermissionTargets';
|
||||
import { Principal } from './Principal';
|
||||
/**
|
||||
* Defines the Permission interface.
|
||||
* Defines the Permission entity.
|
||||
* Permissions can be granted to principals.
|
||||
* The permissions possible targets and actions are defined in enums.
|
||||
*/
|
||||
@Entity()
|
||||
export class Permission {
|
||||
@@ -20,13 +22,14 @@ export class Permission {
|
||||
id: number;
|
||||
|
||||
/**
|
||||
* The permissions principal
|
||||
* The permission's principal.
|
||||
*/
|
||||
@ManyToOne(() => Principal, principal => principal.permissions)
|
||||
principal: Principal;
|
||||
|
||||
/**
|
||||
* The target
|
||||
* The permission's target.
|
||||
* This get's stored as the enum value's string representation for compatability reasons.
|
||||
*/
|
||||
@Column({ type: 'varchar' })
|
||||
@IsNotEmpty()
|
||||
@@ -34,14 +37,16 @@ export class Permission {
|
||||
target: PermissionTarget;
|
||||
|
||||
/**
|
||||
* The action type
|
||||
* The permission's action.
|
||||
* This get's stored as the enum value's string representation for compatability reasons.
|
||||
*/
|
||||
@Column({ type: 'varchar' })
|
||||
@IsEnum(PermissionAction)
|
||||
action: PermissionAction;
|
||||
|
||||
/**
|
||||
* Turn this into a string for exporting (and jwts).
|
||||
* Turn this into a string for exporting and jwts.
|
||||
* Mainly used to shrink the size of jwts (otherwise the would contain entire objects).
|
||||
*/
|
||||
public toString(): string {
|
||||
return this.target + ":" + this.action;
|
||||
|
||||
Reference in New Issue
Block a user