From 27db78400c558e19bfac0da885fe0b7d0a3e6a0c Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 5 Aug 2021 13:54:35 +0200 Subject: Fix backend channel name validator consistency --- server/middlewares/validators/users.ts | 12 +++++++----- server/middlewares/validators/videos/video-channels.ts | 14 +++++++------- 2 files changed, 14 insertions(+), 12 deletions(-) (limited to 'server/middlewares') diff --git a/server/middlewares/validators/users.ts b/server/middlewares/validators/users.ts index 748b89f8f..bc8607523 100644 --- a/server/middlewares/validators/users.ts +++ b/server/middlewares/validators/users.ts @@ -6,7 +6,6 @@ import { MUserDefault } from '@server/types/models' import { HttpStatusCode } from '../../../shared/models/http/http-error-codes' import { UserRole } from '../../../shared/models/users' import { UserRegister } from '../../../shared/models/users/user-register.model' -import { isActorPreferredUsernameValid } from '../../helpers/custom-validators/activitypub/actor' import { toBooleanOrNull, toIntOrNull } from '../../helpers/custom-validators/misc' import { isThemeNameValid } from '../../helpers/custom-validators/plugins' import { @@ -28,7 +27,7 @@ import { isUserVideoQuotaValid, isUserVideosHistoryEnabledValid } from '../../helpers/custom-validators/users' -import { isVideoChannelNameValid } from '../../helpers/custom-validators/video-channels' +import { isVideoChannelDisplayNameValid, isVideoChannelUsernameValid } from '../../helpers/custom-validators/video-channels' import { logger } from '../../helpers/logger' import { isThemeRegistered } from '../../lib/plugins/theme-utils' import { Redis } from '../../lib/redis' @@ -56,9 +55,12 @@ const usersAddValidator = [ body('username').custom(isUserUsernameValid).withMessage('Should have a valid username (lowercase alphanumeric characters)'), body('password').custom(isUserPasswordValidOrEmpty).withMessage('Should have a valid password'), body('email').isEmail().withMessage('Should have a valid email'), - body('channelName').optional().custom(isActorPreferredUsernameValid).withMessage('Should have a valid channel name'), + + body('channelName').optional().custom(isVideoChannelUsernameValid).withMessage('Should have a valid channel name'), + body('videoQuota').custom(isUserVideoQuotaValid).withMessage('Should have a valid user quota'), body('videoQuotaDaily').custom(isUserVideoQuotaDailyValid).withMessage('Should have a valid daily user quota'), + body('role') .customSanitizer(toIntOrNull) .custom(isUserRoleValid).withMessage('Should have a valid role'), @@ -106,10 +108,10 @@ const usersRegisterValidator = [ body('channel.name') .optional() - .custom(isActorPreferredUsernameValid).withMessage('Should have a valid channel name'), + .custom(isVideoChannelUsernameValid).withMessage('Should have a valid channel name'), body('channel.displayName') .optional() - .custom(isVideoChannelNameValid).withMessage('Should have a valid display name'), + .custom(isVideoChannelDisplayNameValid).withMessage('Should have a valid display name'), async (req: express.Request, res: express.Response, next: express.NextFunction) => { logger.debug('Checking usersRegister parameters', { parameters: omit(req.body, 'password') }) diff --git a/server/middlewares/validators/videos/video-channels.ts b/server/middlewares/validators/videos/video-channels.ts index ea10fe425..3b5693d23 100644 --- a/server/middlewares/validators/videos/video-channels.ts +++ b/server/middlewares/validators/videos/video-channels.ts @@ -4,12 +4,12 @@ import { VIDEO_CHANNELS } from '@server/initializers/constants' import { MChannelAccountDefault, MUser } from '@server/types/models' import { UserRight } from '../../../../shared' import { HttpStatusCode } from '../../../../shared/models/http/http-error-codes' -import { isActorPreferredUsernameValid } from '../../../helpers/custom-validators/activitypub/actor' import { isBooleanValid, toBooleanOrNull } from '../../../helpers/custom-validators/misc' import { isVideoChannelDescriptionValid, - isVideoChannelNameValid, - isVideoChannelSupportValid + isVideoChannelDisplayNameValid, + isVideoChannelSupportValid, + isVideoChannelUsernameValid } from '../../../helpers/custom-validators/video-channels' import { logger } from '../../../helpers/logger' import { ActorModel } from '../../../models/actor/actor' @@ -17,8 +17,8 @@ import { VideoChannelModel } from '../../../models/video/video-channel' import { areValidationErrors, doesLocalVideoChannelNameExist, doesVideoChannelNameWithHostExist } from '../shared' const videoChannelsAddValidator = [ - body('name').custom(isActorPreferredUsernameValid).withMessage('Should have a valid channel name'), - body('displayName').custom(isVideoChannelNameValid).withMessage('Should have a valid display name'), + body('name').custom(isVideoChannelUsernameValid).withMessage('Should have a valid channel name'), + body('displayName').custom(isVideoChannelDisplayNameValid).withMessage('Should have a valid display name'), body('description').optional().custom(isVideoChannelDescriptionValid).withMessage('Should have a valid description'), body('support').optional().custom(isVideoChannelSupportValid).withMessage('Should have a valid support text'), @@ -50,7 +50,7 @@ const videoChannelsUpdateValidator = [ param('nameWithHost').exists().withMessage('Should have an video channel name with host'), body('displayName') .optional() - .custom(isVideoChannelNameValid).withMessage('Should have a valid display name'), + .custom(isVideoChannelDisplayNameValid).withMessage('Should have a valid display name'), body('description') .optional() .custom(isVideoChannelDescriptionValid).withMessage('Should have a valid description'), @@ -117,7 +117,7 @@ const videoChannelsNameWithHostValidator = [ ] const localVideoChannelValidator = [ - param('name').custom(isVideoChannelNameValid).withMessage('Should have a valid video channel name'), + param('name').custom(isVideoChannelDisplayNameValid).withMessage('Should have a valid video channel name'), async (req: express.Request, res: express.Response, next: express.NextFunction) => { logger.debug('Checking localVideoChannelValidator parameters', { parameters: req.params }) -- cgit v1.2.3