Skip to content

Node.js based forum software built for the modern web

refactor: custom reasons

Barış Soner Uşaklı1fa3a1242653
diff --git a/public/openapi/read/admin/manage/users/custom-reasons.yaml b/public/openapi/read/admin/manage/users/custom-reasons.yaml
index ea609e1709..fe1bec8357 100644
--- a/public/openapi/read/admin/manage/users/custom-reasons.yaml
+++ b/public/openapi/read/admin/manage/users/custom-reasons.yaml
@@ -25,4 +25,6 @@ get:
parsedBody:
type: string
description: "body parsed with filter:parse.raw hook"
+ translatedType:
+ type: string
- $ref: ../../../../components/schemas/CommonProps.yaml#/CommonProps
\ No newline at end of file
diff --git a/src/user/bans.js b/src/user/bans.js
index 417f0c3e7d..db1163307e 100644
--- a/src/user/bans.js
+++ b/src/user/bans.js
@@ -169,10 +169,16 @@ module.exports = function (User) {
const keys = await db.getSortedSetRange('custom-reasons', 0, -1);
type = type || '';
const reasons = (await db.getObjects(keys.map(k => `custom-reason:${k}`))).filter(Boolean);
+ const translations = new Map([
+ ['ban', '[[admin/manage/custom-reasons:reason-ban]]'],
+ ['mute', '[[admin/manage/custom-reasons:reason-mute]]'],
+ ['post-queue', '[[admin/manage/custom-reasons:reason-post-queue]]'],
+ ]);
await Promise.all(reasons.map(async (reason, i) => {
reason.key = i;
reason.parsedBody = translator.escape(await plugins.hooks.fire('filter:parse.raw', reason.body || ''));
reason.body = translator.escape(reason.body);
+ reason.translatedType = translations.get(reason.type) || '';
}));
if (type !== '') {
return reasons.filter(reason => reason.type === type || reason.type === '');
diff --git a/src/views/admin/manage/users/custom-reasons.tpl b/src/views/admin/manage/users/custom-reasons.tpl
index 29ba650e75..471177d24b 100644
--- a/src/views/admin/manage/users/custom-reasons.tpl
+++ b/src/views/admin/manage/users/custom-reasons.tpl
@@ -33,7 +33,7 @@
<a href="#" component="sort/handle" class="btn btn-light btn-sm d-none d-md-block ui-sortable-handle" style="cursor:grab;"><i class="fa fa-arrows-up-down text-muted"></i></a>
</td>
<td class="text-nowrap">{./title}</td>
- <td class="text-nowrap">{{{ if ./type }}}[[admin/manage/custom-reasons:reason-{{./type}}]]{{{ else }}}[[admin/manage/custom-reasons:reason-all]]{{{ end }}}</td>
+ <td class="text-nowrap">{{{ if ./type }}}{./translatedType}{{{ else }}}[[admin/manage/custom-reasons:reason-all]]{{{ end }}}</td>
<td class="">{./parsedBody}</td>
<td class="">
<div class="d-flex justify-content-end gap-1">