discourse/lib/validators/enable_discourse_id_validator.rb
Régis Hanol d2b1ca9f16
FEATURE: log errors when enabling discourse id (#36110)
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
2025-11-25 11:20:32 +01:00

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