mirror of
https://github.com/Chocobozzz/PeerTube.git
synced 2024-12-02 05:19:17 -06:00
28 lines
800 B
TypeScript
28 lines
800 B
TypeScript
import express from 'express'
|
|
import { UserRight } from '../../shared'
|
|
import { HttpStatusCode } from '../../shared/models/http/http-error-codes'
|
|
import { logger } from '../helpers/logger'
|
|
|
|
function ensureUserHasRight (userRight: UserRight) {
|
|
return function (req: express.Request, res: express.Response, next: express.NextFunction) {
|
|
const user = res.locals.oauth.token.user
|
|
if (user.hasRight(userRight) === false) {
|
|
const message = `User ${user.username} does not have right ${userRight} to access to ${req.path}.`
|
|
logger.info(message)
|
|
|
|
return res.fail({
|
|
status: HttpStatusCode.FORBIDDEN_403,
|
|
message
|
|
})
|
|
}
|
|
|
|
return next()
|
|
}
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
export {
|
|
ensureUserHasRight
|
|
}
|