diff --git a/app/assets/stylesheets/application.scss b/app/assets/stylesheets/application.scss index d97ec39f1..1da88b08a 100644 --- a/app/assets/stylesheets/application.scss +++ b/app/assets/stylesheets/application.scss @@ -43,6 +43,7 @@ @import "budgets/**/*"; @import "comments/**/*"; @import "debates/**/*"; +@import "devise/**/*"; @import "documents/**/*"; @import "layout/**/*"; @import "machine_learning/**/*"; diff --git a/app/assets/stylesheets/devise/omniauth_form.scss b/app/assets/stylesheets/devise/omniauth_form.scss new file mode 100644 index 000000000..8691a3c14 --- /dev/null +++ b/app/assets/stylesheets/devise/omniauth_form.scss @@ -0,0 +1,15 @@ +.devise-omniauth-form { + .oauth-logins { + display: flex; + flex-direction: column; + + @include breakpoint(medium) { + flex-direction: row; + } + + .oauth-login { + @include grid-column-gutter; + flex-grow: 1; + } + } +} diff --git a/app/views/devise/_omniauth_form.html.erb b/app/components/devise/omniauth_form_component.html.erb similarity index 50% rename from app/views/devise/_omniauth_form.html.erb rename to app/components/devise/omniauth_form_component.html.erb index 8cbe25844..45e3097b6 100644 --- a/app/views/devise/_omniauth_form.html.erb +++ b/app/components/devise/omniauth_form_component.html.erb @@ -1,22 +1,22 @@ -<% if oauth_logins.any? %> -
-
-
- <%= t("omniauth.info.#{action}") %> -
+
+
+
+ <%= t("omniauth.info.#{action}") %>
+
+
<% oauth_logins.each do |login| %> -
+ <% end %> - -
- <%= t("omniauth.or_fill") %> -
-<% end %> + +
+ <%= t("omniauth.or_fill") %> +
+
diff --git a/app/components/devise/omniauth_form_component.rb b/app/components/devise/omniauth_form_component.rb new file mode 100644 index 000000000..fbde17268 --- /dev/null +++ b/app/components/devise/omniauth_form_component.rb @@ -0,0 +1,22 @@ +class Devise::OmniauthFormComponent < ApplicationComponent + attr_reader :action + + def initialize(action) + @action = action + end + + def render? + oauth_logins.any? + end + + private + + def oauth_logins + [ + (:twitter if feature?(:twitter_login)), + (:facebook if feature?(:facebook_login)), + (:google_oauth2 if feature?(:google_login)), + (:wordpress_oauth2 if feature?(:wordpress_login)) + ].compact + end +end diff --git a/app/helpers/settings_helper.rb b/app/helpers/settings_helper.rb index b5ac46af9..dc293a72d 100644 --- a/app/helpers/settings_helper.rb +++ b/app/helpers/settings_helper.rb @@ -1,13 +1,4 @@ module SettingsHelper - def oauth_logins - [ - (:twitter if feature?(:twitter_login)), - (:facebook if feature?(:facebook_login)), - (:google_oauth2 if feature?(:google_login)), - (:wordpress_oauth2 if feature?(:wordpress_login)) - ].compact - end - def feature?(name) setting["feature.#{name}"].presence || setting["process.#{name}"].presence || setting[name].presence end diff --git a/app/views/devise/sessions/new.html.erb b/app/views/devise/sessions/new.html.erb index bad3ce637..544d6c299 100644 --- a/app/views/devise/sessions/new.html.erb +++ b/app/views/devise/sessions/new.html.erb @@ -1,7 +1,7 @@ <% provide :title, t("devise_views.sessions.new.title") %>

<%= t("devise_views.sessions.new.title") %>

-<%= render "devise/omniauth_form", action: "sign_in" %> +<%= render Devise::OmniauthFormComponent.new("sign_in") %>

<%= sanitize(t("devise_views.shared.links.signup", diff --git a/app/views/users/registrations/new.html.erb b/app/views/users/registrations/new.html.erb index 1382b385d..145f33e3e 100644 --- a/app/views/users/registrations/new.html.erb +++ b/app/views/users/registrations/new.html.erb @@ -1,7 +1,7 @@ <% provide :title, t("devise_views.users.registrations.new.title") %>

<%= t("devise_views.users.registrations.new.title") %>

-<%= render "devise/omniauth_form", action: "sign_up" %> +<%= render Devise::OmniauthFormComponent.new("sign_up") %> <%= form_for(resource, as: resource_name, url: registration_path(resource_name)) do |f| %> <%= render "shared/errors", resource: resource %> diff --git a/spec/components/devise/omniauth_form_component_spec.rb b/spec/components/devise/omniauth_form_component_spec.rb new file mode 100644 index 000000000..9c9a6f814 --- /dev/null +++ b/spec/components/devise/omniauth_form_component_spec.rb @@ -0,0 +1,56 @@ +require "rails_helper" + +describe Devise::OmniauthFormComponent do + describe "#oauth_logins" do + let(:component) { Devise::OmniauthFormComponent.new("sign_up") } + + before do + Setting["feature.facebook_login"] = false + Setting["feature.twitter_login"] = false + Setting["feature.google_login"] = false + Setting["feature.wordpress_login"] = false + end + + it "is not rendered when all authentications are disabled" do + render_inline component + + expect(page).not_to be_rendered + end + + it "renders the twitter link when the feature is enabled" do + Setting["feature.twitter_login"] = true + + render_inline component + + expect(page).to have_link "Twitter" + expect(page).to have_link count: 1 + end + + it "renders the facebook link when the feature is enabled" do + Setting["feature.facebook_login"] = true + + render_inline component + + expect(page).to have_link "Facebook" + expect(page).to have_link count: 1 + end + + it "renders the google link when the feature is enabled" do + Setting["feature.google_login"] = true + + render_inline component + + expect(page).to have_link "Google" + expect(page).to have_link count: 1 + end + + it "renders the wordpress link when the feature is enabled" do + Setting["feature.wordpress_login"] = true + + render_inline component + + expect(page).to have_link "Wordpress" + expect(page).to have_link count: 1 + end + end +end diff --git a/spec/system/users_auth_spec.rb b/spec/system/users_auth_spec.rb index 60f3c8877..936b035cd 100644 --- a/spec/system/users_auth_spec.rb +++ b/spec/system/users_auth_spec.rb @@ -127,103 +127,6 @@ describe "Users" do end context "OAuth authentication" do - context "Form buttons" do - before do - Setting["feature.facebook_login"] = false - Setting["feature.twitter_login"] = false - Setting["feature.google_login"] = false - Setting["feature.wordpress_login"] = false - end - - scenario "No button will appear if all features are disabled" do - visit new_user_registration_path - - expect(page).not_to have_link "Twitter" - expect(page).not_to have_link "Facebook" - expect(page).not_to have_link "Google" - expect(page).not_to have_link "Wordpress" - - visit new_user_session_path - - expect(page).not_to have_link "Twitter" - expect(page).not_to have_link "Facebook" - expect(page).not_to have_link "Google" - expect(page).not_to have_link "Wordpress" - end - - scenario "Twitter login button will appear if feature is enabled" do - Setting["feature.twitter_login"] = true - - visit new_user_registration_path - - expect(page).to have_link "Twitter" - expect(page).not_to have_link "Facebook" - expect(page).not_to have_link "Google" - expect(page).not_to have_link "Wordpress" - - visit new_user_session_path - - expect(page).to have_link "Twitter" - expect(page).not_to have_link "Facebook" - expect(page).not_to have_link "Google" - expect(page).not_to have_link "Wordpress" - end - - scenario "Facebook login button will appear if feature is enabled" do - Setting["feature.facebook_login"] = true - - visit new_user_registration_path - - expect(page).not_to have_link "Twitter" - expect(page).to have_link "Facebook" - expect(page).not_to have_link "Google" - expect(page).not_to have_link "Wordpress" - - visit new_user_session_path - - expect(page).not_to have_link "Twitter" - expect(page).to have_link "Facebook" - expect(page).not_to have_link "Google" - expect(page).not_to have_link "Wordpress" - end - - scenario "Google login button will appear if feature is enabled" do - Setting["feature.google_login"] = true - - visit new_user_registration_path - - expect(page).not_to have_link "Twitter" - expect(page).not_to have_link "Facebook" - expect(page).to have_link "Google" - expect(page).not_to have_link "Wordpress" - - visit new_user_session_path - - expect(page).not_to have_link "Twitter" - expect(page).not_to have_link "Facebook" - expect(page).to have_link "Google" - expect(page).not_to have_link "Wordpress" - end - - scenario "Wordpress login button will appear if feature is enabled" do - Setting["feature.wordpress_login"] = true - - visit new_user_registration_path - - expect(page).not_to have_link "Twitter" - expect(page).not_to have_link "Facebook" - expect(page).not_to have_link "Google" - expect(page).to have_link "Wordpress" - - visit new_user_session_path - - expect(page).not_to have_link "Twitter" - expect(page).not_to have_link "Facebook" - expect(page).not_to have_link "Google" - expect(page).to have_link "Wordpress" - end - end - context "Twitter" do let(:twitter_hash) { { uid: "12345", info: { name: "manuela" }} } let(:twitter_hash_with_email) do