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.
This commit is contained in:
parent
ca78b1a1c5
commit
297c64c3b8
|
@ -56,6 +56,8 @@ en:
|
|||
ai_nsfw_flag_threshold_sexy: "Threshold for an image classified as sexy to be considered NSFW."
|
||||
ai_nsfw_models: "Models to use for NSFW inference."
|
||||
|
||||
ai_spam_detection_enabled: "Enable the AI spam detection module"
|
||||
|
||||
ai_openai_api_key: "API key for OpenAI API. ONLY used for Image creation and edits. For GPT use the LLM config tab"
|
||||
ai_openai_image_generation_url: "URL for OpenAI image generation API"
|
||||
ai_openai_image_edit_url: "URL for OpenAI image edit API"
|
||||
|
@ -275,6 +277,7 @@ en:
|
|||
invalid_error_type: "Invalid error type provided"
|
||||
unexpected: "An unexpected error occured"
|
||||
bot_user_update_failed: "Failed to update the spam scanning bot user"
|
||||
configuration_missing: "The AI spam detection configuration is missing. Add configuration in the 'Admin > Plugins > Discourse AI > Spam' before enabling."
|
||||
|
||||
ai_bot:
|
||||
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]"
|
||||
|
|
|
@ -374,7 +374,7 @@ discourse_ai:
|
|||
|
||||
ai_spam_detection_enabled:
|
||||
default: false
|
||||
hidden: true
|
||||
validator: "DiscourseAi::Configuration::SpamDetectionValidator"
|
||||
ai_spam_detection_user_id:
|
||||
default: ""
|
||||
hidden: true
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module DiscourseAi
|
||||
module Configuration
|
||||
class SpamDetectionValidator
|
||||
def initialize(opts = {})
|
||||
@opts = opts
|
||||
end
|
||||
|
||||
def valid_value?(val)
|
||||
return true if Rails.env.test?
|
||||
return true if AiModerationSetting.spam
|
||||
|
||||
false
|
||||
end
|
||||
|
||||
def error_message
|
||||
I18n.t("discourse_ai.spam_detection.configuration_missing")
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue