A platform for community discussion. Free, open, simple.
DEV: Add capability to pass an icon setting into auth provider registration (#34584)
Chris Alberti1f227a5eb4ef
diff --git a/app/assets/javascripts/discourse/app/models/login-method.js b/app/assets/javascripts/discourse/app/models/login-method.jsindex 0e2c6c0769c..75da429d503 100644--- a/app/assets/javascripts/discourse/app/models/login-method.js+++ b/app/assets/javascripts/discourse/app/models/login-method.js@@ -41,6 +41,11 @@ export default class LoginMethod extends EmberObject {return this.title_override || i18n(`login.${this.name}.title`);}+ @discourseComputed+ icon() {+ return this.icon_override || "user";+ }+@discourseComputedscreenReaderTitle() {return (diff --git a/app/serializers/auth_provider_serializer.rb b/app/serializers/auth_provider_serializer.rbindex 11e2d4819db..6026408d8f0 100644--- a/app/serializers/auth_provider_serializer.rb+++ b/app/serializers/auth_provider_serializer.rb@@ -6,7 +6,7 @@ class AuthProviderSerializer < ApplicationSerializer:custom_url,:frame_height,:frame_width,- :icon,+ :icon_override,:name,:pretty_name_override,:provider_url,@@ -24,4 +24,8 @@ class AuthProviderSerializer < ApplicationSerializerdef title_overrideobject.title_setting ? SiteSetting.get(object.title_setting) : object.titleend++ def icon_override+ object.icon_setting ? SiteSetting.get(object.icon_setting) : object.icon+ endenddiff --git a/lib/auth/auth_provider.rb b/lib/auth/auth_provider.rbindex e44a3e6f8c5..a9573cd5fc9 100644--- a/lib/auth/auth_provider.rb+++ b/lib/auth/auth_provider.rb@@ -14,6 +14,7 @@ class Auth::AuthProviderframe_heightframe_widthicon+ icon_settingpretty_namepretty_name_settingtitlediff --git a/spec/serializers/auth_provider_serializer_spec.rb b/spec/serializers/auth_provider_serializer_spec.rbnew file mode 100644index 00000000000..a3ca417e002--- /dev/null+++ b/spec/serializers/auth_provider_serializer_spec.rb@@ -0,0 +1,69 @@+# frozen_string_literal: true++RSpec.describe AuthProviderSerializer do+ fab!(:user)++ before do+ allow(SiteSetting).to receive(:get).and_call_original+ allow(SiteSetting).to receive(:get).with(:test_icon).and_return("bullseye")+ allow(SiteSetting).to receive(:get).with(:test_pretty_name).and_return("new pretty name")+ allow(SiteSetting).to receive(:get).with(:test_title).and_return("new_title")+ end++ let(:authenticator) do+ Class+ .new(Auth::ManagedAuthenticator) do+ def name+ "test_auth"+ end++ def enabled?+ true+ end+ end+ .new+ end++ let(:serializer) do+ AuthProviderSerializer.new(auth_provider, scope: Guardian.new(user), root: false)+ end++ context "without overridden attributes" do+ let(:auth_provider) do+ Auth::AuthProvider.new(+ authenticator:,+ icon: "flash",+ pretty_name: "old pretty name",+ title: "old_title",+ )+ end++ it "returns the original values" do+ json = serializer.as_json+ expect(json[:pretty_name_override]).to eq("old pretty name")+ expect(json[:title_override]).to eq("old_title")+ expect(json[:icon_override]).to eq("flash")+ end+ end++ context "with overridden attributes" do+ let(:auth_provider) do+ Auth::AuthProvider.new(+ authenticator:,+ icon: "flash",+ icon_setting: :test_icon,+ pretty_name: "old pretty name",+ pretty_name_setting: :test_pretty_name,+ title: "old_title",+ title_setting: :test_title,+ )+ end++ it "returns the overridden values" do+ json = serializer.as_json+ expect(json[:pretty_name_override]).to eq("new pretty name")+ expect(json[:title_override]).to eq("new_title")+ expect(json[:icon_override]).to eq("bullseye")+ end+ end+enddiff --git a/spec/system/user_page/user_preferences_account_spec.rb b/spec/system/user_page/user_preferences_account_spec.rbindex 1130354146b..5485028c693 100644--- a/spec/system/user_page/user_preferences_account_spec.rb+++ b/spec/system/user_page/user_preferences_account_spec.rb@@ -44,6 +44,57 @@ describe "User preferences | Account", type: :system doendend+ describe "overridden provider attributes" do+ before do+ authenticator =+ Class+ .new(Auth::ManagedAuthenticator) do+ def name+ "test_auth"+ end++ def enabled?+ true+ end+ end+ .new++ provider =+ Auth::AuthProvider.new(+ authenticator:,+ icon: "flash",+ icon_setting: :test_icon,+ pretty_name: "old pretty name",+ pretty_name_setting: :test_pretty_name,+ title: "old_title",+ title_setting: :test_title,+ )+ DiscoursePluginRegistry.register_auth_provider(provider)++ allow(SiteSetting).to receive(:get).and_call_original+ allow(SiteSetting).to receive(:get).with(:test_icon).and_return("bullseye")+ allow(SiteSetting).to receive(:get).with(:test_pretty_name).and_return("new pretty name")+ allow(SiteSetting).to receive(:get).with(:test_title).and_return("new_title")+ end++ after { DiscoursePluginRegistry.reset! }++ it "displays the correct name when overridden" do+ user_account_preferences_page.visit(user)+ name = find(".pref-associated-accounts table tr.test-auth .associated-account__name")+ expect(name).not_to have_text("old pretty name")+ expect(name).to have_text("new pretty name")+ end++ it "displays the correct icon when overridden" do+ user_account_preferences_page.visit(user)+ icon_classes =+ find(".pref-associated-accounts table tr.test-auth .associated-account__icon svg")[:class]+ expect(icon_classes).not_to have_content("d-icon-flash")+ expect(icon_classes).to have_content("d-icon-bullseye")+ end+ end+describe "external login provider URLs" doit "shows provider URLs as links when available" doSiteSetting.enable_discord_logins = true