FEATURE: Use translated name for 'your email has been authenticated by' (#6649)

FEATURE: Use translated name for ‘your email has been authenticated by’ (#6649)

From f645cb9c1463bc130f428fd4c59de3f8259a140b Mon Sep 17 00:00:00 2001
From: David Taylor <david@taylorhq.com>
Date: Thu, 22 Nov 2018 19:12:04 +0000
Subject: [PATCH] FEATURE: Use translated name for 'your email has been
 authenticated by' (#6649)


diff --git a/app/assets/javascripts/discourse/controllers/create-account.js.es6 b/app/assets/javascripts/discourse/controllers/create-account.js.es6
index fe51b0c..aa1b5e8 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 e36d463..47d7005 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 65bd1af..6185da3 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 bb633f0..4b45e3a 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 ec2d425..88f3005 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"
+  );
+});

GitHub

2 Likes