]>
Commit | Line | Data |
---|---|---|
1 | import * as express from 'express' | |
2 | import { body } from 'express-validator' | |
3 | import { isBulkRemoveCommentsOfScopeValid } from '@server/helpers/custom-validators/bulk' | |
4 | import { doesAccountNameWithHostExist } from '@server/helpers/middlewares' | |
5 | import { UserRight } from '@shared/models' | |
6 | import { BulkRemoveCommentsOfBody } from '@shared/models/bulk/bulk-remove-comments-of-body.model' | |
7 | import { logger } from '../../helpers/logger' | |
8 | import { areValidationErrors } from './utils' | |
9 | ||
10 | const 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 | ||
37 | export { | |
38 | bulkRemoveCommentsOfValidator | |
39 | } | |
40 | ||
41 | // --------------------------------------------------------------------------- |