1 import express from 'express'
2 import { HttpStatusCode, UserRight } from '@shared/models'
3 import { logger } from '../helpers/logger'
5 function ensureUserHasRight (userRight: UserRight) {
6 return function (req: express.Request, res: express.Response, next: express.NextFunction) {
7 const user = res.locals.oauth.token.user
8 if (user.hasRight(userRight) === false) {
9 const message = `User ${user.username} does not have right ${userRight} to access to ${req.path}.`
13 status: HttpStatusCode.FORBIDDEN_403,
22 // ---------------------------------------------------------------------------