diff options
author | Chocobozzz <me@florianbigard.com> | 2020-11-16 13:49:09 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2020-11-16 13:57:14 +0100 |
commit | 19149d45b8f68569535f7188ef25e09e3d62c8b4 (patch) | |
tree | 92da0e0db2b0e277b2110a630f502433c86c9119 /server/middlewares/validators | |
parent | 8872828d59a5152e27734711ae30ebe86e84f570 (diff) | |
parent | f1273314593a4a7dc7ec9594ce0c6c3ae8f62b34 (diff) | |
download | PeerTube-19149d45b8f68569535f7188ef25e09e3d62c8b4.tar.gz PeerTube-19149d45b8f68569535f7188ef25e09e3d62c8b4.tar.zst PeerTube-19149d45b8f68569535f7188ef25e09e3d62c8b4.zip |
Merge branch 'feature/admin-comments' into develop
Diffstat (limited to 'server/middlewares/validators')
-rw-r--r-- | server/middlewares/validators/sort.ts | 3 | ||||
-rw-r--r-- | server/middlewares/validators/users.ts | 1 | ||||
-rw-r--r-- | server/middlewares/validators/videos/video-comments.ts | 33 |
3 files changed, 35 insertions, 2 deletions
diff --git a/server/middlewares/validators/sort.ts b/server/middlewares/validators/sort.ts index 29aba0436..e93ceb200 100644 --- a/server/middlewares/validators/sort.ts +++ b/server/middlewares/validators/sort.ts | |||
@@ -10,6 +10,7 @@ const SORTABLE_VIDEOS_COLUMNS = createSortableColumns(SORTABLE_COLUMNS.VIDEOS) | |||
10 | const SORTABLE_VIDEOS_SEARCH_COLUMNS = createSortableColumns(SORTABLE_COLUMNS.VIDEOS_SEARCH) | 10 | const SORTABLE_VIDEOS_SEARCH_COLUMNS = createSortableColumns(SORTABLE_COLUMNS.VIDEOS_SEARCH) |
11 | const SORTABLE_VIDEO_CHANNELS_SEARCH_COLUMNS = createSortableColumns(SORTABLE_COLUMNS.VIDEO_CHANNELS_SEARCH) | 11 | const SORTABLE_VIDEO_CHANNELS_SEARCH_COLUMNS = createSortableColumns(SORTABLE_COLUMNS.VIDEO_CHANNELS_SEARCH) |
12 | const SORTABLE_VIDEO_IMPORTS_COLUMNS = createSortableColumns(SORTABLE_COLUMNS.VIDEO_IMPORTS) | 12 | const SORTABLE_VIDEO_IMPORTS_COLUMNS = createSortableColumns(SORTABLE_COLUMNS.VIDEO_IMPORTS) |
13 | const SORTABLE_VIDEO_COMMENTS_COLUMNS = createSortableColumns(SORTABLE_COLUMNS.VIDEO_COMMENT_THREADS) | ||
13 | const SORTABLE_VIDEO_COMMENT_THREADS_COLUMNS = createSortableColumns(SORTABLE_COLUMNS.VIDEO_COMMENT_THREADS) | 14 | const SORTABLE_VIDEO_COMMENT_THREADS_COLUMNS = createSortableColumns(SORTABLE_COLUMNS.VIDEO_COMMENT_THREADS) |
14 | const SORTABLE_VIDEO_RATES_COLUMNS = createSortableColumns(SORTABLE_COLUMNS.VIDEO_RATES) | 15 | const SORTABLE_VIDEO_RATES_COLUMNS = createSortableColumns(SORTABLE_COLUMNS.VIDEO_RATES) |
15 | const SORTABLE_BLACKLISTS_COLUMNS = createSortableColumns(SORTABLE_COLUMNS.BLACKLISTS) | 16 | const SORTABLE_BLACKLISTS_COLUMNS = createSortableColumns(SORTABLE_COLUMNS.BLACKLISTS) |
@@ -33,6 +34,7 @@ const videosSortValidator = checkSort(SORTABLE_VIDEOS_COLUMNS) | |||
33 | const videoImportsSortValidator = checkSort(SORTABLE_VIDEO_IMPORTS_COLUMNS) | 34 | const videoImportsSortValidator = checkSort(SORTABLE_VIDEO_IMPORTS_COLUMNS) |
34 | const videosSearchSortValidator = checkSort(SORTABLE_VIDEOS_SEARCH_COLUMNS) | 35 | const videosSearchSortValidator = checkSort(SORTABLE_VIDEOS_SEARCH_COLUMNS) |
35 | const videoChannelsSearchSortValidator = checkSort(SORTABLE_VIDEO_CHANNELS_SEARCH_COLUMNS) | 36 | const videoChannelsSearchSortValidator = checkSort(SORTABLE_VIDEO_CHANNELS_SEARCH_COLUMNS) |
37 | const videoCommentsValidator = checkSort(SORTABLE_VIDEO_COMMENTS_COLUMNS) | ||
36 | const videoCommentThreadsSortValidator = checkSort(SORTABLE_VIDEO_COMMENT_THREADS_COLUMNS) | 38 | const videoCommentThreadsSortValidator = checkSort(SORTABLE_VIDEO_COMMENT_THREADS_COLUMNS) |
37 | const videoRatesSortValidator = checkSort(SORTABLE_VIDEO_RATES_COLUMNS) | 39 | const videoRatesSortValidator = checkSort(SORTABLE_VIDEO_RATES_COLUMNS) |
38 | const blacklistSortValidator = checkSort(SORTABLE_BLACKLISTS_COLUMNS) | 40 | const blacklistSortValidator = checkSort(SORTABLE_BLACKLISTS_COLUMNS) |
@@ -55,6 +57,7 @@ export { | |||
55 | abusesSortValidator, | 57 | abusesSortValidator, |
56 | videoChannelsSortValidator, | 58 | videoChannelsSortValidator, |
57 | videoImportsSortValidator, | 59 | videoImportsSortValidator, |
60 | videoCommentsValidator, | ||
58 | videosSearchSortValidator, | 61 | videosSearchSortValidator, |
59 | videosSortValidator, | 62 | videosSortValidator, |
60 | blacklistSortValidator, | 63 | blacklistSortValidator, |
diff --git a/server/middlewares/validators/users.ts b/server/middlewares/validators/users.ts index 452c7fb93..c91c378b3 100644 --- a/server/middlewares/validators/users.ts +++ b/server/middlewares/validators/users.ts | |||
@@ -41,6 +41,7 @@ import { Hooks } from '@server/lib/plugins/hooks' | |||
41 | const usersListValidator = [ | 41 | const usersListValidator = [ |
42 | query('blocked') | 42 | query('blocked') |
43 | .optional() | 43 | .optional() |
44 | .customSanitizer(toBooleanOrNull) | ||
44 | .isBoolean().withMessage('Should be a valid boolean banned state'), | 45 | .isBoolean().withMessage('Should be a valid boolean banned state'), |
45 | 46 | ||
46 | (req: express.Request, res: express.Response, next: express.NextFunction) => { | 47 | (req: express.Request, res: express.Response, next: express.NextFunction) => { |
diff --git a/server/middlewares/validators/videos/video-comments.ts b/server/middlewares/validators/videos/video-comments.ts index 77f5c6ff3..a3c9febc4 100644 --- a/server/middlewares/validators/videos/video-comments.ts +++ b/server/middlewares/validators/videos/video-comments.ts | |||
@@ -1,8 +1,8 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { body, param } from 'express-validator' | 2 | import { body, param, query } from 'express-validator' |
3 | import { MUserAccountUrl } from '@server/types/models' | 3 | import { MUserAccountUrl } from '@server/types/models' |
4 | import { UserRight } from '../../../../shared' | 4 | import { UserRight } from '../../../../shared' |
5 | import { isIdOrUUIDValid, isIdValid } from '../../../helpers/custom-validators/misc' | 5 | import { exists, isBooleanValid, isIdOrUUIDValid, isIdValid, toBooleanOrNull } from '../../../helpers/custom-validators/misc' |
6 | import { | 6 | import { |
7 | doesVideoCommentExist, | 7 | doesVideoCommentExist, |
8 | doesVideoCommentThreadExist, | 8 | doesVideoCommentThreadExist, |
@@ -15,6 +15,34 @@ import { Hooks } from '../../../lib/plugins/hooks' | |||
15 | import { MCommentOwnerVideoReply, MVideo, MVideoFullLight } from '../../../types/models/video' | 15 | import { MCommentOwnerVideoReply, MVideo, MVideoFullLight } from '../../../types/models/video' |
16 | import { areValidationErrors } from '../utils' | 16 | import { areValidationErrors } from '../utils' |
17 | 17 | ||
18 | const listVideoCommentsValidator = [ | ||
19 | query('isLocal') | ||
20 | .optional() | ||
21 | .customSanitizer(toBooleanOrNull) | ||
22 | .custom(isBooleanValid) | ||
23 | .withMessage('Should have a valid is local boolean'), | ||
24 | |||
25 | query('search') | ||
26 | .optional() | ||
27 | .custom(exists).withMessage('Should have a valid search'), | ||
28 | |||
29 | query('searchAccount') | ||
30 | .optional() | ||
31 | .custom(exists).withMessage('Should have a valid account search'), | ||
32 | |||
33 | query('searchVideo') | ||
34 | .optional() | ||
35 | .custom(exists).withMessage('Should have a valid video search'), | ||
36 | |||
37 | (req: express.Request, res: express.Response, next: express.NextFunction) => { | ||
38 | logger.debug('Checking listVideoCommentsValidator parameters.', { parameters: req.query }) | ||
39 | |||
40 | if (areValidationErrors(req, res)) return | ||
41 | |||
42 | return next() | ||
43 | } | ||
44 | ] | ||
45 | |||
18 | const listVideoCommentThreadsValidator = [ | 46 | const listVideoCommentThreadsValidator = [ |
19 | param('videoId').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid videoId'), | 47 | param('videoId').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid videoId'), |
20 | 48 | ||
@@ -116,6 +144,7 @@ export { | |||
116 | listVideoCommentThreadsValidator, | 144 | listVideoCommentThreadsValidator, |
117 | listVideoThreadCommentsValidator, | 145 | listVideoThreadCommentsValidator, |
118 | addVideoCommentThreadValidator, | 146 | addVideoCommentThreadValidator, |
147 | listVideoCommentsValidator, | ||
119 | addVideoCommentReplyValidator, | 148 | addVideoCommentReplyValidator, |
120 | videoCommentGetValidator, | 149 | videoCommentGetValidator, |
121 | removeVideoCommentValidator | 150 | removeVideoCommentValidator |