Skip to content

Node.js based forum software built for the modern web

feat: allow admins to hide topic event types (#14824)

palmoni5f2c968e9853f
diff --git a/install/data/defaults.json b/install/data/defaults.json
index fde027c5e7..93c827e227 100644
--- a/install/data/defaults.json
+++ b/install/data/defaults.json
@@ -17,6 +17,7 @@
"movingTopicsMaxPosts": 5,
"enablePostHistory": 1,
"topicBacklinks": 1,
+ "hiddenTopicEventTypes": [],
"postCacheSize": 20971520,
"disableChat": 0,
"chatEditDuration": 0,
diff --git a/public/language/en-GB/admin/settings/post.json b/public/language/en-GB/admin/settings/post.json
index ebf84cd656..4d39d52c3b 100644
--- a/public/language/en-GB/admin/settings/post.json
+++ b/public/language/en-GB/admin/settings/post.json
@@ -59,6 +59,8 @@
"backlinks": "Backlinks",
"backlinks.enabled": "Enable topic backlinks",
"backlinks.help": "If a post references another topic, a link back to the post will be inserted into the referenced topic at that point in time.",
+ "topic-events.hidden": "Hidden topic event types",
+ "topic-events.hidden-help": "Topic events of the selected types are not shown to anybody in the topic timeline. Events are still recorded, so re-enabling a type restores the events logged while it was hidden.",
"ip-tracking": "IP Tracking",
"ip-tracking.each-post": "Track IP Address for each post",
"enable-post-history": "Enable Post History"
diff --git a/src/controllers/admin/settings.js b/src/controllers/admin/settings.js
index 0738cd8920..5d48bb2352 100644
--- a/src/controllers/admin/settings.js
+++ b/src/controllers/admin/settings.js
@@ -7,6 +7,7 @@ const groups = require('../../groups');
const languages = require('../../languages');
const navigationAdmin = require('../../navigation/admin');
const social = require('../../social');
+const topics = require('../../topics');
const helpers = require('../helpers');
const plugins = require('../../plugins');
@@ -96,6 +97,7 @@ settingsController.post = async (req, res) => {
res.render('admin/settings/post', {
title: '[[admin/menu:settings/post]]',
groupsExemptFromPostQueue: groupData,
+ topicEventTypes: Object.keys(topics.events._types).sort(),
});
};
diff --git a/src/topics/events.js b/src/topics/events.js
index fda12af969..580e4aa168 100644
--- a/src/topics/events.js
+++ b/src/topics/events.js
@@ -235,6 +235,12 @@ async function modifyEvent({ uid, events }) {
// Remove events whose types no longer exist (e.g. plugin uninstalled)
events = events.filter(event => Events._types.hasOwnProperty(event.type));
+ // Remove event types hidden via acp settings
+ const hiddenTypes = meta.config.hiddenTopicEventTypes || [];
+ if (hiddenTypes.length) {
+ events = events.filter(event => !hiddenTypes.includes(event.type));
+ }
+
// Add user & metadata
events.forEach((event) => {
event.timestampISO = utils.toISOString(event.timestamp);
diff --git a/src/views/admin/settings/post.tpl b/src/views/admin/settings/post.tpl
index 1fbf1e2337..f5983cd1be 100644
--- a/src/views/admin/settings/post.tpl
+++ b/src/views/admin/settings/post.tpl
@@ -37,6 +37,16 @@
<p class="form-text">{{tx("admin/settings/post:backlinks.help")}}</p>
</div>
+ <div class="mb-3">
+ <label class="form-label" for="hiddenTopicEventTypes">{{tx("admin/settings/post:topic-events.hidden")}}</label>
+ <select id="hiddenTopicEventTypes" class="form-select" multiple data-field="hiddenTopicEventTypes">
+ {{{ each topicEventTypes }}}
+ <option value="{@value}">{@value}</option>
+ {{{ end }}}
+ </select>
+ <p class="form-text">{{tx("admin/settings/post:topic-events.hidden-help")}}</p>
+ </div>
+
<div class="form-check form-switch mb-3">
<input id="trackIPPerPost" class="form-check-input" type="checkbox" data-field="trackIpPerPost">
<label for="trackIPPerPost" class="form-check-label">{{tx("admin/settings/post:ip-tracking.each-post")}}</label>
diff --git a/test/topics/events.js b/test/topics/events.js
index 8b05921d59..f6acc487ff 100644
--- a/test/topics/events.js
+++ b/test/topics/events.js
@@ -84,6 +84,17 @@ describe('Topic Events', () => {
assert(['id', 'icon', 'text', 'timestamp', 'timestampISO', 'type', 'quux'].every(key => event.hasOwnProperty(key)));
});
});
+
+ it('should not return events of a type hidden in the acp', async () => {
+ const oldValue = meta.config.hiddenTopicEventTypes;
+ meta.config.hiddenTopicEventTypes = ['foo'];
+ const events = await topics.events.get(topic.topicData.tid);
+ assert.strictEqual(events.length, 0);
+
+ meta.config.hiddenTopicEventTypes = oldValue;
+ const restored = await topics.events.get(topic.topicData.tid);
+ assert.strictEqual(restored.length, 1);
+ });
});
describe('.purge()', () => {