2021-08-27 08:32:44 -04:00
|
|
|
import express from 'express'
|
2020-05-14 10:56:15 -04:00
|
|
|
import { body } from 'express-validator'
|
|
|
|
import { isBulkRemoveCommentsOfScopeValid } from '@server/helpers/custom-validators/bulk'
|
2021-07-16 08:27:30 -04:00
|
|
|
import { HttpStatusCode, UserRight } from '@shared/models'
|
2020-05-14 10:56:15 -04:00
|
|
|
import { BulkRemoveCommentsOfBody } from '@shared/models/bulk/bulk-remove-comments-of-body.model'
|
|
|
|
import { logger } from '../../helpers/logger'
|
2021-06-03 11:33:44 -04:00
|
|
|
import { areValidationErrors, doesAccountNameWithHostExist } from './shared'
|
2020-05-14 10:56:15 -04:00
|
|
|
|
|
|
|
const bulkRemoveCommentsOfValidator = [
|
|
|
|
body('accountName').exists().withMessage('Should have an account name with host'),
|
|
|
|
body('scope')
|
|
|
|
.custom(isBulkRemoveCommentsOfScopeValid).withMessage('Should have a valid scope'),
|
|
|
|
|
|
|
|
async (req: express.Request, res: express.Response, next: express.NextFunction) => {
|
|
|
|
logger.debug('Checking bulkRemoveCommentsOfValidator parameters', { parameters: req.body })
|
|
|
|
|
|
|
|
if (areValidationErrors(req, res)) return
|
|
|
|
if (!await doesAccountNameWithHostExist(req.body.accountName, res)) return
|
|
|
|
|
|
|
|
const user = res.locals.oauth.token.User
|
|
|
|
const body = req.body as BulkRemoveCommentsOfBody
|
|
|
|
|
|
|
|
if (body.scope === 'instance' && user.hasRight(UserRight.REMOVE_ANY_VIDEO_COMMENT) !== true) {
|
2021-05-31 19:36:53 -04:00
|
|
|
return res.fail({
|
|
|
|
status: HttpStatusCode.FORBIDDEN_403,
|
|
|
|
message: 'User cannot remove any comments of this instance.'
|
2020-05-14 10:56:15 -04:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
return next()
|
|
|
|
}
|
|
|
|
]
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
export {
|
|
|
|
bulkRemoveCommentsOfValidator
|
|
|
|
}
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|