]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/middlewares/user-right.ts
Support studio transcoding in peertube runner
[github/Chocobozzz/PeerTube.git] / server / middlewares / user-right.ts
index bcebe9d7f09797c57988de94fcf58ac1556b549a..7d53e834125aeaa12226d6a055c5675a27a59cac 100644 (file)
@@ -1,16 +1,18 @@
-import 'express-validator'
-import * as express from 'express'
-
-import { UserInstance } from '../models'
-import { UserRight } from '../../shared'
-import { logger } from '../helpers'
+import express from 'express'
+import { HttpStatusCode, UserRight } from '@shared/models'
+import { logger } from '../helpers/logger'
 
 function ensureUserHasRight (userRight: UserRight) {
   return function (req: express.Request, res: express.Response, next: express.NextFunction) {
-    const user: UserInstance = res.locals.oauth.token.user
+    const user = res.locals.oauth.token.user
     if (user.hasRight(userRight) === false) {
-      logger.info('User %s does not have right %s to access to %s.', user.username, UserRight[userRight], req.path)
-      return res.sendStatus(403)
+      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()