discourse-ai/lib/configuration/spam_detection_validator.rb
Keegan George 33fd6801e5
DEV: Add back validator for Spam setting (#1415)
## 🔍 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.
2025-06-06 10:56:36 -07:00

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