]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/middlewares/user-right.ts
Fix search with bad webfinger handles
[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'
954605a8
C
5
6function ensureUserHasRight (userRight: UserRight) {
7 return function (req: express.Request, res: express.Response, next: express.NextFunction) {
dae86118 8 const user = res.locals.oauth.token.user
954605a8 9 if (user.hasRight(userRight) === false) {
eec63bbc
C
10 const message = `User ${user.username} does not have right ${UserRight[userRight]} to access to ${req.path}.`
11 logger.info(message)
12
13 return res.status(403)
14 .json({
15 error: message
16 })
17 .end()
954605a8
C
18 }
19
20 return next()
21 }
22}
23
24// ---------------------------------------------------------------------------
25
26export {
27 ensureUserHasRight
28}