discourse/lib/validators/enable_discourse_id_validator.rb
Régis Hanol 5a414c7b49
FEATURE: open the discourse-id gates (#34949)
- Unhide the "enable_discourse_id" site setting so admins can toggle it
via the site settings admin pages rather than using the CLI.
- Update the "EnableDiscourseIdValidator" to automatically register when
enabling the site setting
- Update the "EnableDiscourseIdValidator" to display the appropriate
error message the registration fails
- Update the "DiscourseId::Register" service to not automatically enable
"enable_discourse_id" site setting to avoid infinite loops
- Removes the now redundant "admin:register_discourse_id" rake task

Internal ref - t/161934

Replaces #34899
2025-09-24 16:59:07 +02:00

32 lines
619 B
Ruby

# frozen_string_literal: true
class EnableDiscourseIdValidator
def initialize(opts = {})
@opts = opts
end
def valid_value?(val)
return true if val == "f"
if credentials_missing?
@result = DiscourseId::Register.call
return @result.success?
end
true
end
def error_message
if @result&.error.present?
@result.error
elsif credentials_missing?
I18n.t("site_settings.errors.discourse_id_credentials")
end
end
private
def credentials_missing?
SiteSetting.discourse_id_client_id.blank? || SiteSetting.discourse_id_client_secret.blank?
end
end