aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/middlewares/validators
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2020-11-10 14:41:20 +0100
committerChocobozzz <me@florianbigard.com>2020-11-10 14:50:16 +0100
commit7a4ea932461f228ae44a173ddcd48ffb088aa023 (patch)
tree429b6fa7dae496d339a9f22e4076e39ffda97461 /server/middlewares/validators
parent403c69c5a34e6db621f30c7b2bfb2b80dc8e74c1 (diff)
downloadPeerTube-7a4ea932461f228ae44a173ddcd48ffb088aa023.tar.gz
PeerTube-7a4ea932461f228ae44a173ddcd48ffb088aa023.tar.zst
PeerTube-7a4ea932461f228ae44a173ddcd48ffb088aa023.zip
Remove deprecated abuse api
Diffstat (limited to 'server/middlewares/validators')
-rw-r--r--server/middlewares/validators/abuse.ts119
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 @@
1import * as express from 'express' 1import * as express from 'express'
2import { body, param, query } from 'express-validator' 2import { body, param, query } from 'express-validator'
3import { 3import {
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 {
15import { exists, isIdOrUUIDValid, isIdValid, toIntOrNull } from '@server/helpers/custom-validators/misc' 15import { exists, isIdOrUUIDValid, isIdValid, toIntOrNull } from '@server/helpers/custom-validators/misc'
16import { doesCommentIdExist } from '@server/helpers/custom-validators/video-comments' 16import { doesCommentIdExist } from '@server/helpers/custom-validators/video-comments'
17import { logger } from '@server/helpers/logger' 17import { logger } from '@server/helpers/logger'
18import { doesAbuseExist, doesAccountIdExist, doesVideoAbuseExist, doesVideoExist } from '@server/helpers/middlewares' 18import { doesAbuseExist, doesAccountIdExist, doesVideoExist } from '@server/helpers/middlewares'
19import { AbuseMessageModel } from '@server/models/abuse/abuse-message' 19import { AbuseMessageModel } from '@server/models/abuse/abuse-message'
20import { AbuseCreate, UserRight } from '@shared/models' 20import { AbuseCreate, UserRight } from '@shared/models'
21import { areValidationErrors } from './utils' 21import { 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
261const 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
295const 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
309const 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
329const 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
370export { 261export {
@@ -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}