diff options
Diffstat (limited to 'server/middlewares')
-rw-r--r-- | server/middlewares/validators/users.ts | 27 |
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' | |||
4 | import { Hooks } from '@server/lib/plugins/hooks' | 4 | import { Hooks } from '@server/lib/plugins/hooks' |
5 | import { MUserDefault } from '@server/types/models' | 5 | import { MUserDefault } from '@server/types/models' |
6 | import { HttpStatusCode, UserRegister, UserRole } from '@shared/models' | 6 | import { HttpStatusCode, UserRegister, UserRole } from '@shared/models' |
7 | import { toBooleanOrNull, toIntOrNull } from '../../helpers/custom-validators/misc' | 7 | import { isBooleanValid, isIdValid, toBooleanOrNull, toIntOrNull } from '../../helpers/custom-validators/misc' |
8 | import { isThemeNameValid } from '../../helpers/custom-validators/plugins' | 8 | import { isThemeNameValid } from '../../helpers/custom-validators/plugins' |
9 | import { | 9 | import { |
10 | isUserAdminFlagsValid, | 10 | isUserAdminFlagsValid, |
@@ -31,7 +31,7 @@ import { Redis } from '../../lib/redis' | |||
31 | import { isSignupAllowed, isSignupAllowedForCurrentIP } from '../../lib/signup' | 31 | import { isSignupAllowed, isSignupAllowedForCurrentIP } from '../../lib/signup' |
32 | import { ActorModel } from '../../models/actor/actor' | 32 | import { ActorModel } from '../../models/actor/actor' |
33 | import { UserModel } from '../../models/user/user' | 33 | import { UserModel } from '../../models/user/user' |
34 | import { areValidationErrors, doesVideoExist, isValidVideoIdParam } from './shared' | 34 | import { areValidationErrors, doesVideoChannelIdExist, doesVideoExist, isValidVideoIdParam } from './shared' |
35 | 35 | ||
36 | const usersListValidator = [ | 36 | const usersListValidator = [ |
37 | query('blocked') | 37 | query('blocked') |
@@ -318,6 +318,28 @@ const usersVideoRatingValidator = [ | |||
318 | } | 318 | } |
319 | ] | 319 | ] |
320 | 320 | ||
321 | const 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 | |||
321 | const ensureUserRegistrationAllowed = [ | 343 | const 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, |