diff --git a/app/components/budgets/investments/ballot_component.html.erb b/app/components/budgets/investments/ballot_component.html.erb
index d3840b269..2863bb8f1 100644
--- a/app/components/budgets/investments/ballot_component.html.erb
+++ b/app/components/budgets/investments/ballot_component.html.erb
@@ -40,17 +40,5 @@
<% end %>
- <% if reason.present? && !voted? %>
-
-
-
- <%= sanitize(t("budgets.ballots.reasons_for_not_balloting.#{reason}",
- verify_account: link_to_verify_account, signin: link_to_signin,
- signup: link_to_signup, my_heading: link_to_my_heading,
- change_ballot: link_to_change_ballot,
- heading_link: heading_link(assigned_heading, budget))) %>
-
-
-
- <% end %>
+ <%= render Shared::ParticipationNotAllowedComponent.new(investment, cannot_vote_text: cannot_vote_text) %>
diff --git a/app/components/budgets/investments/ballot_component.rb b/app/components/budgets/investments/ballot_component.rb
index 016ff1bac..539e80afd 100644
--- a/app/components/budgets/investments/ballot_component.rb
+++ b/app/components/budgets/investments/ballot_component.rb
@@ -1,7 +1,6 @@
class Budgets::Investments::BallotComponent < ApplicationComponent
attr_reader :investment, :investment_ids, :ballot, :assigned_heading
- delegate :current_user, :heading_link, :link_to_signin, :link_to_signup,
- :link_to_verify_account, to: :helpers
+ delegate :current_user, :heading_link, :link_to_verify_account, to: :helpers
def initialize(investment:, investment_ids:, ballot:, assigned_heading:)
@investment = investment
@@ -42,4 +41,14 @@ class Budgets::Investments::BallotComponent < ApplicationComponent
link_to(t("budgets.ballots.reasons_for_not_balloting.change_ballot"),
budget_ballot_path(budget))
end
+
+ def cannot_vote_text
+ if reason.present? && !voted?
+ t("budgets.ballots.reasons_for_not_balloting.#{reason}",
+ verify_account: link_to_verify_account,
+ my_heading: link_to_my_heading,
+ change_ballot: link_to_change_ballot,
+ heading_link: heading_link(assigned_heading, budget))
+ end
+ end
end
diff --git a/app/components/budgets/investments/votes_component.html.erb b/app/components/budgets/investments/votes_component.html.erb
index 5ba4b299c..bb16453c3 100644
--- a/app/components/budgets/investments/votes_component.html.erb
+++ b/app/components/budgets/investments/votes_component.html.erb
@@ -34,21 +34,7 @@
<% end %>
- <% if reason.present? && !user_voted_for? %>
-
-
-
- <%= sanitize(t("votes.budget_investments.#{reason}",
- count: investment.group.max_votable_headings,
- verify_account: link_to_verify_account,
- signin: link_to_signin,
- signup: link_to_signup,
- supported_headings: (current_user && current_user.headings_voted_within_group(investment.group).map(&:name).sort.to_sentence)
- )) %>
-
-
-
- <% end %>
+ <%= render Shared::ParticipationNotAllowedComponent.new(investment, cannot_vote_text: cannot_vote_text) %>
<% if user_voted_for? && setting["twitter_handle"] %>
diff --git a/app/components/budgets/investments/votes_component.rb b/app/components/budgets/investments/votes_component.rb
index 65e6251b4..2a8877db2 100644
--- a/app/components/budgets/investments/votes_component.rb
+++ b/app/components/budgets/investments/votes_component.rb
@@ -1,7 +1,6 @@
class Budgets::Investments::VotesComponent < ApplicationComponent
attr_reader :investment
- delegate :namespace, :current_user, :image_absolute_url,
- :link_to_verify_account, :link_to_signin, :link_to_signup, to: :helpers
+ delegate :namespace, :current_user, :image_absolute_url, :link_to_verify_account, to: :helpers
def initialize(investment)
@investment = investment
@@ -59,4 +58,13 @@ class Budgets::Investments::VotesComponent < ApplicationComponent
def remove_support_aria_label
t("budgets.investments.votes.remove_support_label", investment: investment.title)
end
+
+ def cannot_vote_text
+ if reason.present? && !user_voted_for?
+ t("votes.budget_investments.#{reason}",
+ count: investment.group.max_votable_headings,
+ verify_account: link_to_verify_account,
+ supported_headings: (current_user && current_user.headings_voted_within_group(investment.group).map(&:name).sort.to_sentence))
+ end
+ end
end
diff --git a/app/components/debates/votes_component.html.erb b/app/components/debates/votes_component.html.erb
index 659a5054c..d822145d4 100644
--- a/app/components/debates/votes_component.html.erb
+++ b/app/components/debates/votes_component.html.erb
@@ -5,21 +5,5 @@
<%= t("debates.debate.votes", count: debate.votes_score) %>
- <% if !current_user %>
-
- <%= render "shared/login_to_vote" %>
-
- <% elsif organization? %>
-
-
- <%= t("votes.organizations") %>
-
-
- <% elsif !can_vote? %>
-
-
- <%= sanitize(t("votes.anonymous", verify_account: link_to_verify_account)) %>
-
-
- <% end %>
+ <%= render Shared::ParticipationNotAllowedComponent.new(debate, cannot_vote_text: cannot_vote_text) %>
diff --git a/app/components/debates/votes_component.rb b/app/components/debates/votes_component.rb
index b8fbed82b..7ebba83cf 100644
--- a/app/components/debates/votes_component.rb
+++ b/app/components/debates/votes_component.rb
@@ -12,7 +12,7 @@ class Debates::VotesComponent < ApplicationComponent
debate.votable_by?(current_user)
end
- def organization?
- current_user&.organization?
+ def cannot_vote_text
+ t("votes.anonymous", verify_account: link_to_verify_account) unless can_vote?
end
end
diff --git a/app/components/legislation/proposals/votes_component.html.erb b/app/components/legislation/proposals/votes_component.html.erb
index 86620b33e..c85edf51c 100644
--- a/app/components/legislation/proposals/votes_component.html.erb
+++ b/app/components/legislation/proposals/votes_component.html.erb
@@ -7,24 +7,7 @@
<%= t("proposals.proposal.votes", count: proposal.votes_score) %>
- <% if !current_user %>
-
- <%= render "shared/login_to_vote" %>
-
- <% elsif organization? %>
-
-
- <%= t("votes.organizations") %>
-
-
- <% elsif !can_vote? %>
-
-
- <%= sanitize(t("legislation.proposals.not_verified",
- verify_account: link_to_verify_account)) %>
-
-
- <% end %>
+ <%= render Shared::ParticipationNotAllowedComponent.new(proposal, cannot_vote_text: cannot_vote_text) %>
<% if current_user&.voted_as_when_voted_for(proposal) && setting["twitter_handle"] %>
diff --git a/app/components/legislation/proposals/votes_component.rb b/app/components/legislation/proposals/votes_component.rb
index a93d69683..96495800f 100644
--- a/app/components/legislation/proposals/votes_component.rb
+++ b/app/components/legislation/proposals/votes_component.rb
@@ -12,7 +12,7 @@ class Legislation::Proposals::VotesComponent < ApplicationComponent
proposal.votable_by?(current_user)
end
- def organization?
- current_user&.organization?
+ def cannot_vote_text
+ t("legislation.proposals.not_verified", verify_account: link_to_verify_account) unless can_vote?
end
end
diff --git a/app/components/proposals/votes_component.html.erb b/app/components/proposals/votes_component.html.erb
index 667a92fb0..1d1ea009d 100644
--- a/app/components/proposals/votes_component.html.erb
+++ b/app/components/proposals/votes_component.html.erb
@@ -19,25 +19,7 @@
<% end %>
- <% if !current_user %>
-
- <%= render "shared/login_to_vote" %>
-
- <% elsif organization? %>
-
-
- <%= t("votes.organizations") %>
-
-
- <% elsif !can_vote? %>
-
-
-
- <%= sanitize(t("votes.verified_only", verify_account: link_to_verify_account)) %>
-
-
-
- <% end %>
+ <%= render Shared::ParticipationNotAllowedComponent.new(proposal, cannot_vote_text: cannot_vote_text) %>
<% if voted? && setting["twitter_handle"] %>
diff --git a/app/components/proposals/votes_component.rb b/app/components/proposals/votes_component.rb
index 6fbf7d351..5718b72eb 100644
--- a/app/components/proposals/votes_component.rb
+++ b/app/components/proposals/votes_component.rb
@@ -25,7 +25,7 @@ class Proposals::VotesComponent < ApplicationComponent
t("proposals.proposal.support_label", proposal: proposal.title)
end
- def organization?
- current_user&.organization?
+ def cannot_vote_text
+ t("votes.verified_only", verify_account: link_to_verify_account) unless can_vote?
end
end
diff --git a/app/components/shared/participation_not_allowed_component.html.erb b/app/components/shared/participation_not_allowed_component.html.erb
new file mode 100644
index 000000000..6a7459e64
--- /dev/null
+++ b/app/components/shared/participation_not_allowed_component.html.erb
@@ -0,0 +1,5 @@
+
diff --git a/app/components/shared/participation_not_allowed_component.rb b/app/components/shared/participation_not_allowed_component.rb
new file mode 100644
index 000000000..1cabdb53c
--- /dev/null
+++ b/app/components/shared/participation_not_allowed_component.rb
@@ -0,0 +1,30 @@
+class Shared::ParticipationNotAllowedComponent < ApplicationComponent
+ attr_reader :votable, :cannot_vote_text
+ delegate :current_user, :link_to_signin, :link_to_signup, to: :helpers
+
+ def initialize(votable, cannot_vote_text:)
+ @votable = votable
+ @cannot_vote_text = cannot_vote_text
+ end
+
+ def render?
+ body.present?
+ end
+
+ private
+
+ def body
+ @body ||=
+ if !current_user
+ sanitize(t("users.login_to_continue", signin: link_to_signin, signup: link_to_signup))
+ elsif organization?
+ tag.p t("votes.organizations")
+ elsif cannot_vote_text.present?
+ tag.p sanitize(cannot_vote_text)
+ end
+ end
+
+ def organization?
+ current_user&.organization?
+ end
+end
diff --git a/app/views/shared/_login_to_vote.html.erb b/app/views/shared/_login_to_vote.html.erb
deleted file mode 100644
index 20ff9c5ce..000000000
--- a/app/views/shared/_login_to_vote.html.erb
+++ /dev/null
@@ -1,3 +0,0 @@
-
- <%= sanitize(t("users.login_to_continue", signin: link_to_signin, signup: link_to_signup)) %>
-
diff --git a/config/locales/en/budgets.yml b/config/locales/en/budgets.yml
index 4e2fb88bb..99a49af9a 100644
--- a/config/locales/en/budgets.yml
+++ b/config/locales/en/budgets.yml
@@ -31,9 +31,7 @@ en:
voted_info_2: "But you can change your vote at any time until this phase is closed."
zero: You have not voted any investment project.
reasons_for_not_balloting:
- not_logged_in: You must %{signin} or %{signup} to continue.
not_verified: Only verified users can vote on investments; %{verify_account}.
- organization: Organizations are not permitted to vote
not_selected: Unselected investment projects can not be supported
not_enough_money: "You have already assigned the available budget.
Remember you can %{change_ballot} at any time"
no_ballots_allowed: Selecting phase is closed
diff --git a/config/locales/en/general.yml b/config/locales/en/general.yml
index eebed8c93..01477295b 100644
--- a/config/locales/en/general.yml
+++ b/config/locales/en/general.yml
@@ -855,9 +855,7 @@ en:
supports: Supports
verified_only: Only verified users can vote on proposals; %{verify_account}.
budget_investments:
- not_logged_in: You must %{signin} or %{signup} to continue.
not_verified: Only verified users can vote on investment projects; %{verify_account}.
- organization: Organizations are not permitted to vote
unfeasible: Unfeasible investment projects can not be supported
not_voting_allowed: Voting phase is closed
different_heading_assigned:
diff --git a/config/locales/es/budgets.yml b/config/locales/es/budgets.yml
index 6d892076b..1fea405b4 100644
--- a/config/locales/es/budgets.yml
+++ b/config/locales/es/budgets.yml
@@ -31,9 +31,7 @@ es:
voted_info_2: "Pero puedes cambiarlos en cualquier momento hasta el cierre de esta fase."
zero: Todavía no has votado ningún proyecto de gasto.
reasons_for_not_balloting:
- not_logged_in: Necesitas %{signin} o %{signup} para continuar.
not_verified: Los proyectos de gasto sólo pueden ser apoyados por usuarios verificados, %{verify_account}.
- organization: Las organizaciones no pueden votar.
not_selected: No se pueden votar proyectos inviables.
not_enough_money: "Ya has asignado el presupuesto disponible.
Recuerda que puedes %{change_ballot} en cualquier momento"
no_ballots_allowed: El periodo de votación está cerrado.
diff --git a/config/locales/es/general.yml b/config/locales/es/general.yml
index 3c18e9b39..c76541d7e 100644
--- a/config/locales/es/general.yml
+++ b/config/locales/es/general.yml
@@ -855,9 +855,7 @@ es:
supports: Apoyos
verified_only: Las propuestas sólo pueden ser votadas por usuarios verificados, %{verify_account}.
budget_investments:
- not_logged_in: Necesitas %{signin} o %{signup} para continuar.
not_verified: Los proyectos de gasto sólo pueden ser apoyadas por usuarios verificados, %{verify_account}.
- organization: Las organizaciones no pueden votar.
unfeasible: No se pueden votar propuestas inviables.
not_voting_allowed: El periodo de votación está cerrado.
different_heading_assigned:
diff --git a/spec/components/shared/participation_not_allowed_component_spec.rb b/spec/components/shared/participation_not_allowed_component_spec.rb
new file mode 100644
index 000000000..10faf446a
--- /dev/null
+++ b/spec/components/shared/participation_not_allowed_component_spec.rb
@@ -0,0 +1,70 @@
+require "rails_helper"
+
+describe Shared::ParticipationNotAllowedComponent do
+ let(:votable) { create(:proposal) }
+
+ context "Without cannot vote text" do
+ let(:component) { Shared::ParticipationNotAllowedComponent.new(votable, cannot_vote_text: nil) }
+
+ it "asks anonymous users to sign in or sign up" do
+ render_inline component
+
+ expect(page).to have_content "You must sign in or sign up to continue"
+ expect(page).to have_link "sign in"
+ expect(page).to have_link "sign up"
+ end
+
+ it "says voting is not allowed to organizations" do
+ sign_in(create(:organization, user: create(:user, :level_two)).user)
+
+ render_inline component
+
+ expect(page).to have_content "Organizations are not permitted to vote"
+ expect(page).not_to have_link "sign in", visible: :all
+ expect(page).not_to have_link "sign up", visible: :all
+ end
+
+ it "is not rendered to regular users" do
+ sign_in(create(:user))
+
+ render_inline component
+
+ expect(page).not_to be_rendered
+ end
+ end
+
+ context "With cannot vote text" do
+ let(:component) { Shared::ParticipationNotAllowedComponent.new(votable, cannot_vote_text: "Too old") }
+
+ it "ignores the text and asks anonymous users to sign in or sign up" do
+ render_inline component
+
+ expect(page).to have_content "You must sign in or sign up to continue"
+ expect(page).to have_link "sign in"
+ expect(page).to have_link "sign up"
+ expect(page).not_to have_content "Too old"
+ end
+
+ it "ignores the text and says voting is not allowed to organizations" do
+ sign_in(create(:organization, user: create(:user, :level_two)).user)
+
+ render_inline component
+
+ expect(page).to have_content "Organizations are not permitted to vote"
+ expect(page).not_to have_link "sign in", visible: :all
+ expect(page).not_to have_link "sign up", visible: :all
+ expect(page).not_to have_content "Too old"
+ end
+
+ it "renders the cannot vote text to regular users" do
+ sign_in(create(:user))
+
+ render_inline component
+
+ expect(page).to have_content "Too old"
+ expect(page).not_to have_content "Organizations are not permitted to vote"
+ expect(page).not_to have_link "sign in", visible: :all
+ expect(page).not_to have_link "sign up", visible: :all
+ end
+ end
+end