Skip to content
This repository was archived by the owner on Jul 22, 2025. It is now read-only.

Commit 8d943fa

Browse files
authored
FEATURE: Display spam module on features list. (#1469)
1 parent b35f9bc commit 8d943fa

File tree

6 files changed

+76
-32
lines changed

6 files changed

+76
-32
lines changed

assets/javascripts/discourse/components/ai-features-list.gjs

Lines changed: 35 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,11 @@ export default class AiFeaturesList extends Component {
6868
});
6969
}
7070

71+
@action
72+
isSpamModule(aModule) {
73+
return aModule.module_name === "spam";
74+
}
75+
7176
@action
7277
hasGroups(feature) {
7378
return this.groupList(feature).length > 0;
@@ -101,12 +106,20 @@ export default class AiFeaturesList extends Component {
101106
<h3>{{i18n
102107
(concat "discourse_ai.features." module.module_name ".name")
103108
}}</h3>
104-
<DButton
105-
class="edit"
106-
@label="discourse_ai.features.edit"
107-
@route="adminPlugins.show.discourse-ai-features.edit"
108-
@routeModels={{module.id}}
109-
/>
109+
{{#if (this.isSpamModule module)}}
110+
<DButton
111+
class="edit"
112+
@label="discourse_ai.features.edit"
113+
@route="adminPlugins.show.discourse-ai-spam"
114+
/>
115+
{{else}}
116+
<DButton
117+
class="edit"
118+
@label="discourse_ai.features.edit"
119+
@route="adminPlugins.show.discourse-ai-features.edit"
120+
@routeModels={{module.id}}
121+
/>
122+
{{/if}}
110123
</div>
111124
<div>{{i18n
112125
(concat
@@ -181,20 +194,22 @@ export default class AiFeaturesList extends Component {
181194
{{i18n "discourse_ai.features.no_llm"}}
182195
{{/if}}
183196
</div>
184-
{{#if feature.personas}}
185-
<div class="ai-feature-card__groups">
186-
<span>{{i18n "discourse_ai.features.groups"}}</span>
187-
{{#if (this.hasGroups feature)}}
188-
<ul class="ai-feature-card__item-groups">
189-
{{#each (this.groupList feature) as |group|}}
190-
<li>{{group.name}}</li>
191-
{{/each}}
192-
</ul>
193-
{{else}}
194-
{{i18n "discourse_ai.features.no_groups"}}
195-
{{/if}}
196-
</div>
197-
{{/if}}
197+
{{#unless (this.isSpamModule module)}}
198+
{{#if feature.personas}}
199+
<div class="ai-feature-card__groups">
200+
<span>{{i18n "discourse_ai.features.groups"}}</span>
201+
{{#if (this.hasGroups feature)}}
202+
<ul class="ai-feature-card__item-groups">
203+
{{#each (this.groupList feature) as |group|}}
204+
<li>{{group.name}}</li>
205+
{{/each}}
206+
</ul>
207+
{{else}}
208+
{{i18n "discourse_ai.features.no_groups"}}
209+
{{/if}}
210+
</div>
211+
{{/if}}
212+
{{/unless}}
198213
</div>
199214
</div>
200215
{{/each}}

config/locales/client.en.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ en:
230230

231231
ai_helper:
232232
name: "Helper"
233-
description: "Assists users in community interaction, such as creating topics, writing posts, and reading content."
233+
description: "Assists users in community interaction, such as creating topics, writing posts, and reading content"
234234
proofread: Proofread text
235235
title_suggestions: "Suggest titles"
236236
explain: "Explain"
@@ -248,6 +248,11 @@ en:
248248
post_raw_translator: "Post raw translator"
249249
topic_title_translator: "Topic title translator"
250250
short_text_translator: "Short text translator"
251+
252+
spam:
253+
name: "Spam"
254+
description: "Identifies potential spam using the selected LLM and flags it for site moderators to inspect in the review queue"
255+
inspect_posts: "Inspect posts"
251256

252257
modals:
253258
select_option: "Select an option..."

lib/configuration/feature.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,19 @@ def bot_features
131131
]
132132
end
133133

134+
def spam_features
135+
feature_cache[:spam] ||= [
136+
new(
137+
"inspect_posts",
138+
nil,
139+
DiscourseAi::Configuration::Module::SPAM_ID,
140+
DiscourseAi::Configuration::Module::SPAM,
141+
persona_ids_lookup: -> { [AiModerationSetting.spam&.ai_persona_id].compact },
142+
llm_models_lookup: -> { [AiModerationSetting.spam&.llm_model].compact },
143+
),
144+
]
145+
end
146+
134147
def lookup_bot_persona_ids
135148
AiPersona
136149
.where(enabled: true)
@@ -182,6 +195,7 @@ def all
182195
ai_helper_features,
183196
translation_features,
184197
bot_features,
198+
spam_features,
185199
].flatten
186200
end
187201

lib/configuration/module.rb

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@ class Module
1010
AI_HELPER = "ai_helper"
1111
TRANSLATION = "translation"
1212
BOT = "bot"
13+
SPAM = "spam"
1314

14-
NAMES = [SUMMARIZATION, SEARCH, DISCORD, INFERENCE, AI_HELPER, TRANSLATION, BOT].freeze
15+
NAMES = [SUMMARIZATION, SEARCH, DISCORD, INFERENCE, AI_HELPER, TRANSLATION, BOT, SPAM].freeze
1516

1617
SUMMARIZATION_ID = 1
1718
SEARCH_ID = 2
@@ -20,53 +21,60 @@ class Module
2021
AI_HELPER_ID = 5
2122
TRANSLATION_ID = 6
2223
BOT_ID = 7
24+
SPAM_ID = 8
2325

2426
class << self
2527
def all
2628
[
2729
new(
2830
SUMMARIZATION_ID,
2931
SUMMARIZATION,
30-
"ai_summarization_enabled",
32+
enabled_by_setting: "ai_summarization_enabled",
3133
features: DiscourseAi::Configuration::Feature.summarization_features,
3234
),
3335
new(
3436
SEARCH_ID,
3537
SEARCH,
36-
"ai_bot_enabled",
38+
enabled_by_setting: "ai_bot_enabled",
3739
features: DiscourseAi::Configuration::Feature.search_features,
3840
extra_check: -> { SiteSetting.ai_bot_discover_persona.present? },
3941
),
4042
new(
4143
DISCORD_ID,
4244
DISCORD,
43-
"ai_discord_search_enabled",
45+
enabled_by_setting: "ai_discord_search_enabled",
4446
features: DiscourseAi::Configuration::Feature.discord_features,
4547
),
4648
new(
4749
INFERENCE_ID,
4850
INFERENCE,
49-
"inferred_concepts_enabled",
51+
enabled_by_setting: "inferred_concepts_enabled",
5052
features: DiscourseAi::Configuration::Feature.inference_features,
5153
),
5254
new(
5355
AI_HELPER_ID,
5456
AI_HELPER,
55-
"ai_helper_enabled",
57+
enabled_by_setting: "ai_helper_enabled",
5658
features: DiscourseAi::Configuration::Feature.ai_helper_features,
5759
),
5860
new(
5961
TRANSLATION_ID,
6062
TRANSLATION,
61-
"ai_translation_enabled",
63+
enabled_by_setting: "ai_translation_enabled",
6264
features: DiscourseAi::Configuration::Feature.translation_features,
6365
),
6466
new(
6567
BOT_ID,
6668
BOT,
67-
"ai_bot_enabled",
69+
enabled_by_setting: "ai_bot_enabled",
6870
features: DiscourseAi::Configuration::Feature.bot_features,
6971
),
72+
new(
73+
SPAM_ID,
74+
SPAM,
75+
enabled_by_setting: "ai_spam_detection_enabled",
76+
features: DiscourseAi::Configuration::Feature.spam_features,
77+
),
7078
]
7179
end
7280

@@ -75,7 +83,7 @@ def find_by(id:)
7583
end
7684
end
7785

78-
def initialize(id, name, enabled_by_setting, features: [], extra_check: nil)
86+
def initialize(id, name, enabled_by_setting: nil, features: [], extra_check: nil)
7987
@id = id
8088
@name = name
8189
@enabled_by_setting = enabled_by_setting
@@ -86,6 +94,8 @@ def initialize(id, name, enabled_by_setting, features: [], extra_check: nil)
8694
attr_reader :id, :name, :enabled_by_setting, :features
8795

8896
def enabled?
97+
return @extra_check.call if enabled_by_setting.blank? && @extra_check.present?
98+
8999
enabled_setting = SiteSetting.get(enabled_by_setting)
90100

91101
if @extra_check

spec/requests/admin/ai_features_controller_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
get "/admin/plugins/discourse-ai/ai-features.json"
2020

2121
expect(response.status).to eq(200)
22-
expect(response.parsed_body["ai_features"].count).to eq(7)
22+
expect(response.parsed_body["ai_features"].count).to eq(8)
2323
end
2424
end
2525

spec/system/admin_ai_features_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
ai_features_page.toggle_unconfigured
2929

3030
# this changes as we add more AI features
31-
expect(ai_features_page).to have_listed_modules(6)
31+
expect(ai_features_page).to have_listed_modules(7)
3232
end
3333

3434
it "lists the persona used for the corresponding AI feature" do

0 commit comments

Comments
 (0)