]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/middlewares/validators/videos/video-watch.ts
Add ability to unpublish video/playlist
[github/Chocobozzz/PeerTube.git] / server / middlewares / validators / videos / video-watch.ts
index bca64662fbf9a0814a0af1dabd462915efcaf43a..a3a800d14f6023771047fdf34ccadbe885a760db 100644 (file)
@@ -1,7 +1,7 @@
 import { body, param } from 'express-validator/check'
 import * as express from 'express'
 import { isIdOrUUIDValid } from '../../../helpers/custom-validators/misc'
-import { isVideoExist } from '../../../helpers/custom-validators/videos'
+import { doesVideoExist } from '../../../helpers/custom-validators/videos'
 import { areValidationErrors } from '../utils'
 import { logger } from '../../../helpers/logger'
 
@@ -15,7 +15,13 @@ const videoWatchingValidator = [
     logger.debug('Checking videoWatching parameters', { parameters: req.body })
 
     if (areValidationErrors(req, res)) return
-    if (!await isVideoExist(req.params.videoId, res, 'id')) return
+    if (!await doesVideoExist(req.params.videoId, res, 'id')) return
+
+    const user = res.locals.oauth.token.User
+    if (user.videosHistoryEnabled === false) {
+      logger.warn('Cannot set videos to watch by user %d: videos history is disabled.', user.id)
+      return res.status(409).end()
+    }
 
     return next()
   }