Skip to content

A platform for community discussion. Free, open, simple.

FEATURE: Add new configurable moderation guide (#36287)

Ted Johansson540dc392cd9f
diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml
index fabec146835..bb8d26e22de 100644
--- a/config/locales/client.en.yml
+++ b/config/locales/client.en.yml
@@ -986,6 +986,7 @@ en:
visibility: "Visibility"
topic_unlisted: "This topic is unlisted and only accessible via direct link."
help:
+ community_moderation_guide: "This community's moderation guide"
moderation_guide: "Discourse moderation guide"
flag_priorities: "Managing user reputation and flag priorities"
spam_detection: "Spam detection"
diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml
index cb90f5a27dd..760f910726a 100644
--- a/config/locales/server.en.yml
+++ b/config/locales/server.en.yml
@@ -2306,6 +2306,7 @@ en:
auto_silence_fast_typers_on_first_post: "Automatically silence users that do not meet `fast typing threshold`"
auto_silence_fast_typers_max_trust_level: "Maximum trust level to auto silence fast typers"
auto_silence_first_post_regex: "Case insensitive regex that if passed will cause first post by user to be silenced and sent to approval queue. Example: raging|a[bc]a , will cause all posts containing raging or aba or aca to be silenced on first. Only applies to first post. DEPRECATED: Use Silence Watched Words instead."
+ moderator_guide_topic: "The topic that outlines how you moderate your community. Link will be visible on the review queue for moderators and admins."
reviewable_claiming: "Does reviewable content need to be claimed before it can be acted upon?"
reviewable_default_topics: "Show reviewable content grouped by topic by default"
reviewable_default_visibility: "Don't show reviewable items unless they meet this priority"
@@ -2781,6 +2782,7 @@ en:
invalid_username: "There's no user with that username."
valid_username: "There's a user with that username."
invalid_group: "There's no group with that name."
+ invalid_topic: "There's no topic with that ID."
invalid_integer_min_max: "Value must be between %{min} and %{max}."
invalid_integer_min: "Value must be %{min} or greater."
invalid_integer_max: "Value cannot be higher than %{max}."
diff --git a/config/site_settings.yml b/config/site_settings.yml
index 058cc6c3ab9..c7a0ead87ea 100644
--- a/config/site_settings.yml
+++ b/config/site_settings.yml
@@ -3579,6 +3579,11 @@ uncategorized:
validator: "DefaultComposerCategoryValidator"
area: "posts_and_topics"
+ moderator_guide_topic:
+ type: "topic"
+ default: ""
+ client: true
+
notify_about_reviewable_item_after:
type: float
default: 48
diff --git a/frontend/discourse/admin/components/site-setting.gjs b/frontend/discourse/admin/components/site-setting.gjs
index 6ec1ab63abf..40d3c098916 100644
--- a/frontend/discourse/admin/components/site-setting.gjs
+++ b/frontend/discourse/admin/components/site-setting.gjs
@@ -51,6 +51,7 @@ const CUSTOM_TYPES = [
"font_list",
"locale_list",
"locale_enum",
+ "topic",
];
export default class SiteSettingComponent extends Component {
diff --git a/frontend/discourse/admin/components/site-settings/topic.gjs b/frontend/discourse/admin/components/site-settings/topic.gjs
new file mode 100644
index 00000000000..2f883d17763
--- /dev/null
+++ b/frontend/discourse/admin/components/site-settings/topic.gjs
@@ -0,0 +1,59 @@
+import Component from "@glimmer/component";
+import { tracked } from "@glimmer/tracking";
+import { hash } from "@ember/helper";
+import { action } from "@ember/object";
+import { isPresent } from "@ember/utils";
+import TopicModel from "discourse/models/topic";
+import TopicChooser from "discourse/select-kit/components/topic-chooser";
+
+export default class Topic extends Component {
+ @tracked selectedTopic;
+ @tracked selectedTopicId = this.args.value;
+ @tracked topicLoading = false;
+
+ constructor() {
+ super(...arguments);
+
+ if (isPresent(this.selectedTopicId)) {
+ this.loadSelectedTopic();
+ }
+ }
+
+ @action
+ onChangeTopicSetting(topicId, topic) {
+ this.args.changeValueCallback(topicId);
+ this.selectedTopicId = topicId;
+ this.selectedTopic = topic;
+ }
+
+ get selectedTopicContent() {
+ if (this.topicLoading || !this.selectedTopicId) {
+ return [];
+ }
+ return [this.selectedTopic];
+ }
+
+ async loadSelectedTopic() {
+ this.topicLoading = true;
+
+ try {
+ const topic = await TopicModel.find(this.selectedTopicId, {});
+ this.onChangeTopicSetting(this.selectedTopicId, topic);
+ this.topicLoading = false;
+ } catch {
+ // eslint-disable-next-line no-console
+ console.error("Selected topic has been deleted.");
+ } finally {
+ this.topicLoading = false;
+ }
+ }
+
+ <template>
+ <TopicChooser
+ @value={{@value}}
+ @content={{this.selectedTopicContent}}
+ @onChange={{this.onChangeTopicSetting}}
+ @options={{hash castInteger=true}}
+ />
+ </template>
+}
diff --git a/frontend/discourse/app/components/reviewable-refresh/help-resources.gjs b/frontend/discourse/app/components/reviewable-refresh/help-resources.gjs
index 52fbafe0c31..c4a186115d4 100644
--- a/frontend/discourse/app/components/reviewable-refresh/help-resources.gjs
+++ b/frontend/discourse/app/components/reviewable-refresh/help-resources.gjs
@@ -1,43 +1,67 @@
+import Component from "@glimmer/component";
+import { service } from "@ember/service";
+import { isPresent } from "@ember/utils";
import icon from "discourse/helpers/d-icon";
+import getURL from "discourse/lib/get-url";
import { i18n } from "discourse-i18n";
-<template>
- <div class="review-item__resources">
- <h3 class="review-item__aside-title">{{i18n "review.need_help"}}</h3>
- <ul class="review-resources__list">
- <li class="review-resources__item">
- <span class="review-resources__icon">
- {{icon "book"}}
- </span>
- <a
- href="https://meta.discourse.org/t/-/63116"
- class="review-resources__link"
- >
- {{i18n "review.help.moderation_guide"}}
- </a>
- </li>
- <li class="review-resources__item">
- <span class="review-resources__icon">
- {{icon "book"}}
- </span>
- <a
- href="https://meta.discourse.org/t/-/123464"
- class="review-resources__link"
- >
- {{i18n "review.help.flag_priorities"}}
- </a>
- </li>
- <li class="review-resources__item">
- <span class="review-resources__icon">
- {{icon "book"}}
- </span>
- <a
- href="https://meta.discourse.org/t/-/343541"
- class="review-resources__link"
- >
- {{i18n "review.help.spam_detection"}}
- </a>
- </li>
- </ul>
- </div>
-</template>
+export default class HelpResources extends Component {
+ @service siteSettings;
+
+ get moderatorGuideUrl() {
+ if (isPresent(this.siteSettings.moderator_guide_topic)) {
+ return getURL("/t/") + this.siteSettings.moderator_guide_topic;
+ }
+ }
+
+ <template>
+ <div class="review-item__resources">
+ <h3 class="review-item__aside-title">{{i18n "review.need_help"}}</h3>
+ <ul class="review-resources__list">
+ {{#if this.moderatorGuideUrl}}
+ <li class="review-resources__item">
+ <span class="review-resources__icon">
+ {{icon "book"}}
+ </span>
+ <a href={{this.moderatorGuideUrl}} class="review-resources__link">
+ {{i18n "review.help.community_moderation_guide"}}
+ </a>
+ </li>
+ {{/if}}
+ <li class="review-resources__item">
+ <span class="review-resources__icon">
+ {{icon "book"}}
+ </span>
+ <a
+ href="https://meta.discourse.org/t/-/63116"
+ class="review-resources__link"
+ >
+ {{i18n "review.help.moderation_guide"}}
+ </a>
+ </li>
+ <li class="review-resources__item">
+ <span class="review-resources__icon">
+ {{icon "book"}}
+ </span>
+ <a
+ href="https://meta.discourse.org/t/-/123464"
+ class="review-resources__link"
+ >
+ {{i18n "review.help.flag_priorities"}}
+ </a>
+ </li>
+ <li class="review-resources__item">
+ <span class="review-resources__icon">
+ {{icon "book"}}
+ </span>
+ <a
+ href="https://meta.discourse.org/t/-/343541"
+ class="review-resources__link"
+ >
+ {{i18n "review.help.spam_detection"}}
+ </a>
+ </li>
+ </ul>
+ </div>
+ </template>
+}
diff --git a/lib/site_settings/type_supervisor.rb b/lib/site_settings/type_supervisor.rb
index 9940e218bef..0538e32d9c6 100644
--- a/lib/site_settings/type_supervisor.rb
+++ b/lib/site_settings/type_supervisor.rb
@@ -63,6 +63,7 @@ class SiteSettings::TypeSupervisor
file_size_restriction: 27,
objects: 28,
locale_enum: 29,
+ topic: 30,
)
end
@@ -344,6 +345,8 @@ class SiteSettings::TypeSupervisor
StringSettingValidator
when self.class.types[:host_list]
HostListSettingValidator
+ when self.class.types[:topic]
+ TopicSettingValidator
else
nil
end
diff --git a/lib/validators/topic_setting_validator.rb b/lib/validators/topic_setting_validator.rb
new file mode 100644
index 00000000000..a85fae0dd81
--- /dev/null
+++ b/lib/validators/topic_setting_validator.rb
@@ -0,0 +1,15 @@
+# frozen_string_literal: true
+
+class TopicSettingValidator
+ def initialize(opts = {})
+ @opts = opts
+ end
+
+ def valid_value?(val)
+ val.blank? || Topic.with_deleted.exists?(id: val)
+ end
+
+ def error_message
+ I18n.t("site_settings.errors.invalid_topic")
+ end
+end
diff --git a/spec/lib/validators/topic_setting_validator_spec.rb b/spec/lib/validators/topic_setting_validator_spec.rb
new file mode 100644
index 00000000000..5791195e545
--- /dev/null
+++ b/spec/lib/validators/topic_setting_validator_spec.rb
@@ -0,0 +1,26 @@
+# frozen_string_literal: true
+
+RSpec.describe TopicSettingValidator do
+ describe "#valid_value?" do
+ subject(:validator) { described_class.new }
+
+ fab!(:topic)
+
+ it "has a valid error message" do
+ expect(validator.error_message).to eq(I18n.t("site_settings.errors.invalid_topic"))
+ end
+
+ it "returns true for blank values" do
+ expect(validator.valid_value?("")).to eq(true)
+ expect(validator.valid_value?(nil)).to eq(true)
+ end
+
+ it "returns true if value matches an existing topic ID" do
+ expect(validator.valid_value?(topic.id)).to eq(true)
+ end
+
+ it "returns false if value does not match an existing topic ID" do
+ expect(validator.valid_value?(1337)).to eq(false)
+ end
+ end
+end
diff --git a/spec/system/admin_site_setting_topic_chooser_spec.rb b/spec/system/admin_site_setting_topic_chooser_spec.rb
new file mode 100644
index 00000000000..e5d1cb61dc3
--- /dev/null
+++ b/spec/system/admin_site_setting_topic_chooser_spec.rb
@@ -0,0 +1,42 @@
+# frozen_string_literal: true
+
+describe "Admin Site Setting Topic Selector Component", type: :system do
+ let(:settings_page) { PageObjects::Pages::AdminSiteSettings.new }
+ let(:banner) { PageObjects::Components::AdminChangesBanner.new }
+ fab!(:admin)
+ fab!(:topic) { Fabricate(:topic, title: "Moderator guide", fancy_title: "Moderator guide") }
+ fab!(:post) { Fabricate(:post, topic: topic) }
+
+ before { sign_in(admin) }
+
+ it "can configure the setting with a topic" do
+ settings_page.visit
+ settings_page.type_in_search("moderator guide topic")
+
+ expect(settings_page).to have_n_results(1)
+
+ settings_page.find(".topic-chooser > summary").click
+
+ expect(settings_page).to have_css("input.filter-input")
+
+ settings_page.find("input.filter-input").fill_in(with: topic.id)
+ settings_page.find(".topic-row").click
+
+ expect(settings_page).to have_css(".selected-name", text: "Moderator guide")
+
+ banner.click_save
+
+ expect(settings_page).to have_overridden_topic_setting("moderator_guide_topic", value: topic.id)
+ end
+
+ it "can load a topics title when loading the component" do
+ SiteSetting.moderator_guide_topic = topic.id
+
+ settings_page.visit
+ settings_page.type_in_search("moderator guide topic")
+
+ expect(settings_page).to have_n_results(1)
+
+ expect(settings_page).to have_css(".selected-name", text: "Moderator guide")
+ end
+end
diff --git a/spec/system/page_objects/pages/admin_site_settings.rb b/spec/system/page_objects/pages/admin_site_settings.rb
index c65700afdb2..749266b45e1 100644
--- a/spec/system/page_objects/pages/admin_site_settings.rb
+++ b/spec/system/page_objects/pages/admin_site_settings.rb
@@ -97,6 +97,12 @@ module PageObjects
true
end
+ def has_overridden_topic_setting?(setting_name, value: nil)
+ setting_field = find_setting(setting_name, overridden: true)
+ return setting_field.find(".selected-name")["data-value"] == value.to_s if value
+ true
+ end
+
def has_no_overridden_setting?(setting_name)
find_setting(setting_name, overridden: false)
end
diff --git a/spec/system/reviewables_spec.rb b/spec/system/reviewables_spec.rb
index 4a1a810f489..5d9d13d11b9 100644
--- a/spec/system/reviewables_spec.rb
+++ b/spec/system/reviewables_spec.rb
@@ -331,4 +331,37 @@ describe "Reviewables", type: :system do
expect(review_page).to have_no_information_about_unknown_reviewables_visible
end
end
+
+ describe "custom community moderator guide topic" do
+ fab!(:group)
+ fab!(:topic) { Fabricate(:topic, title: "Moderator guide") }
+ fab!(:post) { Fabricate(:post, topic: topic) }
+ fab!(:reviewable, :reviewable_queued_post)
+
+ before do
+ SiteSetting.reviewable_old_moderator_actions = false
+ SiteSetting.reviewable_ui_refresh = group.name
+ group.add(admin)
+ end
+
+ it "displays the custom guide topic link when configured" do
+ SiteSetting.moderator_guide_topic = topic.id
+
+ review_page.visit_reviewable(reviewable)
+ expect(review_page).to have_css(
+ "a.review-resources__link",
+ text: I18n.t("js.review.help.community_moderation_guide"),
+ )
+ end
+
+ it "does not display anything when no custom guide topic configured" do
+ SiteSetting.moderator_guide_topic = ""
+
+ review_page.visit_reviewable(reviewable)
+ expect(review_page).to have_no_css(
+ "a.review-resources__link",
+ text: I18n.t("js.review.help.community_moderation_guide"),
+ )
+ end
+ end
end