X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fmiddlewares%2Fvalidators%2Fusers.ts;h=452c7fb930d2af67ccb8bd549e8836794957277a;hb=fb7194043d0486ce0a6a40b2ffbdf32878c33a6f;hp=aff18be3dc985a39f4566e7ebbcd754970cbfbc8;hpb=4e68fc8605bff02f4c79deafc24cb39779802d0d;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/middlewares/validators/users.ts b/server/middlewares/validators/users.ts index aff18be3d..452c7fb93 100644 --- a/server/middlewares/validators/users.ts +++ b/server/middlewares/validators/users.ts @@ -56,7 +56,7 @@ 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').custom(isActorPreferredUsernameValid).withMessage('Should have a valid channel name'), + body('channelName').optional().custom(isActorPreferredUsernameValid).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') @@ -76,20 +76,17 @@ const usersAddValidator = [ .json({ error: 'You can only create users (and not administrators or moderators)' }) } - if (!req.body.channelName) { - return res.status(400) - .json({ error: 'Channel name is required.' }) - } - - if (req.body.channelName === req.body.username) { - return res.status(400) - .json({ error: 'Channel name cannot be the same as user username.' }) - } + if (req.body.channelName) { + if (req.body.channelName === req.body.username) { + return res.status(400) + .json({ error: 'Channel name cannot be the same as user username.' }) + } - const existing = await ActorModel.loadLocalByName(req.body.channelName) - if (existing) { - return res.status(409) - .json({ error: `Channel with name ${req.body.channelName} already exists.` }) + const existing = await ActorModel.loadLocalByName(req.body.channelName) + if (existing) { + return res.status(409) + .json({ error: `Channel with name ${req.body.channelName} already exists.` }) + } } return next() @@ -500,7 +497,7 @@ export { function checkUserIdExist (idArg: number | string, res: express.Response, withStats = false) { const id = parseInt(idArg + '', 10) - return checkUserExist(() => UserModel.loadById(id, withStats), res) + return checkUserExist(() => UserModel.loadByIdWithChannels(id, withStats), res) } function checkUserEmailExist (email: string, res: express.Response, abortResponse = true) {