diff options
author | Rigel Kent <sendmemail@rigelk.eu> | 2020-03-27 15:19:03 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-03-27 15:19:03 +0100 |
commit | 76314386aeafdd6849b7b70c517779d6b2013473 (patch) | |
tree | f0ba33e0f6e7b2eb99222a9eb5b85846cf309ab1 /server/middlewares | |
parent | 56d72521ec139dfc0aef083b8541a5b16d974ac1 (diff) | |
download | PeerTube-76314386aeafdd6849b7b70c517779d6b2013473.tar.gz PeerTube-76314386aeafdd6849b7b70c517779d6b2013473.tar.zst PeerTube-76314386aeafdd6849b7b70c517779d6b2013473.zip |
Add overview of a user's actions in user-edit (#2558)
Diffstat (limited to 'server/middlewares')
-rw-r--r-- | server/middlewares/validators/users.ts | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/server/middlewares/validators/users.ts b/server/middlewares/validators/users.ts index adc67a046..840b9fc74 100644 --- a/server/middlewares/validators/users.ts +++ b/server/middlewares/validators/users.ts | |||
@@ -1,6 +1,6 @@ | |||
1 | import * as Bluebird from 'bluebird' | 1 | import * as Bluebird from 'bluebird' |
2 | import * as express from 'express' | 2 | import * as express from 'express' |
3 | import { body, param } from 'express-validator' | 3 | import { body, param, query } from 'express-validator' |
4 | import { omit } from 'lodash' | 4 | import { omit } from 'lodash' |
5 | import { isIdOrUUIDValid, toBooleanOrNull, toIntOrNull } from '../../helpers/custom-validators/misc' | 5 | import { isIdOrUUIDValid, toBooleanOrNull, toIntOrNull } from '../../helpers/custom-validators/misc' |
6 | import { | 6 | import { |
@@ -256,12 +256,13 @@ const usersUpdateMeValidator = [ | |||
256 | 256 | ||
257 | const usersGetValidator = [ | 257 | const usersGetValidator = [ |
258 | param('id').isInt().not().isEmpty().withMessage('Should have a valid id'), | 258 | param('id').isInt().not().isEmpty().withMessage('Should have a valid id'), |
259 | query('withStats').optional().isBoolean().withMessage('Should have a valid stats flag'), | ||
259 | 260 | ||
260 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { | 261 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { |
261 | logger.debug('Checking usersGet parameters', { parameters: req.params }) | 262 | logger.debug('Checking usersGet parameters', { parameters: req.params }) |
262 | 263 | ||
263 | if (areValidationErrors(req, res)) return | 264 | if (areValidationErrors(req, res)) return |
264 | if (!await checkUserIdExist(req.params.id, res)) return | 265 | if (!await checkUserIdExist(req.params.id, res, req.query.withStats)) return |
265 | 266 | ||
266 | return next() | 267 | return next() |
267 | } | 268 | } |
@@ -460,9 +461,9 @@ export { | |||
460 | 461 | ||
461 | // --------------------------------------------------------------------------- | 462 | // --------------------------------------------------------------------------- |
462 | 463 | ||
463 | function checkUserIdExist (idArg: number | string, res: express.Response) { | 464 | function checkUserIdExist (idArg: number | string, res: express.Response, withStats = false) { |
464 | const id = parseInt(idArg + '', 10) | 465 | const id = parseInt(idArg + '', 10) |
465 | return checkUserExist(() => UserModel.loadById(id), res) | 466 | return checkUserExist(() => UserModel.loadById(id, withStats), res) |
466 | } | 467 | } |
467 | 468 | ||
468 | function checkUserEmailExist (email: string, res: express.Response, abortResponse = true) { | 469 | function checkUserEmailExist (email: string, res: express.Response, abortResponse = true) { |