]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/middlewares/user-right.ts
fix account URI in remote comment modal (partial rollback)
[github/Chocobozzz/PeerTube.git] / server / middlewares / user-right.ts
1 import * as express from 'express'
2 import 'express-validator'
3 import { UserRight } from '../../shared'
4 import { logger } from '../helpers/logger'
5 import { UserModel } from '../models/account/user'
6
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 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()
19 }
20
21 return next()
22 }
23 }
24
25 // ---------------------------------------------------------------------------
26
27 export {
28 ensureUserHasRight
29 }