diff options
Diffstat (limited to 'server/middlewares')
-rw-r--r-- | server/middlewares/validators/abuse.ts | 119 |
1 files changed, 3 insertions, 116 deletions
diff --git a/server/middlewares/validators/abuse.ts b/server/middlewares/validators/abuse.ts index f99d850a5..99403ca40 100644 --- a/server/middlewares/validators/abuse.ts +++ b/server/middlewares/validators/abuse.ts | |||
@@ -1,10 +1,10 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { body, param, query } from 'express-validator' | 2 | import { body, param, query } from 'express-validator' |
3 | import { | 3 | import { |
4 | areAbusePredefinedReasonsValid, | ||
4 | isAbuseFilterValid, | 5 | isAbuseFilterValid, |
5 | isAbuseMessageValid, | 6 | isAbuseMessageValid, |
6 | isAbuseModerationCommentValid, | 7 | isAbuseModerationCommentValid, |
7 | areAbusePredefinedReasonsValid, | ||
8 | isAbusePredefinedReasonValid, | 8 | isAbusePredefinedReasonValid, |
9 | isAbuseReasonValid, | 9 | isAbuseReasonValid, |
10 | isAbuseStateValid, | 10 | isAbuseStateValid, |
@@ -15,7 +15,7 @@ import { | |||
15 | import { exists, isIdOrUUIDValid, isIdValid, toIntOrNull } from '@server/helpers/custom-validators/misc' | 15 | import { exists, isIdOrUUIDValid, isIdValid, toIntOrNull } from '@server/helpers/custom-validators/misc' |
16 | import { doesCommentIdExist } from '@server/helpers/custom-validators/video-comments' | 16 | import { doesCommentIdExist } from '@server/helpers/custom-validators/video-comments' |
17 | import { logger } from '@server/helpers/logger' | 17 | import { logger } from '@server/helpers/logger' |
18 | import { doesAbuseExist, doesAccountIdExist, doesVideoAbuseExist, doesVideoExist } from '@server/helpers/middlewares' | 18 | import { doesAbuseExist, doesAccountIdExist, doesVideoExist } from '@server/helpers/middlewares' |
19 | import { AbuseMessageModel } from '@server/models/abuse/abuse-message' | 19 | import { AbuseMessageModel } from '@server/models/abuse/abuse-message' |
20 | import { AbuseCreate, UserRight } from '@shared/models' | 20 | import { AbuseCreate, UserRight } from '@shared/models' |
21 | import { areValidationErrors } from './utils' | 21 | import { areValidationErrors } from './utils' |
@@ -256,115 +256,6 @@ const deleteAbuseMessageValidator = [ | |||
256 | } | 256 | } |
257 | ] | 257 | ] |
258 | 258 | ||
259 | // FIXME: deprecated in 2.3. Remove these validators | ||
260 | |||
261 | const videoAbuseReportValidator = [ | ||
262 | param('videoId') | ||
263 | .custom(isIdOrUUIDValid) | ||
264 | .not() | ||
265 | .isEmpty() | ||
266 | .withMessage('Should have a valid videoId'), | ||
267 | body('reason') | ||
268 | .custom(isAbuseReasonValid) | ||
269 | .withMessage('Should have a valid reason'), | ||
270 | body('predefinedReasons') | ||
271 | .optional() | ||
272 | .custom(areAbusePredefinedReasonsValid) | ||
273 | .withMessage('Should have a valid list of predefined reasons'), | ||
274 | body('startAt') | ||
275 | .optional() | ||
276 | .customSanitizer(toIntOrNull) | ||
277 | .custom(isAbuseTimestampValid) | ||
278 | .withMessage('Should have valid starting time value'), | ||
279 | body('endAt') | ||
280 | .optional() | ||
281 | .customSanitizer(toIntOrNull) | ||
282 | .custom(isAbuseTimestampValid) | ||
283 | .withMessage('Should have valid ending time value'), | ||
284 | |||
285 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { | ||
286 | logger.debug('Checking videoAbuseReport parameters', { parameters: req.body }) | ||
287 | |||
288 | if (areValidationErrors(req, res)) return | ||
289 | if (!await doesVideoExist(req.params.videoId, res)) return | ||
290 | |||
291 | return next() | ||
292 | } | ||
293 | ] | ||
294 | |||
295 | const videoAbuseGetValidator = [ | ||
296 | param('videoId').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid videoId'), | ||
297 | param('id').custom(isIdValid).not().isEmpty().withMessage('Should have a valid id'), | ||
298 | |||
299 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { | ||
300 | logger.debug('Checking videoAbuseGetValidator parameters', { parameters: req.body }) | ||
301 | |||
302 | if (areValidationErrors(req, res)) return | ||
303 | if (!await doesVideoAbuseExist(req.params.id, req.params.videoId, res)) return | ||
304 | |||
305 | return next() | ||
306 | } | ||
307 | ] | ||
308 | |||
309 | const videoAbuseUpdateValidator = [ | ||
310 | param('videoId').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid videoId'), | ||
311 | param('id').custom(isIdValid).not().isEmpty().withMessage('Should have a valid id'), | ||
312 | body('state') | ||
313 | .optional() | ||
314 | .custom(isAbuseStateValid).withMessage('Should have a valid video abuse state'), | ||
315 | body('moderationComment') | ||
316 | .optional() | ||
317 | .custom(isAbuseModerationCommentValid).withMessage('Should have a valid video moderation comment'), | ||
318 | |||
319 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { | ||
320 | logger.debug('Checking videoAbuseUpdateValidator parameters', { parameters: req.body }) | ||
321 | |||
322 | if (areValidationErrors(req, res)) return | ||
323 | if (!await doesVideoAbuseExist(req.params.id, req.params.videoId, res)) return | ||
324 | |||
325 | return next() | ||
326 | } | ||
327 | ] | ||
328 | |||
329 | const videoAbuseListValidator = [ | ||
330 | query('id') | ||
331 | .optional() | ||
332 | .custom(isIdValid).withMessage('Should have a valid id'), | ||
333 | query('predefinedReason') | ||
334 | .optional() | ||
335 | .custom(isAbusePredefinedReasonValid) | ||
336 | .withMessage('Should have a valid predefinedReason'), | ||
337 | query('search') | ||
338 | .optional() | ||
339 | .custom(exists).withMessage('Should have a valid search'), | ||
340 | query('state') | ||
341 | .optional() | ||
342 | .custom(isAbuseStateValid).withMessage('Should have a valid video abuse state'), | ||
343 | query('videoIs') | ||
344 | .optional() | ||
345 | .custom(isAbuseVideoIsValid).withMessage('Should have a valid "video is" attribute'), | ||
346 | query('searchReporter') | ||
347 | .optional() | ||
348 | .custom(exists).withMessage('Should have a valid reporter search'), | ||
349 | query('searchReportee') | ||
350 | .optional() | ||
351 | .custom(exists).withMessage('Should have a valid reportee search'), | ||
352 | query('searchVideo') | ||
353 | .optional() | ||
354 | .custom(exists).withMessage('Should have a valid video search'), | ||
355 | query('searchVideoChannel') | ||
356 | .optional() | ||
357 | .custom(exists).withMessage('Should have a valid video channel search'), | ||
358 | |||
359 | (req: express.Request, res: express.Response, next: express.NextFunction) => { | ||
360 | logger.debug('Checking videoAbuseListValidator parameters', { parameters: req.body }) | ||
361 | |||
362 | if (areValidationErrors(req, res)) return | ||
363 | |||
364 | return next() | ||
365 | } | ||
366 | ] | ||
367 | |||
368 | // --------------------------------------------------------------------------- | 259 | // --------------------------------------------------------------------------- |
369 | 260 | ||
370 | export { | 261 | export { |
@@ -376,9 +267,5 @@ export { | |||
376 | abuseUpdateValidator, | 267 | abuseUpdateValidator, |
377 | deleteAbuseMessageValidator, | 268 | deleteAbuseMessageValidator, |
378 | abuseListForUserValidator, | 269 | abuseListForUserValidator, |
379 | getAbuseValidator, | 270 | getAbuseValidator |
380 | videoAbuseReportValidator, | ||
381 | videoAbuseGetValidator, | ||
382 | videoAbuseUpdateValidator, | ||
383 | videoAbuseListValidator | ||
384 | } | 271 | } |