From 619dd813c7a61294715636bf1a53a87e326ac1f7 Mon Sep 17 00:00:00 2001 From: le-hu Date: Tue, 19 Jan 2021 01:27:07 +0100 Subject: [PATCH] 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 --- app/models/identity.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/models/identity.rb b/app/models/identity.rb index 80b6a45ef..a68133286 100644 --- a/app/models/identity.rb +++ b/app/models/identity.rb @@ -1,4 +1,7 @@ class Identity < ApplicationRecord + NO_EMAIL_MSG = "No email found. Please relink your %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