49 lines
1.0 KiB
TypeScript
49 lines
1.0 KiB
TypeScript
import {
|
|
IsEnum,
|
|
IsInt,
|
|
IsNotEmpty
|
|
} from "class-validator";
|
|
import { Column, Entity, ManyToOne, PrimaryGeneratedColumn } from "typeorm";
|
|
import { PermissionAction } from '../enums/PermissionAction';
|
|
import { PermissionTarget } from '../enums/PermissionTargets';
|
|
import { Principal } from './Principal';
|
|
/**
|
|
* Defines the Permission interface.
|
|
*/
|
|
@Entity()
|
|
export class Permission {
|
|
/**
|
|
* Autogenerated unique id (primary key).
|
|
*/
|
|
@PrimaryGeneratedColumn()
|
|
@IsInt()
|
|
id: number;
|
|
|
|
/**
|
|
* The permissions principal
|
|
*/
|
|
@ManyToOne(() => Principal, principal => principal.permissions)
|
|
principal: Principal;
|
|
|
|
/**
|
|
* The target
|
|
*/
|
|
@Column({ type: 'varchar' })
|
|
@IsNotEmpty()
|
|
@IsEnum(PermissionTarget)
|
|
target: PermissionTarget;
|
|
|
|
/**
|
|
* The action type
|
|
*/
|
|
@Column({ type: 'varchar' })
|
|
@IsEnum(PermissionAction)
|
|
action: PermissionAction;
|
|
|
|
/**
|
|
* Turn this into a string for exporting (and jwts).
|
|
*/
|
|
public toString(): string {
|
|
return this.target + ":" + this.action;
|
|
}
|
|
} |