Use current user in votes components

Just like we do in most places; we almost never use `user_signed_in?`.
This commit is contained in:
Javi Martín
2021-09-28 23:21:43 +02:00
parent 4b42a68b6a
commit 70f717e564
8 changed files with 20 additions and 20 deletions

View File

@@ -1,5 +1,5 @@
<div class="votes">
<% if user_signed_in? %>
<% if current_user %>
<%= t("comments.comment.votes", count: comment.total_votes) %>
&nbsp;|&nbsp;
@@ -36,7 +36,7 @@
<% end %>
<%= comment.total_dislikes %>
</span>
<% elsif !user_signed_in? %>
<% else %>
<div class="participation-allowed">
<%= t("comments.comment.votes", count: comment.total_votes) %>
&nbsp;|&nbsp;

View File

@@ -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

View File

@@ -1,7 +1,7 @@
<% voted_classes = css_classes_for_vote(debate) %>
<div class="votes">
<div class="in-favor inline-block">
<% 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 %>
<span class="icon-like">
@@ -22,7 +22,7 @@
<span class="divider"></span>
<div class="against inline-block">
<% 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 %>
<span class="icon-unlike">
<span class="show-for-sr"><%= t("votes.disagree") %></span>
@@ -43,19 +43,19 @@
<%= t("debates.debate.votes", count: debate.votes_score) %>
</span>
<% if user_signed_in? && current_user.organization? %>
<% if current_user&.organization? %>
<div class="participation-not-allowed" style="display:none" aria-hidden="false">
<p>
<%= t("votes.organizations") %>
</p>
</div>
<% elsif user_signed_in? && !debate.votable_by?(current_user) %>
<% elsif current_user && !debate.votable_by?(current_user) %>
<div class="participation-not-allowed" style="display:none" aria-hidden="false">
<p>
<%= sanitize(t("votes.anonymous", verify_account: link_to_verify_account)) %>
</p>
</div>
<% elsif !user_signed_in? %>
<% elsif !current_user %>
<div tabindex="0">
<%= render "shared/login_to_vote" %>
</div>

View File

@@ -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

View File

@@ -2,7 +2,7 @@
<div class="votes">
<% if proposal.process.proposals_phase.open? %>
<div class="in-favor inline-block">
<% 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 %>
<span class="icon-like">
@@ -23,7 +23,7 @@
<span class="divider"></span>
<div class="against inline-block">
<% 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 %>
<span class="icon-unlike">
<span class="show-for-sr"><%= t("votes.disagree") %></span>
@@ -45,20 +45,20 @@
<%= t("proposals.proposal.votes", count: proposal.votes_score) %>
</span>
<% if user_signed_in? && current_user.organization? %>
<% if current_user&.organization? %>
<div class="participation-not-allowed" style="display:none" aria-hidden="false">
<p>
<%= t("votes.organizations") %>
</p>
</div>
<% elsif user_signed_in? && !proposal.votable_by?(current_user) %>
<% elsif current_user && !proposal.votable_by?(current_user) %>
<div class="participation-not-allowed" style="display:none" aria-hidden="false">
<p>
<%= sanitize(t("legislation.proposals.not_verified",
verify_account: link_to_verify_account)) %>
</p>
</div>
<% elsif !user_signed_in? %>
<% elsif !current_user %>
<div tabindex="0">
<%= render "shared/login_to_vote" %>
</div>

View File

@@ -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

View File

@@ -6,7 +6,7 @@
<div class="supported callout success">
<%= t("proposals.proposal.already_supported") %>
</div>
<% 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 %>
</div>
<% if user_signed_in? && current_user.organization? %>
<% if current_user&.organization? %>
<div class="participation-not-allowed" style="display:none" aria-hidden="false">
<p>
<%= t("votes.organizations") %>
</p>
</div>
<% elsif user_signed_in? && !proposal.votable_by?(current_user) %>
<% elsif current_user && !proposal.votable_by?(current_user) %>
<div tabindex="0">
<div class="participation-not-allowed" style="display:none" aria-hidden="false">
<p>
@@ -33,7 +33,7 @@
</p>
</div>
</div>
<% elsif !user_signed_in? %>
<% elsif !current_user %>
<div tabindex="0">
<%= render "shared/login_to_vote" %>
</div>

View File

@@ -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