2
1

bulk.ts 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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. import { HttpStatusCode } from '@shared/core-utils/miscs/http-error-codes'
  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. async (req: express.Request, res: express.Response, next: express.NextFunction) => {
  15. logger.debug('Checking bulkRemoveCommentsOfValidator parameters', { parameters: req.body })
  16. if (areValidationErrors(req, res)) return
  17. if (!await doesAccountNameWithHostExist(req.body.accountName, res)) return
  18. const user = res.locals.oauth.token.User
  19. const body = req.body as BulkRemoveCommentsOfBody
  20. if (body.scope === 'instance' && user.hasRight(UserRight.REMOVE_ANY_VIDEO_COMMENT) !== true) {
  21. return res.status(HttpStatusCode.FORBIDDEN_403)
  22. .json({
  23. error: 'User cannot remove any comments of this instance.'
  24. })
  25. }
  26. return next()
  27. }
  28. ]
  29. // ---------------------------------------------------------------------------
  30. export {
  31. bulkRemoveCommentsOfValidator
  32. }
  33. // ---------------------------------------------------------------------------