]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/middlewares/validators/videos.js
Server: fix video remoe validation
[github/Chocobozzz/PeerTube.git] / server / middlewares / validators / videos.js
index 09a188c765ae3dac558601e2e1b0b5582ea602f0..295ed05fa054ad99fe2d1d88abe97feb0dfe0f9b 100644 (file)
@@ -71,15 +71,16 @@ function videosRemove (req, res, next) {
   logger.debug('Checking videosRemove parameters', { parameters: req.params })
 
   checkErrors(req, res, function () {
-    db.Video.loadAndPopulateAuthor(req.params.id, function (err, video) {
-      if (err) {
-        logger.error('Error in videosRemove request validator.', { error: err })
-        return res.sendStatus(500)
+    checkVideoExists(req.params.id, res, function () {
+      // We need to make additional checks
+
+      if (res.locals.video.isOwned() === false) {
+        return res.status(403).send('Cannot remove video of another pod')
       }
 
-      if (!video) return res.status(404).send('Video not found')
-      else if (video.isOwned() === false) return res.status(403).send('Cannot remove video of another pod')
-      else if (video.Author.name !== res.locals.oauth.token.user.username) return res.status(403).send('Cannot remove video of another user')
+      if (res.locals.video.Author.userId !== res.locals.oauth.token.User.id) {
+        return res.status(403).send('Cannot remove video of another user')
+      }
 
       next()
     })