mirror of
https://gh.wpcy.net/https://github.com/discourse/discourse.git
synced 2026-05-03 08:18:42 +08:00
- 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
32 lines
619 B
Ruby
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
|