mirror of
https://github.com/discourse/discourse-ai.git
synced 2025-07-08 23:32:45 +00:00
## 🔍 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.
23 lines
431 B
Ruby
23 lines
431 B
Ruby
# 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
|