Skip to content

Commit

Permalink
feat: feature flag for auto-resolving a user's flags on ban [breaking]
Browse files Browse the repository at this point in the history
The default behaviour has now been changed to 'off'. Going forward, a user's flags will no longer automatically resolve on ban.
  • Loading branch information
julianlam committed Jan 25, 2021
1 parent a396b10 commit 6b1c97d
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 12 deletions.
4 changes: 3 additions & 1 deletion public/language/en-GB/admin/settings/reputation.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
24 changes: 13 additions & 11 deletions src/flags.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
9 changes: 9 additions & 0 deletions src/views/admin/settings/reputation.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,15 @@
<div class="form-group">
<label for="flags:limitPerTarget">[[admin/settings/reputation:flags.limit-per-target]]</label>
<input type="text" class="form-control" placeholder="[[admin/settings/reputation:flags.limit-per-target-placeholder]]" data-field="flags:limitPerTarget" id="flags:limitPerTarget">
<p class="help-block">
[[admin/settings/reputation:flags.limit-per-target-help]]
</p>
</div>
<div class="checkbox">
<label class="mdl-switch mdl-js-switch mdl-js-ripple-effect">
<input type="checkbox" class="mdl-switch__input" data-field="flags:autoResolveOnBan">
<span class="mdl-switch__label"><strong>[[admin/settings/reputation:flags.auto-resolve-on-ban]]</strong></span>
</label>
</div>
</form>
</div>
Expand Down

0 comments on commit 6b1c97d

Please sign in to comment.