]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/middlewares/user-right.ts
fix plugin storage return value when storing a Json array
[github/Chocobozzz/PeerTube.git] / server / middlewares / user-right.ts
CommitLineData
41fb13c3 1import express from 'express'
954605a8 2import { UserRight } from '../../shared'
c0e8b12e 3import { HttpStatusCode } from '../../shared/models/http/http-error-codes'
4c7e60bc 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) {
bd45d503 10 const message = `User ${user.username} does not have right ${userRight} to access to ${req.path}.`
eec63bbc
C
11 logger.info(message)
12
76148b27
RK
13 return res.fail({
14 status: HttpStatusCode.FORBIDDEN_403,
15 message
16 })
954605a8
C
17 }
18
19 return next()
20 }
21}
22
23// ---------------------------------------------------------------------------
24
25export {
26 ensureUserHasRight
27}