Add validator channelName for create-user api

pull/3068/head
kimsible 2020-07-29 16:23:42 +02:00 committed by Chocobozzz
parent 3d215dc5f9
commit 4e68fc8605
1 changed files with 17 additions and 0 deletions

View File

@ -56,6 +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('videoQuota').custom(isUserVideoQuotaValid).withMessage('Should have a valid user quota'),
body('videoQuotaDaily').custom(isUserVideoQuotaDailyValid).withMessage('Should have a valid daily user quota'),
body('role')
@ -75,6 +76,22 @@ 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.' })
}
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()
}
]