X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fmiddlewares%2Fvalidators%2Fvideos.js;h=1b6dbccf08358f44706c04d86f1297596714f9be;hb=efe923bcdaf15b47593ad8583df09a92c715ac6c;hp=09a188c765ae3dac558601e2e1b0b5582ea602f0;hpb=7b1f49de22c40ae121ddb3c399b2540ba56fd414;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/middlewares/validators/videos.js b/server/middlewares/validators/videos.js index 09a188c76..1b6dbccf0 100644 --- a/server/middlewares/validators/videos.js +++ b/server/middlewares/validators/videos.js @@ -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.authorId !== res.locals.oauth.token.User.id) { + return res.status(403).send('Cannot remove video of another user') + } next() })