]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/commitdiff
Make channelName optionnal in tests only and validators
authorkimsible <kimsible@users.noreply.github.com>
Wed, 29 Jul 2020 18:10:03 +0000 (20:10 +0200)
committerChocobozzz <chocobozzz@cpy.re>
Tue, 11 Aug 2020 06:46:35 +0000 (08:46 +0200)
Fix tests channel displayName

Make channelName in createUser optionnal on server side to not break api

Fix auto channelName with createUser in tests

server/middlewares/validators/users.ts

index aff18be3dc985a39f4566e7ebbcd754970cbfbc8..76ecff8845bcfbf262a9a794508e8f96b17575de 100644 (file)
@@ -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()