From 168575d606972ccf66962aaebf8b55078d10d5fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Fri, 18 Feb 2022 16:59:38 +0100 Subject: [PATCH] Remove "not allowed" when supporting comments Hovering over the votes showed a "participation not allowed" message which was annoying when scrolling with the browser or simply moving the mouse around the page. Furthermore, it hid the information about the number of votes, links to show/collapse replies, ... We're planning to change the behavior of all the "participation not allowed" messages in order to show them on click instead of showing them on hover (just like it's done on touchscreens). In the case of comments, supports, however, there's very limited space in the part showing the number of supports for comments, so adding this message without breaking the layout is challenging. So, for now, we're simply redirecting unauthenticated users to the login page. If find an easy way to implement a better user interface in the future to display the "participation not allowed" message, we might change this behaviour. --- app/assets/stylesheets/participation.scss | 6 ------ .../comments/votes_component.html.erb | 18 ++++-------------- app/components/comments/votes_component.rb | 2 +- app/controllers/comments_controller.rb | 2 +- config/locales/en/general.yml | 1 - config/locales/es/general.yml | 1 - spec/support/common_actions/votes.rb | 6 ------ spec/system/votes_spec.rb | 12 ++++++++---- 8 files changed, 14 insertions(+), 34 deletions(-) diff --git a/app/assets/stylesheets/participation.scss b/app/assets/stylesheets/participation.scss index e31c0b34d..ecc13411d 100644 --- a/app/assets/stylesheets/participation.scss +++ b/app/assets/stylesheets/participation.scss @@ -126,12 +126,6 @@ } } -.reply .participation-not-allowed { - padding-right: $line-height / 2; - padding-top: $line-height / 6; - text-align: right; -} - // 02. New participation // --------------------- diff --git a/app/components/comments/votes_component.html.erb b/app/components/comments/votes_component.html.erb index 61f6b2cb0..b765af80f 100644 --- a/app/components/comments/votes_component.html.erb +++ b/app/components/comments/votes_component.html.erb @@ -5,9 +5,8 @@ <%= button_to vote_comment_path(comment, value: "yes"), method: "post", - remote: true, - title: t("votes.agree"), - disabled: !can?(:vote, comment) do %> + remote: can?(:vote, comment), + title: t("votes.agree") do %> <%= t("votes.agree") %> <% end %> <%= comment.total_likes %> @@ -16,19 +15,10 @@ <%= button_to vote_comment_path(comment, value: "no"), method: "post", - remote: true, - title: t("votes.disagree"), - disabled: !can?(:vote, comment) do %> + remote: can?(:vote, comment), + title: t("votes.disagree") do %> <%= t("votes.disagree") %> <% end %> <%= comment.total_dislikes %> - - <% unless current_user %> -
- -
- <% end %> diff --git a/app/components/comments/votes_component.rb b/app/components/comments/votes_component.rb index d776aaaba..d93a24b0f 100644 --- a/app/components/comments/votes_component.rb +++ b/app/components/comments/votes_component.rb @@ -1,6 +1,6 @@ class Comments::VotesComponent < ApplicationComponent attr_reader :comment - delegate :current_user, :can?, :link_to_signin, :link_to_signup, to: :helpers + delegate :can?, to: :helpers def initialize(comment) @comment = comment diff --git a/app/controllers/comments_controller.rb b/app/controllers/comments_controller.rb index 1f918b299..7778b495d 100644 --- a/app/controllers/comments_controller.rb +++ b/app/controllers/comments_controller.rb @@ -1,5 +1,5 @@ class CommentsController < ApplicationController - before_action :authenticate_user!, only: [:create, :hide] + before_action :authenticate_user!, only: [:create, :hide, :vote] before_action :load_commentable, only: :create before_action :verify_resident_for_commentable!, only: :create before_action :verify_comments_open!, only: [:create, :vote] diff --git a/config/locales/en/general.yml b/config/locales/en/general.yml index 743800aea..eebed8c93 100644 --- a/config/locales/en/general.yml +++ b/config/locales/en/general.yml @@ -849,7 +849,6 @@ en: agree: I agree agree_label: "I agree with %{title}" anonymous: Too many anonymous votes to admit vote %{verify_account}. - comment_unauthenticated: You must %{signin} or %{signup} to vote. disagree: I disagree disagree_label: "I don't agree with %{title}" organizations: Organizations are not permitted to vote diff --git a/config/locales/es/general.yml b/config/locales/es/general.yml index 1511b9826..3c18e9b39 100644 --- a/config/locales/es/general.yml +++ b/config/locales/es/general.yml @@ -849,7 +849,6 @@ es: agree: Estoy de acuerdo agree_label: "Estoy de acuerdo con %{title}" anonymous: Demasiados votos anĂ³nimos, para poder votar %{verify_account}. - comment_unauthenticated: Necesitas %{signin} o %{signup} para poder votar. disagree: No estoy de acuerdo disagree_label: "No estoy de acuerdo con %{title}" organizations: Las organizaciones no pueden votar. diff --git a/spec/support/common_actions/votes.rb b/spec/support/common_actions/votes.rb index 29d2ea8b6..e6f4ff061 100644 --- a/spec/support/common_actions/votes.rb +++ b/spec/support/common_actions/votes.rb @@ -4,12 +4,6 @@ module Votes expect(page).to have_selector(".in-favor", obscured: true) end - def expect_message_you_need_to_sign_in_to_vote_comments - within(".participation-not-allowed") do - expect(page).to have_content "You must sign in or sign up to vote" - end - end - def expect_message_to_many_anonymous_votes expect(page).to have_content "Too many anonymous votes to admit vote" expect(page).to have_button "I agree", obscured: true diff --git a/spec/system/votes_spec.rb b/spec/system/votes_spec.rb index f5ea56430..dc8672a01 100644 --- a/spec/system/votes_spec.rb +++ b/spec/system/votes_spec.rb @@ -278,10 +278,12 @@ describe "Votes" do comment = create(:comment, commentable: debate) visit comment_path(comment) + within("#comment_#{comment.id}") do - find("div.votes").hover - expect_message_you_need_to_sign_in_to_vote_comments + click_button "I agree" end + + expect(page).to have_current_path new_user_session_path end scenario "Not logged user trying to vote comments in proposals" do @@ -289,10 +291,12 @@ describe "Votes" do comment = create(:comment, commentable: proposal) visit comment_path(comment) + within("#comment_#{comment.id}_reply") do - find("div.votes").hover - expect_message_you_need_to_sign_in_to_vote_comments + click_button "I agree" end + + expect(page).to have_current_path new_user_session_path end scenario "Anonymous user trying to vote debates" do