mirror of
https://gh.wpcy.net/https://github.com/discourse/discourse.git
synced 2026-05-04 08:00:01 +08:00
When admins try to enable discourse id via the site setting, the automated registration process happen in the background. In the case of an error, nothing was bubbled up back to the admin other than an unhelpful error message. On top of that, no errors were logged to help tech-savvy admins to figure out what might be the problem(s). This commit ensures that any error that is happening during the registration process will be logged via the standard Rails logs. On top of that, the error message shown to the admin has been updated to hopefully provide a more helpful description. Ref - https://meta.discourse.org/t/388711
32 lines
620 B
Ruby
32 lines
620 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_registration")
|
|
end
|
|
end
|
|
|
|
private
|
|
|
|
def credentials_missing?
|
|
SiteSetting.discourse_id_client_id.blank? || SiteSetting.discourse_id_client_secret.blank?
|
|
end
|
|
end
|