2021-08-27 07:32:44 -05:00
|
|
|
import express from 'express'
|
2020-05-14 09:56:15 -05:00
|
|
|
import { body } from 'express-validator'
|
2023-07-31 07:34:36 -05:00
|
|
|
import { BulkRemoveCommentsOfBody, HttpStatusCode, UserRight } from '@peertube/peertube-models'
|
|
|
|
import { isBulkRemoveCommentsOfScopeValid } from '@server/helpers/custom-validators/bulk.js'
|
|
|
|
import { areValidationErrors, doesAccountNameWithHostExist } from './shared/index.js'
|
2020-05-14 09:56:15 -05:00
|
|
|
|
|
|
|
const bulkRemoveCommentsOfValidator = [
|
2022-08-17 07:27:04 -05:00
|
|
|
body('accountName')
|
|
|
|
.exists(),
|
2020-05-14 09:56:15 -05:00
|
|
|
body('scope')
|
2022-08-17 07:27:04 -05:00
|
|
|
.custom(isBulkRemoveCommentsOfScopeValid),
|
2020-05-14 09:56:15 -05:00
|
|
|
|
|
|
|
async (req: express.Request, res: express.Response, next: express.NextFunction) => {
|
|
|
|
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
|
|
|
|
|
2024-03-29 08:25:03 -05:00
|
|
|
if (body.scope === 'instance' && user.hasRight(UserRight.MANAGE_ANY_VIDEO_COMMENT) !== true) {
|
2021-05-31 18:36:53 -05:00
|
|
|
return res.fail({
|
|
|
|
status: HttpStatusCode.FORBIDDEN_403,
|
|
|
|
message: 'User cannot remove any comments of this instance.'
|
2020-05-14 09:56:15 -05:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
return next()
|
|
|
|
}
|
|
|
|
]
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
export {
|
|
|
|
bulkRemoveCommentsOfValidator
|
|
|
|
}
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|