]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/middlewares/user-right.ts
Remove kue migration
[github/Chocobozzz/PeerTube.git] / server / middlewares / user-right.ts
CommitLineData
954605a8 1import * as express from 'express'
3fd3ab2d 2import 'express-validator'
954605a8 3import { UserRight } from '../../shared'
da854ddd 4import { logger } from '../helpers/logger'
3fd3ab2d 5import { UserModel } from '../models/account/user'
954605a8
C
6
7function ensureUserHasRight (userRight: UserRight) {
8 return function (req: express.Request, res: express.Response, next: express.NextFunction) {
3fd3ab2d 9 const user = res.locals.oauth.token.user as UserModel
954605a8 10 if (user.hasRight(userRight) === false) {
eec63bbc
C
11 const message = `User ${user.username} does not have right ${UserRight[userRight]} to access to ${req.path}.`
12 logger.info(message)
13
14 return res.status(403)
15 .json({
16 error: message
17 })
18 .end()
954605a8
C
19 }
20
21 return next()
22 }
23}
24
25// ---------------------------------------------------------------------------
26
27export {
28 ensureUserHasRight
29}