diff --git a/app/views/users/_account.html.erb b/app/views/users/_account.html.erb index a6710b7d1..58559953e 100644 --- a/app/views/users/_account.html.erb +++ b/app/views/users/_account.html.erb @@ -58,6 +58,11 @@ <% end %> <% end %> + <% elsif @user.identities.enabled.size == 1 %> +
+

<%= t("views.settings.account.remove.heading") %>

+

<%= t("views.settings.account.remove.unable_to_remove") %>

+
<% end %>
diff --git a/config/locales/views/settings/en.yml b/config/locales/views/settings/en.yml index f5d374682..f211e4da5 100644 --- a/config/locales/views/settings/en.yml +++ b/config/locales/views/settings/en.yml @@ -39,6 +39,7 @@ en: you will have to do so in your settings for the specific provider: confirm: Are you absolutely sure you want to remove your %{provider} account? submit: Remove %{provider} + unable_to_remove: You are unable to remove one of your authentication methods as you need a remaining method to authenticate you. Please add another authentication method above before continuing. billing: heading: Billing add: Add Credit Card diff --git a/config/locales/views/settings/fr.yml b/config/locales/views/settings/fr.yml index 3b8098fdd..0de5a3499 100644 --- a/config/locales/views/settings/fr.yml +++ b/config/locales/views/settings/fr.yml @@ -39,6 +39,7 @@ fr: you will have to do so in your settings for the specific provider: confirm: Are you absolutely sure you want to remove your %{provider} account? submit: Remove %{provider} + unable_to_remove: Vous ne pouvez pas supprimer l'une de vos méthodes d'authentification car vous avez besoin d'une méthode restante pour vous authentifier. Veuillez ajouter une autre méthode d'authentification ci-dessus avant de continuer. billing: heading: Billing add: Add Credit Card diff --git a/spec/requests/user/user_settings_spec.rb b/spec/requests/user/user_settings_spec.rb index d2a70d7c5..ba12274e6 100644 --- a/spec/requests/user/user_settings_spec.rb +++ b/spec/requests/user/user_settings_spec.rb @@ -110,6 +110,8 @@ RSpec.describe "UserSettings" do describe ":account" do let(:remove_oauth_section) { "Remove OAuth Associations" } + let(:remove_oauth_description) { "You can remove one of your authentication methods" } + let(:remove_oauth_instructions) { "Please add another authentication method" } let(:user) { create(:user, :with_identity) } before do @@ -122,28 +124,38 @@ RSpec.describe "UserSettings" do expect(response).to have_http_status(:ok) end - it "shows the 'Remove OAuth' section if a user has multiple enabled identities" do + it "shows the description if a user has multiple enabled identities" do allow(Authentication::Providers).to receive(:enabled).and_return(Authentication::Providers.available) providers = Authentication::Providers.available.first(2) allow(user).to receive(:identities).and_return(user.identities.where(provider: providers)) get user_settings_path(tab: "account") - expect(response.body).to include(remove_oauth_section) + expect(response.body).to include(remove_oauth_description) + expect(response.body).not_to include(remove_oauth_instructions) end - it "hides the 'Remove OAuth' section if a user has one enabled identity" do + it "shows instructions how to remove an identity if a user has one enabled identity" do provider = Authentication::Providers.available.first allow(Authentication::Providers).to receive(:enabled).and_return([provider]) allow(user).to receive(:identities).and_return(user.identities.where(provider: provider)) get user_settings_path(tab: "account") - expect(response.body).not_to include(remove_oauth_section) + expect(response.body).not_to include(remove_oauth_description) + expect(response.body).to include(remove_oauth_instructions) end - it "hides the 'Remove OAuth' section if a user has one enabled identity and one disabled" do + it "shows instructions how to remove an identity if a user has one enabled identity and one disabled" do provider = Authentication::Providers.available.first allow(Authentication::Providers).to receive(:enabled).and_return([provider]) + get user_settings_path(tab: "account") + expect(response.body).not_to include(remove_oauth_description) + expect(response.body).to include(remove_oauth_instructions) + end + + it "hides the 'Remove OAuth' section if a user has no enabled identity" do + allow(Authentication::Providers).to receive(:enabled).and_return([]) + get user_settings_path(tab: "account") expect(response.body).not_to include(remove_oauth_section) end