From 9b634f349388cf51d580bab96feaf02313156295 Mon Sep 17 00:00:00 2001 From: Tom Hughes Date: Wed, 15 Apr 2020 22:48:28 +0100 Subject: [PATCH] Cache OpenID provider names on a per-locale basis Fixes #2591 --- app/views/users/account.html.erb | 2 +- app/views/users/new.html.erb | 2 +- lib/auth.rb | 24 ++++++++++++++---------- 3 files changed, 16 insertions(+), 12 deletions(-) diff --git a/app/views/users/account.html.erb b/app/views/users/account.html.erb index fadb74f4c..51c933b5d 100644 --- a/app/views/users/account.html.erb +++ b/app/views/users/account.html.erb @@ -48,7 +48,7 @@
- <%= f.select :auth_provider, Auth::PROVIDERS %> + <%= f.select :auth_provider, Auth.providers %> <%= f.text_field :auth_uid %> (" target="_new"><%= t ".openid.link text" %>)
diff --git a/app/views/users/new.html.erb b/app/views/users/new.html.erb index ba0987c33..6f97a284a 100644 --- a/app/views/users/new.html.erb +++ b/app/views/users/new.html.erb @@ -52,7 +52,7 @@ - <%= f.select(:auth_provider, Auth::PROVIDERS, :default => "", :tabindex => 4) %> + <%= f.select(:auth_provider, Auth.providers, :default => "", :tabindex => 4) %> <%= f.text_field(:auth_uid, :tabindex => 5) %> <%= f.error_message_on(:auth_uid) %> diff --git a/lib/auth.rb b/lib/auth.rb index ff9a22663..bc1ee8ec6 100644 --- a/lib/auth.rb +++ b/lib/auth.rb @@ -1,12 +1,16 @@ module Auth - PROVIDERS = { - I18n.t("auth.providers.none") => "", - I18n.t("auth.providers.openid") => "openid" - }.tap do |providers| - providers[I18n.t("auth.providers.google")] = "google" if Settings.key?(:google_auth_id) - providers[I18n.t("auth.providers.facebook")] = "facebook" if Settings.key?(:facebook_auth_id) - providers[I18n.t("auth.providers.windowslive")] = "windowslive" if Settings.key?(:windowslive_auth_id) - providers[I18n.t("auth.providers.github")] = "github" if Settings.key?(:github_auth_id) - providers[I18n.t("auth.providers.wikipedia")] = "wikipedia" if Settings.key?(:wikipedia_auth_id) - end.freeze + @providers = {} + + def self.providers + @providers[I18n.locale] ||= { + I18n.t("auth.providers.none") => "", + I18n.t("auth.providers.openid") => "openid" + }.tap do |providers| + providers[I18n.t("auth.providers.google")] = "google" if Settings.key?(:google_auth_id) + providers[I18n.t("auth.providers.facebook")] = "facebook" if Settings.key?(:facebook_auth_id) + providers[I18n.t("auth.providers.windowslive")] = "windowslive" if Settings.key?(:windowslive_auth_id) + providers[I18n.t("auth.providers.github")] = "github" if Settings.key?(:github_auth_id) + providers[I18n.t("auth.providers.wikipedia")] = "wikipedia" if Settings.key?(:wikipedia_auth_id) + end.freeze + end end -- 2.39.5