23 lines
554 B
TypeScript
23 lines
554 B
TypeScript
|
|
|
||
|
|
import { FastifyRequest, FastifyReply } from 'fastify';
|
||
|
|
import { RequestRequirement } from '../RequestRequirement';
|
||
|
|
|
||
|
|
export class UserHasPermission extends RequestRequirement
|
||
|
|
{
|
||
|
|
private _permissionID:string = "";
|
||
|
|
|
||
|
|
constructor( permissionID:string )
|
||
|
|
{
|
||
|
|
super();
|
||
|
|
this._permissionID = permissionID;
|
||
|
|
}
|
||
|
|
|
||
|
|
async handle( request:FastifyRequest, reply:FastifyReply ):Promise<boolean>
|
||
|
|
{
|
||
|
|
let user = await this._handler.getUser();
|
||
|
|
|
||
|
|
let userDB = this._handler.userDB;
|
||
|
|
|
||
|
|
return userDB.hasPermission( user, this._permissionID );
|
||
|
|
}
|
||
|
|
}
|