mirror of
https://github.com/discourse/discourse-ai.git
synced 2025-06-30 11:32:18 +00:00
## 🔍 Overview This update re-introduces the validator used on the `ai_spam_detection_enabled` setting. It was initially added here: https://github.com/discourse/discourse-ai/pull/1374 to prevent Spam from being enabled without creating an `AiModerationSetting` value in the database. However, due to issues with backups/migrations we temporarily removed it here: https://github.com/discourse/discourse-ai/pull/1393. Now with some internal fixes, we can re-introduce it. We also update the validator so that it only validates when trying to turn on rather than when turning off too.
24 lines
497 B
Ruby
24 lines
497 B
Ruby
# frozen_string_literal: true
|
|
|
|
module DiscourseAi
|
|
module Configuration
|
|
class SpamDetectionValidator
|
|
def initialize(opts = {})
|
|
@opts = opts
|
|
end
|
|
|
|
def valid_value?(val)
|
|
# only validate when enabling spam detection
|
|
return true if val == "f" || val == "false"
|
|
return true if AiModerationSetting.spam
|
|
|
|
false
|
|
end
|
|
|
|
def error_message
|
|
I18n.t("discourse_ai.spam_detection.configuration_missing")
|
|
end
|
|
end
|
|
end
|
|
end
|