From 47564bbe2eeb2baae9b7e3f9b2b8d16522bc7e04 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 3 Jan 2018 10:12:36 +0100 Subject: Add ability to disable video comments --- server/middlewares/validators/video-comments.ts | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'server/middlewares/validators/video-comments.ts') diff --git a/server/middlewares/validators/video-comments.ts b/server/middlewares/validators/video-comments.ts index fdd092571..ade0b7b9f 100644 --- a/server/middlewares/validators/video-comments.ts +++ b/server/middlewares/validators/video-comments.ts @@ -45,6 +45,7 @@ const addVideoCommentThreadValidator = [ if (areValidationErrors(req, res)) return if (!await isVideoExist(req.params.videoId, res)) return + if (!isVideoCommentsEnabled(res.locals.video, res)) return return next() } @@ -60,6 +61,7 @@ const addVideoCommentReplyValidator = [ if (areValidationErrors(req, res)) return if (!await isVideoExist(req.params.videoId, res)) return + if (!isVideoCommentsEnabled(res.locals.video, res)) return if (!await isVideoCommentExist(req.params.commentId, res.locals.video, res)) return return next() @@ -146,3 +148,15 @@ async function isVideoCommentExist (id: number, video: VideoModel, res: express. res.locals.videoComment = videoComment return true } + +function isVideoCommentsEnabled (video: VideoModel, res: express.Response) { + if (video.commentsEnabled !== true) { + res.status(409) + .json({ error: 'Video comments are disabled for this video.' }) + .end() + + return false + } + + return true +} -- cgit v1.2.3