]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/middlewares/user-right.ts
Reorganize shared models
[github/Chocobozzz/PeerTube.git] / server / middlewares / user-right.ts
1 import * as express from 'express'
2 import { UserRight } from '../../shared'
3 import { logger } from '../helpers/logger'
4
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}.`
10 logger.info(message)
11
12 return res.status(403).json({ error: message })
13 }
14
15 return next()
16 }
17 }
18
19 // ---------------------------------------------------------------------------
20
21 export {
22 ensureUserHasRight
23 }