From 94148c9028829b5576a5dcbfba2c7fb9cf6443d3 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Mon, 27 Jul 2020 11:40:30 +0200 Subject: Add abuse messages management in my account --- server/middlewares/validators/abuse.ts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'server/middlewares') diff --git a/server/middlewares/validators/abuse.ts b/server/middlewares/validators/abuse.ts index cb0bc658a..2a096e0af 100644 --- a/server/middlewares/validators/abuse.ts +++ b/server/middlewares/validators/abuse.ts @@ -201,6 +201,21 @@ const getAbuseValidator = [ } ] +const checkAbuseValidForMessagesValidator = [ + (req: express.Request, res: express.Response, next: express.NextFunction) => { + logger.debug('Checking checkAbuseValidForMessagesValidator parameters', { parameters: req.body }) + + const abuse = res.locals.abuse + if (abuse.ReporterAccount.isOwned() === false) { + return res.status(400).json({ + error: 'This abuse was created by a user of your instance.', + }) + } + + return next() + } +] + const addAbuseMessageValidator = [ body('message').custom(isAbuseMessageValid).not().isEmpty().withMessage('Should have a valid abuse message'), @@ -357,6 +372,7 @@ export { abuseReportValidator, abuseGetValidator, addAbuseMessageValidator, + checkAbuseValidForMessagesValidator, abuseUpdateValidator, deleteAbuseMessageValidator, abuseListForUserValidator, -- cgit v1.2.3