aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/middlewares/validators/bulk.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2020-05-14 16:56:15 +0200
committerChocobozzz <chocobozzz@cpy.re>2020-05-29 09:21:26 +0200
commit444c0a0e017824fb4ce526281a22c4abe0a13c50 (patch)
tree6a3c1ea8c4995361c582176257d1e1315287411d /server/middlewares/validators/bulk.ts
parent99139e7753e20ab0fba8eae5638d3dd3e792fe43 (diff)
downloadPeerTube-444c0a0e017824fb4ce526281a22c4abe0a13c50.tar.gz
PeerTube-444c0a0e017824fb4ce526281a22c4abe0a13c50.tar.zst
PeerTube-444c0a0e017824fb4ce526281a22c4abe0a13c50.zip
Add ability to bulk delete comments
Diffstat (limited to 'server/middlewares/validators/bulk.ts')
-rw-r--r--server/middlewares/validators/bulk.ts41
1 files changed, 41 insertions, 0 deletions
diff --git a/server/middlewares/validators/bulk.ts b/server/middlewares/validators/bulk.ts
new file mode 100644
index 000000000..f9b0f565a
--- /dev/null
+++ b/server/middlewares/validators/bulk.ts
@@ -0,0 +1,41 @@
1import * as express from 'express'
2import { body } from 'express-validator'
3import { isBulkRemoveCommentsOfScopeValid } from '@server/helpers/custom-validators/bulk'
4import { doesAccountNameWithHostExist } from '@server/helpers/middlewares'
5import { UserRight } from '@shared/models'
6import { BulkRemoveCommentsOfBody } from '@shared/models/bulk/bulk-remove-comments-of-body.model'
7import { logger } from '../../helpers/logger'
8import { areValidationErrors } from './utils'
9
10const bulkRemoveCommentsOfValidator = [
11 body('accountName').exists().withMessage('Should have an account name with host'),
12 body('scope')
13 .custom(isBulkRemoveCommentsOfScopeValid).withMessage('Should have a valid scope'),
14
15 async (req: express.Request, res: express.Response, next: express.NextFunction) => {
16 logger.debug('Checking bulkRemoveCommentsOfValidator parameters', { parameters: req.body })
17
18 if (areValidationErrors(req, res)) return
19 if (!await doesAccountNameWithHostExist(req.body.accountName, res)) return
20
21 const user = res.locals.oauth.token.User
22 const body = req.body as BulkRemoveCommentsOfBody
23
24 if (body.scope === 'instance' && user.hasRight(UserRight.REMOVE_ANY_VIDEO_COMMENT) !== true) {
25 return res.status(403)
26 .json({
27 error: 'User cannot remove any comments of this instance.'
28 })
29 }
30
31 return next()
32 }
33]
34
35// ---------------------------------------------------------------------------
36
37export {
38 bulkRemoveCommentsOfValidator
39}
40
41// ---------------------------------------------------------------------------