From 5e61893cb27cd8d1dfa69584df2c1c31127304fa Mon Sep 17 00:00:00 2001 From: David Taylor Date: Mon, 3 Jun 2019 12:14:02 +0100 Subject: [PATCH] FIX: Display generic descriptor for associated account with no info --- config/locales/server.en.yml | 1 + lib/auth/managed_authenticator.rb | 2 +- spec/components/auth/managed_authenticator_spec.rb | 2 ++ 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml index 3730c55553d..ae126b9e7ec 100644 --- a/config/locales/server.en.yml +++ b/config/locales/server.en.yml @@ -786,6 +786,7 @@ en: associated_accounts: revoke_failed: "Failed to revoke your account with %{provider_name}." + connected: "(connected)" activation: action: "Click here to activate your account" diff --git a/lib/auth/managed_authenticator.rb b/lib/auth/managed_authenticator.rb index b47e7e17d66..bdc7f0951c9 100644 --- a/lib/auth/managed_authenticator.rb +++ b/lib/auth/managed_authenticator.rb @@ -4,7 +4,7 @@ class Auth::ManagedAuthenticator < Auth::Authenticator def description_for_user(user) info = UserAssociatedAccount.find_by(provider_name: name, user_id: user.id)&.info return "" if info.nil? - info["email"] || info["nickname"] || info["name"] || "" + info["email"] || info["nickname"] || info["name"] || I18n.t("associated_accounts.connected") end # These three methods are designed to be overriden by child classes diff --git a/spec/components/auth/managed_authenticator_spec.rb b/spec/components/auth/managed_authenticator_spec.rb index ea788144a65..ba463ed44e4 100644 --- a/spec/components/auth/managed_authenticator_spec.rb +++ b/spec/components/auth/managed_authenticator_spec.rb @@ -261,6 +261,8 @@ describe Auth::ManagedAuthenticator do expect(authenticator.description_for_user(user)).to eq('somenickname') association.update(info: { nickname: "bestname" }) expect(authenticator.description_for_user(user)).to eq('bestname') + association.update(info: {}) + expect(authenticator.description_for_user(user)).to eq(I18n.t("associated_accounts.connected")) end end