From f645cb9c1463bc130f428fd4c59de3f8259a140b Mon Sep 17 00:00:00 2001 From: David Taylor Date: Thu, 22 Nov 2018 19:12:04 +0000 Subject: [PATCH] FEATURE: Use translated name for 'your email has been authenticated by' (#6649) --- .../discourse/controllers/create-account.js.es6 | 14 +++++++------- lib/auth/result.rb | 3 +-- .../omniauth_callbacks_controller_spec.rb | 2 +- .../omniauth_callbacks/complete.html.erb_spec.rb | 4 +--- .../controllers/create-account-test.js.es6 | 15 +++++++++++++++ 5 files changed, 25 insertions(+), 13 deletions(-) diff --git a/app/assets/javascripts/discourse/controllers/create-account.js.es6 b/app/assets/javascripts/discourse/controllers/create-account.js.es6 index fe51b0ca486..aa1b5e8ca0e 100644 --- a/app/assets/javascripts/discourse/controllers/create-account.js.es6 +++ b/app/assets/javascripts/discourse/controllers/create-account.js.es6 @@ -147,13 +147,13 @@ export default Ember.Controller.extend( ); }.property("accountEmail", "authOptions.email", "authOptions.email_valid"), - authProviderDisplayName(provider) { - switch (provider) { - case "Google_oauth2": - return "Google"; - default: - return provider; - } + authProviderDisplayName(providerName) { + const matchingProvider = findAll().find(provider => { + return provider.name === providerName; + }); + return matchingProvider + ? matchingProvider.get("prettyName") + : providerName; }, prefillUsername: function() { diff --git a/lib/auth/result.rb b/lib/auth/result.rb index e36d4638bd5..47d7005c224 100644 --- a/lib/auth/result.rb +++ b/lib/auth/result.rb @@ -64,8 +64,7 @@ class Auth::Result else result = { email: email, username: UserNameSuggester.suggest(username || name || email), - # this feels a tad wrong - auth_provider: authenticator_name.capitalize, + auth_provider: authenticator_name, email_valid: !!email_valid, omit_username: !!omit_username } diff --git a/spec/requests/omniauth_callbacks_controller_spec.rb b/spec/requests/omniauth_callbacks_controller_spec.rb index 65bd1afa07f..6185da3eb1a 100644 --- a/spec/requests/omniauth_callbacks_controller_spec.rb +++ b/spec/requests/omniauth_callbacks_controller_spec.rb @@ -125,7 +125,7 @@ RSpec.describe Users::OmniauthCallbacksController do expect(response_body["email"]).to eq(email) expect(response_body["username"]).to eq("Some_name") - expect(response_body["auth_provider"]).to eq("Google_oauth2") + expect(response_body["auth_provider"]).to eq("google_oauth2") expect(response_body["email_valid"]).to eq(true) expect(response_body["omit_username"]).to eq(false) expect(response_body["name"]).to eq("Some Name") diff --git a/spec/views/omniauth_callbacks/complete.html.erb_spec.rb b/spec/views/omniauth_callbacks/complete.html.erb_spec.rb index bb633f0c29d..4b45e3a5fab 100644 --- a/spec/views/omniauth_callbacks/complete.html.erb_spec.rb +++ b/spec/views/omniauth_callbacks/complete.html.erb_spec.rb @@ -33,9 +33,7 @@ describe "users/omniauth_callbacks/complete.html.erb" do render expect(rendered_data["email"]).to eq(result.email) - # TODO this is a bit weird, the upcasing is confusing, - # clean it up throughout - expect(rendered_data["auth_provider"]).to eq("Cas") + expect(rendered_data["auth_provider"]).to eq("CAS") end end diff --git a/test/javascripts/controllers/create-account-test.js.es6 b/test/javascripts/controllers/create-account-test.js.es6 index ec2d4250842..88f3005fb20 100644 --- a/test/javascripts/controllers/create-account-test.js.es6 +++ b/test/javascripts/controllers/create-account-test.js.es6 @@ -84,3 +84,18 @@ QUnit.test("passwordValidation", function(assert) { testInvalidPassword("porkchops", I18n.t("user.password.same_as_username")); testInvalidPassword("pork@chops.com", I18n.t("user.password.same_as_email")); }); + +QUnit.test("authProviderDisplayName", function(assert) { + const controller = this.subject({ siteSettings: Discourse.SiteSettings }); + + assert.equal( + controller.authProviderDisplayName("facebook"), + I18n.t("login.facebook.name"), + "provider name is translated correctly" + ); + assert.equal( + controller.authProviderDisplayName("idontexist"), + "idontexist", + "provider name falls back if not found" + ); +});