X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fmiddlewares%2Fvalidators%2Fusers.ts;h=840b9fc744379e2a13039efafeb5d31b98824e30;hb=e1c5503114deef954731904695cd40dccfcef555;hp=5d52b5804a7f6b5b7c41abb3e6ebe27f4f5b8a9f;hpb=338eb9d33af690db716805fd2277bf68f473b58f;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/middlewares/validators/users.ts b/server/middlewares/validators/users.ts index 5d52b5804..840b9fc74 100644 --- a/server/middlewares/validators/users.ts +++ b/server/middlewares/validators/users.ts @@ -1,6 +1,6 @@ import * as Bluebird from 'bluebird' import * as express from 'express' -import { body, param } from 'express-validator' +import { body, param, query } from 'express-validator' import { omit } from 'lodash' import { isIdOrUUIDValid, toBooleanOrNull, toIntOrNull } from '../../helpers/custom-validators/misc' import { @@ -14,6 +14,7 @@ import { isUserDisplayNameValid, isUserNSFWPolicyValid, isUserPasswordValid, + isUserPasswordValidOrEmpty, isUserRoleValid, isUserUsernameValid, isUserVideoLanguages, @@ -39,7 +40,7 @@ import { Hooks } from '@server/lib/plugins/hooks' const usersAddValidator = [ body('username').custom(isUserUsernameValid).withMessage('Should have a valid username (lowercase alphanumeric characters)'), - body('password').custom(isUserPasswordValid).withMessage('Should have a valid password'), + body('password').custom(isUserPasswordValidOrEmpty).withMessage('Should have a valid password'), body('email').isEmail().withMessage('Should have a valid email'), body('videoQuota').custom(isUserVideoQuotaValid).withMessage('Should have a valid user quota'), body('videoQuotaDaily').custom(isUserVideoQuotaDailyValid).withMessage('Should have a valid daily user quota'), @@ -255,12 +256,13 @@ const usersUpdateMeValidator = [ const usersGetValidator = [ param('id').isInt().not().isEmpty().withMessage('Should have a valid id'), + query('withStats').optional().isBoolean().withMessage('Should have a valid stats flag'), async (req: express.Request, res: express.Response, next: express.NextFunction) => { logger.debug('Checking usersGet parameters', { parameters: req.params }) if (areValidationErrors(req, res)) return - if (!await checkUserIdExist(req.params.id, res)) return + if (!await checkUserIdExist(req.params.id, res, req.query.withStats)) return return next() } @@ -459,9 +461,9 @@ export { // --------------------------------------------------------------------------- -function checkUserIdExist (idArg: number | string, res: express.Response) { +function checkUserIdExist (idArg: number | string, res: express.Response, withStats = false) { const id = parseInt(idArg + '', 10) - return checkUserExist(() => UserModel.loadById(id), res) + return checkUserExist(() => UserModel.loadById(id, withStats), res) } function checkUserEmailExist (email: string, res: express.Response, abortResponse = true) {