diff options
author | Chocobozzz <me@florianbigard.com> | 2019-08-22 14:46:47 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2019-08-22 14:46:47 +0200 |
commit | d5c8932a601c1854db0a2e399ccaf26e17385f1a (patch) | |
tree | 8c38f9d7772c6a2d22dbeb84a7c4de6aaf345aeb /server/middlewares/validators/users.ts | |
parent | 2a8ae7595c1b7853c47955b4b9ecb4a7f7a68fc0 (diff) | |
parent | 820546916cad3ae4cc51eab408aef7bbaff3632f (diff) | |
download | PeerTube-d5c8932a601c1854db0a2e399ccaf26e17385f1a.tar.gz PeerTube-d5c8932a601c1854db0a2e399ccaf26e17385f1a.tar.zst PeerTube-d5c8932a601c1854db0a2e399ccaf26e17385f1a.zip |
Merge branch 'release/1.4.0' into develop
Diffstat (limited to 'server/middlewares/validators/users.ts')
-rw-r--r-- | server/middlewares/validators/users.ts | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/server/middlewares/validators/users.ts b/server/middlewares/validators/users.ts index 40dd0f0e9..d51bc27e6 100644 --- a/server/middlewares/validators/users.ts +++ b/server/middlewares/validators/users.ts | |||
@@ -39,7 +39,9 @@ const usersAddValidator = [ | |||
39 | body('email').isEmail().withMessage('Should have a valid email'), | 39 | body('email').isEmail().withMessage('Should have a valid email'), |
40 | body('videoQuota').custom(isUserVideoQuotaValid).withMessage('Should have a valid user quota'), | 40 | body('videoQuota').custom(isUserVideoQuotaValid).withMessage('Should have a valid user quota'), |
41 | body('videoQuotaDaily').custom(isUserVideoQuotaDailyValid).withMessage('Should have a valid daily user quota'), | 41 | body('videoQuotaDaily').custom(isUserVideoQuotaDailyValid).withMessage('Should have a valid daily user quota'), |
42 | body('role').custom(isUserRoleValid).withMessage('Should have a valid role'), | 42 | body('role') |
43 | .customSanitizer(toIntOrNull) | ||
44 | .custom(isUserRoleValid).withMessage('Should have a valid role'), | ||
43 | body('adminFlags').optional().custom(isUserAdminFlagsValid).withMessage('Should have a valid admin flags'), | 45 | body('adminFlags').optional().custom(isUserAdminFlagsValid).withMessage('Should have a valid admin flags'), |
44 | 46 | ||
45 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { | 47 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { |
@@ -51,7 +53,7 @@ const usersAddValidator = [ | |||
51 | const authUser = res.locals.oauth.token.User | 53 | const authUser = res.locals.oauth.token.User |
52 | if (authUser.role !== UserRole.ADMINISTRATOR && req.body.role !== UserRole.USER) { | 54 | if (authUser.role !== UserRole.ADMINISTRATOR && req.body.role !== UserRole.USER) { |
53 | return res.status(403) | 55 | return res.status(403) |
54 | .json({ error: 'You can only create users (and not administrators or moderators' }) | 56 | .json({ error: 'You can only create users (and not administrators or moderators)' }) |
55 | } | 57 | } |
56 | 58 | ||
57 | return next() | 59 | return next() |
@@ -161,7 +163,10 @@ const usersUpdateValidator = [ | |||
161 | body('emailVerified').optional().isBoolean().withMessage('Should have a valid email verified attribute'), | 163 | body('emailVerified').optional().isBoolean().withMessage('Should have a valid email verified attribute'), |
162 | body('videoQuota').optional().custom(isUserVideoQuotaValid).withMessage('Should have a valid user quota'), | 164 | body('videoQuota').optional().custom(isUserVideoQuotaValid).withMessage('Should have a valid user quota'), |
163 | body('videoQuotaDaily').optional().custom(isUserVideoQuotaDailyValid).withMessage('Should have a valid daily user quota'), | 165 | body('videoQuotaDaily').optional().custom(isUserVideoQuotaDailyValid).withMessage('Should have a valid daily user quota'), |
164 | body('role').optional().custom(isUserRoleValid).withMessage('Should have a valid role'), | 166 | body('role') |
167 | .optional() | ||
168 | .customSanitizer(toIntOrNull) | ||
169 | .custom(isUserRoleValid).withMessage('Should have a valid role'), | ||
165 | body('adminFlags').optional().custom(isUserAdminFlagsValid).withMessage('Should have a valid admin flags'), | 170 | body('adminFlags').optional().custom(isUserAdminFlagsValid).withMessage('Should have a valid admin flags'), |
166 | 171 | ||
167 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { | 172 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { |