diff options
Diffstat (limited to 'server/middlewares')
-rw-r--r-- | server/middlewares/validators/users.ts | 5 | ||||
-rw-r--r-- | server/middlewares/validators/video-comments.ts | 14 | ||||
-rw-r--r-- | server/middlewares/validators/videos.ts | 10 |
3 files changed, 22 insertions, 7 deletions
diff --git a/server/middlewares/validators/users.ts b/server/middlewares/validators/users.ts index 42ebddd56..7c77e9a39 100644 --- a/server/middlewares/validators/users.ts +++ b/server/middlewares/validators/users.ts | |||
@@ -3,11 +3,10 @@ import 'express-validator' | |||
3 | import { body, param } from 'express-validator/check' | 3 | import { body, param } from 'express-validator/check' |
4 | import { isIdOrUUIDValid } from '../../helpers/custom-validators/misc' | 4 | import { isIdOrUUIDValid } from '../../helpers/custom-validators/misc' |
5 | import { | 5 | import { |
6 | isAvatarFile, | 6 | isAvatarFile, isUserAutoPlayVideoValid, isUserDisplayNSFWValid, isUserPasswordValid, isUserRoleValid, isUserUsernameValid, |
7 | isUserAutoPlayVideoValid, isUserDisplayNSFWValid, isUserPasswordValid, isUserRoleValid, isUserUsernameValid, | ||
8 | isUserVideoQuotaValid | 7 | isUserVideoQuotaValid |
9 | } from '../../helpers/custom-validators/users' | 8 | } from '../../helpers/custom-validators/users' |
10 | import { isVideoExist, isVideoFile } from '../../helpers/custom-validators/videos' | 9 | import { isVideoExist } from '../../helpers/custom-validators/videos' |
11 | import { logger } from '../../helpers/logger' | 10 | import { logger } from '../../helpers/logger' |
12 | import { isSignupAllowed } from '../../helpers/utils' | 11 | import { isSignupAllowed } from '../../helpers/utils' |
13 | import { CONSTRAINTS_FIELDS } from '../../initializers' | 12 | import { CONSTRAINTS_FIELDS } from '../../initializers' |
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 = [ | |||
45 | 45 | ||
46 | if (areValidationErrors(req, res)) return | 46 | if (areValidationErrors(req, res)) return |
47 | if (!await isVideoExist(req.params.videoId, res)) return | 47 | if (!await isVideoExist(req.params.videoId, res)) return |
48 | if (!isVideoCommentsEnabled(res.locals.video, res)) return | ||
48 | 49 | ||
49 | return next() | 50 | return next() |
50 | } | 51 | } |
@@ -60,6 +61,7 @@ const addVideoCommentReplyValidator = [ | |||
60 | 61 | ||
61 | if (areValidationErrors(req, res)) return | 62 | if (areValidationErrors(req, res)) return |
62 | if (!await isVideoExist(req.params.videoId, res)) return | 63 | if (!await isVideoExist(req.params.videoId, res)) return |
64 | if (!isVideoCommentsEnabled(res.locals.video, res)) return | ||
63 | if (!await isVideoCommentExist(req.params.commentId, res.locals.video, res)) return | 65 | if (!await isVideoCommentExist(req.params.commentId, res.locals.video, res)) return |
64 | 66 | ||
65 | return next() | 67 | return next() |
@@ -146,3 +148,15 @@ async function isVideoCommentExist (id: number, video: VideoModel, res: express. | |||
146 | res.locals.videoComment = videoComment | 148 | res.locals.videoComment = videoComment |
147 | return true | 149 | return true |
148 | } | 150 | } |
151 | |||
152 | function isVideoCommentsEnabled (video: VideoModel, res: express.Response) { | ||
153 | if (video.commentsEnabled !== true) { | ||
154 | res.status(409) | ||
155 | .json({ error: 'Video comments are disabled for this video.' }) | ||
156 | .end() | ||
157 | |||
158 | return false | ||
159 | } | ||
160 | |||
161 | return true | ||
162 | } | ||
diff --git a/server/middlewares/validators/videos.ts b/server/middlewares/validators/videos.ts index bffc50322..e8cb2ae03 100644 --- a/server/middlewares/validators/videos.ts +++ b/server/middlewares/validators/videos.ts | |||
@@ -2,10 +2,10 @@ import * as express from 'express' | |||
2 | import 'express-validator' | 2 | import 'express-validator' |
3 | import { body, param, query } from 'express-validator/check' | 3 | import { body, param, query } from 'express-validator/check' |
4 | import { UserRight, VideoPrivacy } from '../../../shared' | 4 | import { UserRight, VideoPrivacy } from '../../../shared' |
5 | import { isIdOrUUIDValid, isIdValid } from '../../helpers/custom-validators/misc' | 5 | import { isBooleanValid, isIdOrUUIDValid, isIdValid } from '../../helpers/custom-validators/misc' |
6 | import { | 6 | import { |
7 | isVideoAbuseReasonValid, isVideoCategoryValid, isVideoDescriptionValid, isVideoExist, isVideoFile, isVideoLanguageValid, | 7 | isVideoAbuseReasonValid, isVideoCategoryValid, isVideoDescriptionValid, isVideoExist, isVideoFile, isVideoLanguageValid, |
8 | isVideoLicenceValid, isVideoNameValid, isVideoNSFWValid, isVideoPrivacyValid, isVideoRatingTypeValid, isVideoTagsValid | 8 | isVideoLicenceValid, isVideoNameValid, isVideoPrivacyValid, isVideoRatingTypeValid, isVideoTagsValid |
9 | } from '../../helpers/custom-validators/videos' | 9 | } from '../../helpers/custom-validators/videos' |
10 | import { getDurationFromVideoFile } from '../../helpers/ffmpeg-utils' | 10 | import { getDurationFromVideoFile } from '../../helpers/ffmpeg-utils' |
11 | import { logger } from '../../helpers/logger' | 11 | import { logger } from '../../helpers/logger' |
@@ -26,11 +26,12 @@ const videosAddValidator = [ | |||
26 | body('category').optional().custom(isVideoCategoryValid).withMessage('Should have a valid category'), | 26 | body('category').optional().custom(isVideoCategoryValid).withMessage('Should have a valid category'), |
27 | body('licence').optional().custom(isVideoLicenceValid).withMessage('Should have a valid licence'), | 27 | body('licence').optional().custom(isVideoLicenceValid).withMessage('Should have a valid licence'), |
28 | body('language').optional().custom(isVideoLanguageValid).withMessage('Should have a valid language'), | 28 | body('language').optional().custom(isVideoLanguageValid).withMessage('Should have a valid language'), |
29 | body('nsfw').custom(isVideoNSFWValid).withMessage('Should have a valid NSFW attribute'), | 29 | body('nsfw').custom(isBooleanValid).withMessage('Should have a valid NSFW attribute'), |
30 | body('description').optional().custom(isVideoDescriptionValid).withMessage('Should have a valid description'), | 30 | body('description').optional().custom(isVideoDescriptionValid).withMessage('Should have a valid description'), |
31 | body('channelId').custom(isIdValid).withMessage('Should have correct video channel id'), | 31 | body('channelId').custom(isIdValid).withMessage('Should have correct video channel id'), |
32 | body('privacy').custom(isVideoPrivacyValid).withMessage('Should have correct video privacy'), | 32 | body('privacy').custom(isVideoPrivacyValid).withMessage('Should have correct video privacy'), |
33 | body('tags').optional().custom(isVideoTagsValid).withMessage('Should have correct tags'), | 33 | body('tags').optional().custom(isVideoTagsValid).withMessage('Should have correct tags'), |
34 | body('commentsEnabled').custom(isBooleanValid).withMessage('Should have comments enabled boolean'), | ||
34 | 35 | ||
35 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { | 36 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { |
36 | logger.debug('Checking videosAdd parameters', { parameters: req.body, files: req.files }) | 37 | logger.debug('Checking videosAdd parameters', { parameters: req.body, files: req.files }) |
@@ -85,10 +86,11 @@ const videosUpdateValidator = [ | |||
85 | body('category').optional().custom(isVideoCategoryValid).withMessage('Should have a valid category'), | 86 | body('category').optional().custom(isVideoCategoryValid).withMessage('Should have a valid category'), |
86 | body('licence').optional().custom(isVideoLicenceValid).withMessage('Should have a valid licence'), | 87 | body('licence').optional().custom(isVideoLicenceValid).withMessage('Should have a valid licence'), |
87 | body('language').optional().custom(isVideoLanguageValid).withMessage('Should have a valid language'), | 88 | body('language').optional().custom(isVideoLanguageValid).withMessage('Should have a valid language'), |
88 | body('nsfw').optional().custom(isVideoNSFWValid).withMessage('Should have a valid NSFW attribute'), | 89 | body('nsfw').optional().custom(isBooleanValid).withMessage('Should have a valid NSFW attribute'), |
89 | body('privacy').optional().custom(isVideoPrivacyValid).withMessage('Should have correct video privacy'), | 90 | body('privacy').optional().custom(isVideoPrivacyValid).withMessage('Should have correct video privacy'), |
90 | body('description').optional().custom(isVideoDescriptionValid).withMessage('Should have a valid description'), | 91 | body('description').optional().custom(isVideoDescriptionValid).withMessage('Should have a valid description'), |
91 | body('tags').optional().custom(isVideoTagsValid).withMessage('Should have correct tags'), | 92 | body('tags').optional().custom(isVideoTagsValid).withMessage('Should have correct tags'), |
93 | body('commentsEnabled').optional().custom(isBooleanValid).withMessage('Should have comments enabled boolean'), | ||
92 | 94 | ||
93 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { | 95 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { |
94 | logger.debug('Checking videosUpdate parameters', { parameters: req.body }) | 96 | logger.debug('Checking videosUpdate parameters', { parameters: req.body }) |