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

Commit 297c64c

Browse files
authored
DEV: Unhide spam detection setting (#1374)
## 🔍 Overview We want to unhide `ai_spam_detection_enabled` setting so that we can retain staff action log features. However, we also want to ensure users cannot enable spam detection without having `AiModerationSetting.spam` present in the database. In this update we unhide the setting, but also add a validator to ensure the necessary configuration is in place before allowing the setting to be enabled.
1 parent ca78b1a commit 297c64c

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

config/locales/server.en.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ en:
5656
ai_nsfw_flag_threshold_sexy: "Threshold for an image classified as sexy to be considered NSFW."
5757
ai_nsfw_models: "Models to use for NSFW inference."
5858

59+
ai_spam_detection_enabled: "Enable the AI spam detection module"
60+
5961
ai_openai_api_key: "API key for OpenAI API. ONLY used for Image creation and edits. For GPT use the LLM config tab"
6062
ai_openai_image_generation_url: "URL for OpenAI image generation API"
6163
ai_openai_image_edit_url: "URL for OpenAI image edit API"
@@ -275,6 +277,7 @@ en:
275277
invalid_error_type: "Invalid error type provided"
276278
unexpected: "An unexpected error occured"
277279
bot_user_update_failed: "Failed to update the spam scanning bot user"
280+
configuration_missing: "The AI spam detection configuration is missing. Add configuration in the 'Admin > Plugins > Discourse AI > Spam' before enabling."
278281

279282
ai_bot:
280283
reply_error: "Sorry, it looks like our system encountered an unexpected issue while trying to reply.\n\n[details='Error details']\n%{details}\n[/details]"

config/settings.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ discourse_ai:
374374

375375
ai_spam_detection_enabled:
376376
default: false
377-
hidden: true
377+
validator: "DiscourseAi::Configuration::SpamDetectionValidator"
378378
ai_spam_detection_user_id:
379379
default: ""
380380
hidden: true
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# frozen_string_literal: true
2+
3+
module DiscourseAi
4+
module Configuration
5+
class SpamDetectionValidator
6+
def initialize(opts = {})
7+
@opts = opts
8+
end
9+
10+
def valid_value?(val)
11+
return true if Rails.env.test?
12+
return true if AiModerationSetting.spam
13+
14+
false
15+
end
16+
17+
def error_message
18+
I18n.t("discourse_ai.spam_detection.configuration_missing")
19+
end
20+
end
21+
end
22+
end

0 commit comments

Comments
 (0)