diff options
author | kimsible <kimsible@users.noreply.github.com> | 2020-07-29 20:10:03 +0200 |
---|---|---|
committer | Chocobozzz <chocobozzz@cpy.re> | 2020-08-11 08:46:35 +0200 |
commit | 766d13b4470de02d3d7bec94188260b89a356399 (patch) | |
tree | 173891229d01b41996468f68ce16eb1f837d6a20 /server/middlewares/validators/users.ts | |
parent | 69db1470432a6db8ef6929ef3175af75f7aaa963 (diff) | |
download | PeerTube-766d13b4470de02d3d7bec94188260b89a356399.tar.gz PeerTube-766d13b4470de02d3d7bec94188260b89a356399.tar.zst PeerTube-766d13b4470de02d3d7bec94188260b89a356399.zip |
Make channelName optionnal in tests only and validators
Fix tests channel displayName
Make channelName in createUser optionnal on server side to not break api
Fix auto channelName with createUser in tests
Diffstat (limited to 'server/middlewares/validators/users.ts')
-rw-r--r-- | server/middlewares/validators/users.ts | 25 |
1 files changed, 11 insertions, 14 deletions
diff --git a/server/middlewares/validators/users.ts b/server/middlewares/validators/users.ts index aff18be3d..76ecff884 100644 --- a/server/middlewares/validators/users.ts +++ b/server/middlewares/validators/users.ts | |||
@@ -56,7 +56,7 @@ const usersAddValidator = [ | |||
56 | body('username').custom(isUserUsernameValid).withMessage('Should have a valid username (lowercase alphanumeric characters)'), | 56 | body('username').custom(isUserUsernameValid).withMessage('Should have a valid username (lowercase alphanumeric characters)'), |
57 | body('password').custom(isUserPasswordValidOrEmpty).withMessage('Should have a valid password'), | 57 | body('password').custom(isUserPasswordValidOrEmpty).withMessage('Should have a valid password'), |
58 | body('email').isEmail().withMessage('Should have a valid email'), | 58 | body('email').isEmail().withMessage('Should have a valid email'), |
59 | body('channelName').custom(isActorPreferredUsernameValid).withMessage('Should have a valid channel name'), | 59 | body('channelName').optional().custom(isActorPreferredUsernameValid).withMessage('Should have a valid channel name'), |
60 | body('videoQuota').custom(isUserVideoQuotaValid).withMessage('Should have a valid user quota'), | 60 | body('videoQuota').custom(isUserVideoQuotaValid).withMessage('Should have a valid user quota'), |
61 | body('videoQuotaDaily').custom(isUserVideoQuotaDailyValid).withMessage('Should have a valid daily user quota'), | 61 | body('videoQuotaDaily').custom(isUserVideoQuotaDailyValid).withMessage('Should have a valid daily user quota'), |
62 | body('role') | 62 | body('role') |
@@ -76,20 +76,17 @@ const usersAddValidator = [ | |||
76 | .json({ error: 'You can only create users (and not administrators or moderators)' }) | 76 | .json({ error: 'You can only create users (and not administrators or moderators)' }) |
77 | } | 77 | } |
78 | 78 | ||
79 | if (!req.body.channelName) { | 79 | if (req.body.channelName) { |
80 | return res.status(400) | 80 | if (req.body.channelName === req.body.username) { |
81 | .json({ error: 'Channel name is required.' }) | 81 | return res.status(400) |
82 | } | 82 | .json({ error: 'Channel name cannot be the same as user username.' }) |
83 | 83 | } | |
84 | if (req.body.channelName === req.body.username) { | ||
85 | return res.status(400) | ||
86 | .json({ error: 'Channel name cannot be the same as user username.' }) | ||
87 | } | ||
88 | 84 | ||
89 | const existing = await ActorModel.loadLocalByName(req.body.channelName) | 85 | const existing = await ActorModel.loadLocalByName(req.body.channelName) |
90 | if (existing) { | 86 | if (existing) { |
91 | return res.status(409) | 87 | return res.status(409) |
92 | .json({ error: `Channel with name ${req.body.channelName} already exists.` }) | 88 | .json({ error: `Channel with name ${req.body.channelName} already exists.` }) |
89 | } | ||
93 | } | 90 | } |
94 | 91 | ||
95 | return next() | 92 | return next() |