diff options
Diffstat (limited to 'server/middlewares/validators/abuse.ts')
-rw-r--r-- | server/middlewares/validators/abuse.ts | 27 |
1 files changed, 14 insertions, 13 deletions
diff --git a/server/middlewares/validators/abuse.ts b/server/middlewares/validators/abuse.ts index 3b897fdef..7f002e0d5 100644 --- a/server/middlewares/validators/abuse.ts +++ b/server/middlewares/validators/abuse.ts | |||
@@ -71,9 +71,7 @@ const abuseReportValidator = [ | |||
71 | if (body.comment?.id && !await doesCommentIdExist(body.comment.id, res)) return | 71 | if (body.comment?.id && !await doesCommentIdExist(body.comment.id, res)) return |
72 | 72 | ||
73 | if (!body.video?.id && !body.account?.id && !body.comment?.id) { | 73 | if (!body.video?.id && !body.account?.id && !body.comment?.id) { |
74 | res.status(HttpStatusCode.BAD_REQUEST_400) | 74 | res.fail({ message: 'video id or account id or comment id is required.' }) |
75 | .json({ error: 'video id or account id or comment id is required.' }) | ||
76 | |||
77 | return | 75 | return |
78 | } | 76 | } |
79 | 77 | ||
@@ -195,8 +193,10 @@ const getAbuseValidator = [ | |||
195 | const message = `User ${user.username} does not have right to get abuse ${abuse.id}` | 193 | const message = `User ${user.username} does not have right to get abuse ${abuse.id}` |
196 | logger.warn(message) | 194 | logger.warn(message) |
197 | 195 | ||
198 | return res.status(HttpStatusCode.FORBIDDEN_403) | 196 | return res.fail({ |
199 | .json({ error: message }) | 197 | status: HttpStatusCode.FORBIDDEN_403, |
198 | message | ||
199 | }) | ||
200 | } | 200 | } |
201 | 201 | ||
202 | return next() | 202 | return next() |
@@ -209,10 +209,7 @@ const checkAbuseValidForMessagesValidator = [ | |||
209 | 209 | ||
210 | const abuse = res.locals.abuse | 210 | const abuse = res.locals.abuse |
211 | if (abuse.ReporterAccount.isOwned() === false) { | 211 | if (abuse.ReporterAccount.isOwned() === false) { |
212 | return res.status(HttpStatusCode.BAD_REQUEST_400) | 212 | return res.fail({ message: 'This abuse was created by a user of your instance.' }) |
213 | .json({ | ||
214 | error: 'This abuse was created by a user of your instance.' | ||
215 | }) | ||
216 | } | 213 | } |
217 | 214 | ||
218 | return next() | 215 | return next() |
@@ -246,13 +243,17 @@ const deleteAbuseMessageValidator = [ | |||
246 | const abuseMessage = await AbuseMessageModel.loadByIdAndAbuseId(messageId, abuse.id) | 243 | const abuseMessage = await AbuseMessageModel.loadByIdAndAbuseId(messageId, abuse.id) |
247 | 244 | ||
248 | if (!abuseMessage) { | 245 | if (!abuseMessage) { |
249 | return res.status(HttpStatusCode.NOT_FOUND_404) | 246 | return res.fail({ |
250 | .json({ error: 'Abuse message not found' }) | 247 | status: HttpStatusCode.NOT_FOUND_404, |
248 | message: 'Abuse message not found' | ||
249 | }) | ||
251 | } | 250 | } |
252 | 251 | ||
253 | if (user.hasRight(UserRight.MANAGE_ABUSES) !== true && abuseMessage.accountId !== user.Account.id) { | 252 | if (user.hasRight(UserRight.MANAGE_ABUSES) !== true && abuseMessage.accountId !== user.Account.id) { |
254 | return res.status(HttpStatusCode.FORBIDDEN_403) | 253 | return res.fail({ |
255 | .json({ error: 'Cannot delete this abuse message' }) | 254 | status: HttpStatusCode.FORBIDDEN_403, |
255 | message: 'Cannot delete this abuse message' | ||
256 | }) | ||
256 | } | 257 | } |
257 | 258 | ||
258 | res.locals.abuseMessage = abuseMessage | 259 | res.locals.abuseMessage = abuseMessage |