31 lines
788 B
TypeScript
31 lines
788 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.ums.getUser( request );
|
|
|
|
let userDB = this.ums.userDB;
|
|
|
|
let hasPermission = await userDB.hasPermission( user, this._permissionID );
|
|
|
|
if ( ! hasPermission )
|
|
{
|
|
return this.sendError( "User has no permission for " + this._permissionID );
|
|
}
|
|
|
|
return this.giveOK();
|
|
}
|
|
} |