From 6b1c97db797d93759547067ea96f08dcd790e5c9 Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Mon, 25 Jan 2021 11:07:16 -0500 Subject: [PATCH] feat: feature flag for auto-resolving a user's flags on ban [breaking] The default behaviour has now been changed to 'off'. Going forward, a user's flags will no longer automatically resolve on ban. --- .../en-GB/admin/settings/reputation.json | 4 +++- src/flags.js | 24 ++++++++++--------- src/views/admin/settings/reputation.tpl | 9 +++++++ 3 files changed, 25 insertions(+), 12 deletions(-) diff --git a/public/language/en-GB/admin/settings/reputation.json b/public/language/en-GB/admin/settings/reputation.json index f5659569a9..7cfa636521 100644 --- a/public/language/en-GB/admin/settings/reputation.json +++ b/public/language/en-GB/admin/settings/reputation.json @@ -16,5 +16,7 @@ "flags": "Flag Settings", "flags.limit-per-target": "Maximum number of times something can be flagged", - "flags.limit-per-target-placeholder": "Default: 0" + "flags.limit-per-target-placeholder": "Default: 0", + "flags.limit-per-target-help": "When a post or user is flagged multiple times, each additional flag is considered a "report" and added to the original flag. Set this option to a number other than zero to limit the number of reports an item can receive.", + "flags.auto-resolve-on-ban": "Automatically resolve all of a user's tickets when they are banned" } \ No newline at end of file diff --git a/src/flags.js b/src/flags.js index c6a2a90edd..444384c379 100644 --- a/src/flags.js +++ b/src/flags.js @@ -628,18 +628,20 @@ Flags.resolveFlag = async function (type, id, uid) { }; Flags.resolveUserPostFlags = async function (uid, callerUid) { - await batch.processSortedSet('uid:' + uid + ':posts', async function (pids) { - let postData = await posts.getPostsFields(pids, ['pid', 'flagId']); - postData = postData.filter(p => p && p.flagId); - for (const postObj of postData) { - if (parseInt(postObj.flagId, 10)) { - // eslint-disable-next-line no-await-in-loop - await Flags.update(postObj.flagId, callerUid, { state: 'resolved' }); + if (meta.config['flags:autoResolveOnBan']) { + await batch.processSortedSet('uid:' + uid + ':posts', async function (pids) { + let postData = await posts.getPostsFields(pids, ['pid', 'flagId']); + postData = postData.filter(p => p && p.flagId); + for (const postObj of postData) { + if (parseInt(postObj.flagId, 10)) { + // eslint-disable-next-line no-await-in-loop + await Flags.update(postObj.flagId, callerUid, { state: 'resolved' }); + } } - } - }, { - batch: 500, - }); + }, { + batch: 500, + }); + } }; Flags.getHistory = async function (flagId) { diff --git a/src/views/admin/settings/reputation.tpl b/src/views/admin/settings/reputation.tpl index 1ce7d808dd..c6e5c62387 100644 --- a/src/views/admin/settings/reputation.tpl +++ b/src/views/admin/settings/reputation.tpl @@ -78,6 +78,15 @@
+

+ [[admin/settings/reputation:flags.limit-per-target-help]] +

+
+
+