Skip to content

Node.js based forum software built for the modern web

feat: rescind post flags

Opliko9ab1a2d12942
diff --git a/public/language/en-GB/flags.json b/public/language/en-GB/flags.json
index 996e027833..9e55d76646 100644
--- a/public/language/en-GB/flags.json
+++ b/public/language/en-GB/flags.json
@@ -87,8 +87,11 @@
"modal-submit": "Submit Report",
"modal-submit-success": "Content has been flagged for moderation.",
+ "modal-confirm-rescind": "Rescind Report?",
+
"bulk-actions": "Bulk Actions",
"bulk-resolve": "Resolve Flag(s)",
+ "bulk-purge": "Purge Flag(s)",
"bulk-success": "%1 flags updated",
"flagged-timeago-readable": "Flagged <span class=\"timeago\" title=\"%1\"></span> (%2)",
"auto-flagged": "[Auto Flagged] Received %1 downvotes."
diff --git a/public/src/client/topic/postTools.js b/public/src/client/topic/postTools.js
index 571361734f..2c49b5d948 100644
--- a/public/src/client/topic/postTools.js
+++ b/public/src/client/topic/postTools.js
@@ -147,6 +147,18 @@ define('forum/topic/postTools', [
});
});
+ postContainer.on('click', '[component="post/already-flagged"]', function () {
+ const pid = getData($(this), 'data-pid');
+ require(['flags'], function (flags) {
+ bootbox.confirm('[[flags:modal-confirm-rescind]]', function (confirm) {
+ if (!confirm) {
+ return;
+ }
+ flags.rescindByType('post', pid);
+ });
+ });
+ });
+
postContainer.on('click', '[component="post/flagUser"]', function () {
const uid = getData($(this), 'data-uid');
require(['flags'], function (flags) {
diff --git a/public/src/modules/flags.js b/public/src/modules/flags.js
index bff55bf8b5..845a605f01 100644
--- a/public/src/modules/flags.js
+++ b/public/src/modules/flags.js
@@ -62,6 +62,32 @@ define('flags', ['hooks', 'components', 'api', 'alerts'], function (hooks, compo
}).catch(alerts.error);
};
+ Flag.rescindByType = function (type, id) {
+ api.del(`/flags/${type}/${id}/report`).then(() => {
+ alerts.success('[[flags:rescinded]]');
+ hooks.fire('action:flag.rescinded', { type: type, id: id });
+ if (type === 'post') {
+ const postEl = components.get('post', 'pid', id);
+ postEl.find('[component="post/flag"]').removeClass('hidden').parent().attr('hidden', null);
+ postEl.find('[component="post/already-flagged"]').addClass('hidden').parent().attr('hidden', '');
+ }
+ }).catch(alerts.error);
+ };
+
+ Flag.rescind = function (flagId) {
+ api.del(`/flags/${flagId}/report`).then(() => {
+ alerts.success('[[flags:rescinded]]');
+ hooks.fire('action:flag.rescinded', { flagId: flagId });
+ }).catch(alerts.error);
+ };
+
+ Flag.purge = function (flagId) {
+ api.del(`/flags/${flagId}`).then(() => {
+ alerts.success('[[flags:purged]]');
+ hooks.fire('action:flag.purged', { flagId: flagId });
+ }).catch(alerts.error);
+ };
+
function createFlag(type, id, reason) {
if (!type || !id || !reason) {
return;
diff --git a/src/api/flags.js b/src/api/flags.js
index ffa56e2782..78fe35bb51 100644
--- a/src/api/flags.js
+++ b/src/api/flags.js
@@ -59,6 +59,24 @@ flagsApi.rescind = async ({ uid }, { flagId }) => {
await flags.rescindReport(type, targetId, uid);
};
+flagsApi.rescindPost = async ({ uid }, { pid }) => {
+ const exists = await flags.exists('post', pid, uid);
+ if (!exists) {
+ throw new Error('[[error:no-flag]]');
+ }
+
+ await flags.rescindReport('post', pid, uid);
+};
+
+flagsApi.rescindUser = async ({ uid }, { uid: targetUid }) => {
+ const exists = await flags.exists('user', targetUid, uid);
+ if (!exists) {
+ throw new Error('[[error:no-flag]]');
+ }
+
+ await flags.rescindReport('user', targetUid, uid);
+};
+
flagsApi.appendNote = async (caller, data) => {
const allowed = await user.isPrivileged(caller.uid);
if (!allowed) {
diff --git a/src/controllers/write/flags.js b/src/controllers/write/flags.js
index 4e3ac376a7..cb81ee10ac 100644
--- a/src/controllers/write/flags.js
+++ b/src/controllers/write/flags.js
@@ -37,6 +37,16 @@ Flags.rescind = async (req, res) => {
helpers.formatApiResponse(200, res);
};
+Flags.rescindPost = async (req, res) => {
+ await api.flags.rescindPost(req, { pid: req.params.pid });
+ helpers.formatApiResponse(200, res);
+};
+
+Flags.rescindUser = async (req, res) => {
+ await api.flags.rescindUser(req, { uid: req.params.uid });
+ helpers.formatApiResponse(200, res);
+};
+
Flags.appendNote = async (req, res) => {
const { note, datetime } = req.body;
const payload = await api.flags.appendNote(req, {
diff --git a/src/routes/write/flags.js b/src/routes/write/flags.js
index f30232c5b6..da0b7abe6c 100644
--- a/src/routes/write/flags.js
+++ b/src/routes/write/flags.js
@@ -19,6 +19,9 @@ module.exports = function () {
setupApiRoute(router, 'delete', '/:flagId/report', middlewares, controllers.write.flags.rescind);
+ setupApiRoute(router, 'delete', '/post/:pid/report', middlewares, controllers.write.flags.rescindPost);
+ setupApiRoute(router, 'delete', '/user/:uid/report', middlewares, controllers.write.flags.rescindUser);
+
setupApiRoute(router, 'post', '/:flagId/notes', [...middlewares, middleware.assert.flag], controllers.write.flags.appendNote);
setupApiRoute(router, 'delete', '/:flagId/notes/:datetime', [...middlewares, middleware.assert.flag], controllers.write.flags.deleteNote);