31 lines
819 B
TypeScript
31 lines
819 B
TypeScript
|
|
import { FastifyRequest, FastifyReply } from 'fastify';
|
|
import { RequestRequirement } from '../RequestRequirement';
|
|
import { Message } from '../../../../browser/messages/Message';
|
|
|
|
export class UserHasPermission extends RequestRequirement
|
|
{
|
|
private _permissionID:string = "";
|
|
|
|
constructor( permissionID:string )
|
|
{
|
|
super();
|
|
this._permissionID = permissionID;
|
|
}
|
|
|
|
async handle( request:FastifyRequest, reply:FastifyReply ):Promise<Message[]>
|
|
{
|
|
let user = await this._handler.getUser();
|
|
|
|
let userDB = this._handler.userDB;
|
|
|
|
let hasPermission = await userDB.hasPermission( user, this._permissionID );
|
|
|
|
if ( ! hasPermission )
|
|
{
|
|
return Promise.resolve( [ Message.Error( "User has no permission for " + this._permissionID ) ] );
|
|
}
|
|
|
|
return Promise.resolve( [] );
|
|
}
|
|
} |