aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/middlewares
diff options
context:
space:
mode:
Diffstat (limited to 'server/middlewares')
-rw-r--r--server/middlewares/validators/users.ts27
1 files changed, 25 insertions, 2 deletions
diff --git a/server/middlewares/validators/users.ts b/server/middlewares/validators/users.ts
index c6eeeaf18..8f1a7801f 100644
--- a/server/middlewares/validators/users.ts
+++ b/server/middlewares/validators/users.ts
@@ -4,7 +4,7 @@ import { omit } from 'lodash'
4import { Hooks } from '@server/lib/plugins/hooks' 4import { Hooks } from '@server/lib/plugins/hooks'
5import { MUserDefault } from '@server/types/models' 5import { MUserDefault } from '@server/types/models'
6import { HttpStatusCode, UserRegister, UserRole } from '@shared/models' 6import { HttpStatusCode, UserRegister, UserRole } from '@shared/models'
7import { toBooleanOrNull, toIntOrNull } from '../../helpers/custom-validators/misc' 7import { isBooleanValid, isIdValid, toBooleanOrNull, toIntOrNull } from '../../helpers/custom-validators/misc'
8import { isThemeNameValid } from '../../helpers/custom-validators/plugins' 8import { isThemeNameValid } from '../../helpers/custom-validators/plugins'
9import { 9import {
10 isUserAdminFlagsValid, 10 isUserAdminFlagsValid,
@@ -31,7 +31,7 @@ import { Redis } from '../../lib/redis'
31import { isSignupAllowed, isSignupAllowedForCurrentIP } from '../../lib/signup' 31import { isSignupAllowed, isSignupAllowedForCurrentIP } from '../../lib/signup'
32import { ActorModel } from '../../models/actor/actor' 32import { ActorModel } from '../../models/actor/actor'
33import { UserModel } from '../../models/user/user' 33import { UserModel } from '../../models/user/user'
34import { areValidationErrors, doesVideoExist, isValidVideoIdParam } from './shared' 34import { areValidationErrors, doesVideoChannelIdExist, doesVideoExist, isValidVideoIdParam } from './shared'
35 35
36const usersListValidator = [ 36const usersListValidator = [
37 query('blocked') 37 query('blocked')
@@ -318,6 +318,28 @@ const usersVideoRatingValidator = [
318 } 318 }
319] 319]
320 320
321const usersVideosValidator = [
322 query('isLive')
323 .optional()
324 .customSanitizer(toBooleanOrNull)
325 .custom(isBooleanValid).withMessage('Should have a valid live boolean'),
326
327 query('channelId')
328 .optional()
329 .customSanitizer(toIntOrNull)
330 .custom(isIdValid).withMessage('Should have a valid channel id'),
331
332 async (req: express.Request, res: express.Response, next: express.NextFunction) => {
333 logger.debug('Checking usersVideosValidator parameters', { parameters: req.params })
334
335 if (areValidationErrors(req, res)) return
336
337 if (req.query.channelId && !await doesVideoChannelIdExist(req.query.channelId, res)) return
338
339 return next()
340 }
341]
342
321const ensureUserRegistrationAllowed = [ 343const ensureUserRegistrationAllowed = [
322 async (req: express.Request, res: express.Response, next: express.NextFunction) => { 344 async (req: express.Request, res: express.Response, next: express.NextFunction) => {
323 const allowedParams = { 345 const allowedParams = {
@@ -513,6 +535,7 @@ export {
513 ensureUserRegistrationAllowed, 535 ensureUserRegistrationAllowed,
514 ensureUserRegistrationAllowedForIP, 536 ensureUserRegistrationAllowedForIP,
515 usersGetValidator, 537 usersGetValidator,
538 usersVideosValidator,
516 usersAskResetPasswordValidator, 539 usersAskResetPasswordValidator,
517 usersResetPasswordValidator, 540 usersResetPasswordValidator,
518 usersAskSendVerifyEmailValidator, 541 usersAskSendVerifyEmailValidator,