aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/middlewares/validators
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2018-08-10 16:54:01 +0200
committerChocobozzz <me@florianbigard.com>2018-08-10 16:54:01 +0200
commit268eebed921ac13a9ce0f4717f4923aa24190657 (patch)
tree52f8436968c8dcc686663ef5db8dffd7ed191d34 /server/middlewares/validators
parent904a463c7792837f0a468a522a28448323e48593 (diff)
downloadPeerTube-268eebed921ac13a9ce0f4717f4923aa24190657.tar.gz
PeerTube-268eebed921ac13a9ce0f4717f4923aa24190657.tar.zst
PeerTube-268eebed921ac13a9ce0f4717f4923aa24190657.zip
Add state and moderationComment for abuses on server side
Diffstat (limited to 'server/middlewares/validators')
-rw-r--r--server/middlewares/validators/index.ts1
-rw-r--r--server/middlewares/validators/video-abuses.ts71
-rw-r--r--server/middlewares/validators/videos.ts17
3 files changed, 72 insertions, 17 deletions
diff --git a/server/middlewares/validators/index.ts b/server/middlewares/validators/index.ts
index c5400c8f5..ccbedd57d 100644
--- a/server/middlewares/validators/index.ts
+++ b/server/middlewares/validators/index.ts
@@ -7,6 +7,7 @@ export * from './feeds'
7export * from './sort' 7export * from './sort'
8export * from './users' 8export * from './users'
9export * from './videos' 9export * from './videos'
10export * from './video-abuses'
10export * from './video-blacklist' 11export * from './video-blacklist'
11export * from './video-channels' 12export * from './video-channels'
12export * from './webfinger' 13export * from './webfinger'
diff --git a/server/middlewares/validators/video-abuses.ts b/server/middlewares/validators/video-abuses.ts
new file mode 100644
index 000000000..f15d55a75
--- /dev/null
+++ b/server/middlewares/validators/video-abuses.ts
@@ -0,0 +1,71 @@
1import * as express from 'express'
2import 'express-validator'
3import { body, param } from 'express-validator/check'
4import { isIdOrUUIDValid, isIdValid } from '../../helpers/custom-validators/misc'
5import { isVideoExist } from '../../helpers/custom-validators/videos'
6import { logger } from '../../helpers/logger'
7import { areValidationErrors } from './utils'
8import {
9 isVideoAbuseExist,
10 isVideoAbuseModerationCommentValid,
11 isVideoAbuseReasonValid,
12 isVideoAbuseStateValid
13} from '../../helpers/custom-validators/video-abuses'
14
15const videoAbuseReportValidator = [
16 param('videoId').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid videoId'),
17 body('reason').custom(isVideoAbuseReasonValid).withMessage('Should have a valid reason'),
18
19 async (req: express.Request, res: express.Response, next: express.NextFunction) => {
20 logger.debug('Checking videoAbuseReport parameters', { parameters: req.body })
21
22 if (areValidationErrors(req, res)) return
23 if (!await isVideoExist(req.params.videoId, res)) return
24
25 return next()
26 }
27]
28
29const videoAbuseGetValidator = [
30 param('videoId').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid videoId'),
31 param('id').custom(isIdValid).not().isEmpty().withMessage('Should have a valid id'),
32
33 async (req: express.Request, res: express.Response, next: express.NextFunction) => {
34 logger.debug('Checking videoAbuseGetValidator parameters', { parameters: req.body })
35
36 if (areValidationErrors(req, res)) return
37 if (!await isVideoExist(req.params.videoId, res)) return
38 if (!await isVideoAbuseExist(req.params.id, res.locals.video.id, res)) return
39
40 return next()
41 }
42]
43
44const videoAbuseUpdateValidator = [
45 param('videoId').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid videoId'),
46 param('id').custom(isIdValid).not().isEmpty().withMessage('Should have a valid id'),
47 body('state')
48 .optional()
49 .custom(isVideoAbuseStateValid).withMessage('Should have a valid video abuse state'),
50 body('moderationComment')
51 .optional()
52 .custom(isVideoAbuseModerationCommentValid).withMessage('Should have a valid video moderation comment'),
53
54 async (req: express.Request, res: express.Response, next: express.NextFunction) => {
55 logger.debug('Checking videoAbuseUpdateValidator parameters', { parameters: req.body })
56
57 if (areValidationErrors(req, res)) return
58 if (!await isVideoExist(req.params.videoId, res)) return
59 if (!await isVideoAbuseExist(req.params.id, res.locals.video.id, res)) return
60
61 return next()
62 }
63]
64
65// ---------------------------------------------------------------------------
66
67export {
68 videoAbuseReportValidator,
69 videoAbuseGetValidator,
70 videoAbuseUpdateValidator
71}
diff --git a/server/middlewares/validators/videos.ts b/server/middlewares/validators/videos.ts
index c812d4677..203a00876 100644
--- a/server/middlewares/validators/videos.ts
+++ b/server/middlewares/validators/videos.ts
@@ -14,7 +14,6 @@ import {
14import { 14import {
15 checkUserCanManageVideo, 15 checkUserCanManageVideo,
16 isScheduleVideoUpdatePrivacyValid, 16 isScheduleVideoUpdatePrivacyValid,
17 isVideoAbuseReasonValid,
18 isVideoCategoryValid, 17 isVideoCategoryValid,
19 isVideoChannelOfAccountExist, 18 isVideoChannelOfAccountExist,
20 isVideoDescriptionValid, 19 isVideoDescriptionValid,
@@ -174,20 +173,6 @@ const videosRemoveValidator = [
174 } 173 }
175] 174]
176 175
177const videoAbuseReportValidator = [
178 param('id').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid id'),
179 body('reason').custom(isVideoAbuseReasonValid).withMessage('Should have a valid reason'),
180
181 async (req: express.Request, res: express.Response, next: express.NextFunction) => {
182 logger.debug('Checking videoAbuseReport parameters', { parameters: req.body })
183
184 if (areValidationErrors(req, res)) return
185 if (!await isVideoExist(req.params.id, res)) return
186
187 return next()
188 }
189]
190
191const videoRateValidator = [ 176const videoRateValidator = [
192 param('id').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid id'), 177 param('id').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid id'),
193 body('rating').custom(isVideoRatingTypeValid).withMessage('Should have a valid rate type'), 178 body('rating').custom(isVideoRatingTypeValid).withMessage('Should have a valid rate type'),
@@ -299,8 +284,6 @@ export {
299 videosRemoveValidator, 284 videosRemoveValidator,
300 videosShareValidator, 285 videosShareValidator,
301 286
302 videoAbuseReportValidator,
303
304 videoRateValidator, 287 videoRateValidator,
305 288
306 getCommonVideoAttributes 289 getCommonVideoAttributes