From 70f717e564dce00aede8badefa8abaad1103454f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Tue, 28 Sep 2021 23:21:43 +0200 Subject: [PATCH] Use current user in votes components Just like we do in most places; we almost never use `user_signed_in?`. --- app/components/comments/votes_component.html.erb | 4 ++-- app/components/comments/votes_component.rb | 2 +- app/components/debates/votes_component.html.erb | 10 +++++----- app/components/debates/votes_component.rb | 2 +- .../legislation/proposals/votes_component.html.erb | 10 +++++----- .../legislation/proposals/votes_component.rb | 2 +- app/components/proposals/votes_component.html.erb | 8 ++++---- app/components/proposals/votes_component.rb | 2 +- 8 files changed, 20 insertions(+), 20 deletions(-) diff --git a/app/components/comments/votes_component.html.erb b/app/components/comments/votes_component.html.erb index 701bd225f..e92b2bb25 100644 --- a/app/components/comments/votes_component.html.erb +++ b/app/components/comments/votes_component.html.erb @@ -1,5 +1,5 @@
- <% if user_signed_in? %> + <% if current_user %> <%= t("comments.comment.votes", count: comment.total_votes) %>  |  @@ -36,7 +36,7 @@ <% end %> <%= comment.total_dislikes %> - <% elsif !user_signed_in? %> + <% else %>
<%= t("comments.comment.votes", count: comment.total_votes) %>  |  diff --git a/app/components/comments/votes_component.rb b/app/components/comments/votes_component.rb index 2287eff18..d776aaaba 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 :user_signed_in?, :can?, :link_to_signin, :link_to_signup, to: :helpers + delegate :current_user, :can?, :link_to_signin, :link_to_signup, to: :helpers def initialize(comment) @comment = comment diff --git a/app/components/debates/votes_component.html.erb b/app/components/debates/votes_component.html.erb index 8c0570e67..a756f579e 100644 --- a/app/components/debates/votes_component.html.erb +++ b/app/components/debates/votes_component.html.erb @@ -1,7 +1,7 @@ <% voted_classes = css_classes_for_vote(debate) %>
- <% if user_signed_in? %> + <% if current_user %> <%= link_to vote_debate_path(debate, value: "yes"), class: "like #{voted_classes[:in_favor]}", title: t("votes.agree"), method: "post", remote: true do %> @@ -22,7 +22,7 @@
- <% if user_signed_in? %> + <% if current_user %> <%= link_to vote_debate_path(debate, value: "no"), class: "unlike #{voted_classes[:against]}", title: t("votes.disagree"), method: "post", remote: true do %> <%= t("votes.disagree") %> @@ -43,19 +43,19 @@ <%= t("debates.debate.votes", count: debate.votes_score) %> - <% if user_signed_in? && current_user.organization? %> + <% if current_user&.organization? %> - <% elsif user_signed_in? && !debate.votable_by?(current_user) %> + <% elsif current_user && !debate.votable_by?(current_user) %> - <% elsif !user_signed_in? %> + <% elsif !current_user %>
<%= render "shared/login_to_vote" %>
diff --git a/app/components/debates/votes_component.rb b/app/components/debates/votes_component.rb index 2c75f7f43..80fedc9ba 100644 --- a/app/components/debates/votes_component.rb +++ b/app/components/debates/votes_component.rb @@ -1,6 +1,6 @@ class Debates::VotesComponent < ApplicationComponent attr_reader :debate - delegate :css_classes_for_vote, :current_user, :link_to_verify_account, :user_signed_in?, :votes_percentage, to: :helpers + delegate :css_classes_for_vote, :current_user, :link_to_verify_account, :votes_percentage, to: :helpers def initialize(debate) @debate = debate diff --git a/app/components/legislation/proposals/votes_component.html.erb b/app/components/legislation/proposals/votes_component.html.erb index 34961266d..f3715f41f 100644 --- a/app/components/legislation/proposals/votes_component.html.erb +++ b/app/components/legislation/proposals/votes_component.html.erb @@ -2,7 +2,7 @@
<% if proposal.process.proposals_phase.open? %>
- <% if user_signed_in? %> + <% if current_user %> <%= link_to vote_legislation_process_proposal_path(process_id: proposal.process, id: proposal, value: "yes"), class: "like #{voted_classes[:in_favor]}", title: t("votes.agree"), method: "post", remote: true do %> @@ -23,7 +23,7 @@
- <% if user_signed_in? %> + <% if current_user %> <%= link_to vote_legislation_process_proposal_path(process_id: proposal.process, id: proposal, value: "no"), class: "unlike #{voted_classes[:against]}", title: t("votes.disagree"), method: "post", remote: true do %> <%= t("votes.disagree") %> @@ -45,20 +45,20 @@ <%= t("proposals.proposal.votes", count: proposal.votes_score) %> - <% if user_signed_in? && current_user.organization? %> + <% if current_user&.organization? %> - <% elsif user_signed_in? && !proposal.votable_by?(current_user) %> + <% elsif current_user && !proposal.votable_by?(current_user) %> - <% elsif !user_signed_in? %> + <% elsif !current_user %>
<%= render "shared/login_to_vote" %>
diff --git a/app/components/legislation/proposals/votes_component.rb b/app/components/legislation/proposals/votes_component.rb index 0dabb29ec..f59d11d68 100644 --- a/app/components/legislation/proposals/votes_component.rb +++ b/app/components/legislation/proposals/votes_component.rb @@ -1,6 +1,6 @@ class Legislation::Proposals::VotesComponent < ApplicationComponent attr_reader :proposal - delegate :css_classes_for_vote, :current_user, :link_to_verify_account, :user_signed_in?, :votes_percentage, to: :helpers + delegate :css_classes_for_vote, :current_user, :link_to_verify_account, :votes_percentage, to: :helpers def initialize(proposal) @proposal = proposal diff --git a/app/components/proposals/votes_component.html.erb b/app/components/proposals/votes_component.html.erb index 1834cc094..5ca164d94 100644 --- a/app/components/proposals/votes_component.html.erb +++ b/app/components/proposals/votes_component.html.erb @@ -6,7 +6,7 @@
<%= t("proposals.proposal.already_supported") %>
- <% elsif user_signed_in? && proposal.votable_by?(current_user) %> + <% elsif current_user && proposal.votable_by?(current_user) %> <%= link_to vote_url, class: "button button-support small expanded", title: t("proposals.proposal.support_title"), method: "post", remote: true do %> @@ -19,13 +19,13 @@ <% end %>
- <% if user_signed_in? && current_user.organization? %> + <% if current_user&.organization? %> - <% elsif user_signed_in? && !proposal.votable_by?(current_user) %> + <% elsif current_user && !proposal.votable_by?(current_user) %>
- <% elsif !user_signed_in? %> + <% elsif !current_user %>
<%= render "shared/login_to_vote" %>
diff --git a/app/components/proposals/votes_component.rb b/app/components/proposals/votes_component.rb index 0b42839c8..143b32ada 100644 --- a/app/components/proposals/votes_component.rb +++ b/app/components/proposals/votes_component.rb @@ -1,6 +1,6 @@ class Proposals::VotesComponent < ApplicationComponent attr_reader :proposal - delegate :current_user, :link_to_verify_account, :user_signed_in?, to: :helpers + delegate :current_user, :link_to_verify_account, to: :helpers def initialize(proposal, vote_url: nil) @proposal = proposal