1 import * as express from 'express'
2 import 'express-validator'
3 import { UserRight } from '../../shared'
4 import { logger } from '../helpers'
5 import { UserModel } from '../models/account/user'
7 function ensureUserHasRight (userRight: UserRight) {
8 return function (req: express.Request, res: express.Response, next: express.NextFunction) {
9 const user = res.locals.oauth.token.user as UserModel
10 if (user.hasRight(userRight) === false) {
11 logger.info('User %s does not have right %s to access to %s.', user.username, UserRight[userRight], req.path)
12 return res.sendStatus(403)
19 // ---------------------------------------------------------------------------