secure Identity#email in case of missing auth_data_dump hash (#11936) (#12322)

* secure Identity#email in case of missing auth_data_dump hash (#11936)

* Refactor Identity#email

* Delete wrongly commited debugging line

* extract no email found message into Const

* refactor Identity#email to use || as flow control
This commit is contained in:
le-hu 2021-01-19 01:27:07 +01:00 committed by GitHub
parent 425c3072f7
commit 619dd813c7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,4 +1,7 @@
class Identity < ApplicationRecord
NO_EMAIL_MSG = "No email found. Please relink your %<provider>s " \
"account to avoid errors.".freeze
belongs_to :user
scope :enabled, -> { where(provider: Authentication::Providers.enabled) }
@ -39,6 +42,6 @@ class Identity < ApplicationRecord
end
def email
auth_data_dump.info.email
auth_data_dump&.info&.email || format(NO_EMAIL_MSG, provider: provider)
end
end