disable voting on sps if setting disabled

refactors hover messages on sps votes
This commit is contained in:
Juanjo Bazán
2016-04-15 23:01:00 +02:00
parent 5a785ca7ce
commit e6a9cb4fcc
10 changed files with 111 additions and 26 deletions

View File

@@ -5,11 +5,13 @@ App.Votes =
$("div.anonymous-votes", votes).show();
$("div.organizations-votes", votes).show();
$("div.not-logged", votes).show();
$("div.no-supports-allowed", votes).show();
$("div.logged", votes).hide();
, ->
$("div.anonymous-votes", votes).hide();
$("div.organizations-votes", votes).hide();
$("div.not-logged", votes).hide();
$("div.no-supports-allowed", votes).hide();
$("div.logged", votes).show();
initialize: ->

View File

@@ -240,7 +240,7 @@
}
}
.anonymous-votes, .organizations-votes {
.anonymous-votes, .organizations-votes, .no-supports-allowed {
background: $warning-bg;
color: $warning-color;
height: 100%;
@@ -847,16 +847,13 @@
color: $budget;
}
.not-logged,
.organizations-votes,
.anonymous-votes {
.no-supports-allowed {
background: rgba(69,67,114,.96);
color: white;
padding: rem-calc(12);
}
.anonymous-votes p, .anonymous-votes a,
.organizations-votes p {
.no-supports-allowed p, .no-supports-allowed a {
color: white;
}
}

View File

@@ -112,8 +112,16 @@ class SpendingProposal < ActiveRecord::Base
update(unfeasible_email_sent_at: Time.now)
end
def reason_for_not_being_votable_by(user)
return :not_logged_in unless user
return :not_verified unless user.can?(:vote, SpendingProposal)
return :unfeasible if unfeasible?
return :organization if user.organization?
return :not_voting_allowed if Setting["feature.spending_proposal_features.voting_allowed"].blank?
end
def votable_by?(user)
user && user.level_two_or_three_verified?
reason_for_not_being_votable_by(user).blank?
end
def register_vote(user, vote_value)

View File

@@ -222,6 +222,11 @@ class User < ActiveRecord::Base
self.update(registering_with_oauth: true, email: nil)
end
def ability
@ability ||= Ability.new(self)
end
delegate :can?, :cannot?, to: :ability
private
def clean_document_number
self.document_number = self.document_number.gsub(/[^a-z0-9]+/i, "").upcase unless self.document_number.blank?

View File

@@ -18,25 +18,18 @@
<% end %>
</div>
<% if user_signed_in? && current_user.organization? %>
<div class="organizations-votes" style='display:none'>
<p>
<%= t("votes.organizations") %>
</p>
</div>
<% elsif user_signed_in? && !spending_proposal.votable_by?(current_user)%>
<div class="anonymous-votes" style='display:none'>
<p>
<%= t("votes.verified_only",
verify_account: link_to(t("votes.verify_account"), verification_path )).html_safe %>
</p>
</div>
<% elsif !user_signed_in? %>
<div class="not-logged" style='display:none'>
<%= t("votes.unauthenticated",
signin: link_to(t("votes.signin"), new_user_session_path),
signup: link_to(t("votes.signup"), new_user_registration_path)).html_safe %>
</div>
<% reason = spending_proposal.reason_for_not_being_votable_by(current_user) %>
<% if reason.present? && !voted_for?(@spending_proposal_votes, spending_proposal) %>
<div class="no-supports-allowed" style='display:none'>
<p>
<%= t("votes.spending_proposals.#{reason}",
verify_account: link_to(t("votes.verify_account"), verification_path),
signin: link_to(t("votes.signin"), new_user_session_path),
signup: link_to(t("votes.signup"), new_user_registration_path)
).html_safe %>
</p>
</div>
<% end %>
<% if voted_for?(@spending_proposal_votes, spending_proposal) && setting['twitter_handle'] %>

View File

@@ -500,6 +500,12 @@ en:
unauthenticated: You must %{signin} or %{signup} to continue.
verified_only: Only verified users can vote on proposals; %{verify_account}.
verify_account: verify your account
spending_proposals:
not_logged_in: You must %{signin} or %{signup} to continue.
not_verified: Only verified users can vote on proposals; %{verify_account}.
organization: Organisations are not permitted to vote
unfeasible: Unfeasible investment projects can not be supported
not_voting_allowed: Voting phase is closed
welcome:
debates:
alt: Icon debates

View File

@@ -500,6 +500,12 @@ es:
unauthenticated: Necesitas %{signin} o %{signup} para continuar.
verified_only: Las propuestas sólo pueden ser votadas por usuarios verificados, %{verify_account}.
verify_account: verifica tu cuenta
spending_proposals:
not_logged_in: Necesitas %{signin} o %{signup} para continuar.
not_verified: Las propuestas de inversión 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.
welcome:
debates:
alt: Icono debates

View File

@@ -435,4 +435,24 @@ feature 'Votes' do
end
end
end
scenario 'Disable voting on spending proposals', :js do
login_as(@manuela)
Setting["feature.spending_proposal_features.voting_allowed"] = nil
spending_proposal = create(:spending_proposal)
visit spending_proposals_path
within("#spending_proposal_#{spending_proposal.id}") do
find("div.supports").hover
expect_message_voting_not_allowed
end
visit spending_proposal_path(spending_proposal)
within("#spending_proposal_#{spending_proposal.id}") do
find("div.supports").hover
expect_message_voting_not_allowed
end
end
end

View File

@@ -261,6 +261,49 @@ describe SpendingProposal do
end
end
describe 'Supports' do
let(:user) { create(:user, :level_two) }
let(:luser) { create(:user) }
let(:district) { create(:geozone) }
let(:city_sp) { create(:spending_proposal) }
let(:district_sp) { create(:spending_proposal, geozone: district) }
describe '#reason_for_not_being_votable_by' do
it "rejects not logged in users" do
expect(city_sp.reason_for_not_being_votable_by(nil)).to eq(:not_logged_in)
expect(district_sp.reason_for_not_being_votable_by(nil)).to eq(:not_logged_in)
end
it "rejects not verified users" do
expect(city_sp.reason_for_not_being_votable_by(luser)).to eq(:not_verified)
expect(district_sp.reason_for_not_being_votable_by(luser)).to eq(:not_verified)
end
it "rejects unfeasible spending proposals" do
unfeasible = create(:spending_proposal, feasible: false, valuation_finished: true)
expect(unfeasible.reason_for_not_being_votable_by(user)).to eq(:unfeasible)
end
it "rejects organizations" do
create(:organization, user: user)
expect(city_sp.reason_for_not_being_votable_by(user)).to eq(:organization)
expect(district_sp.reason_for_not_being_votable_by(user)).to eq(:organization)
end
it "rejects votes when voting is not allowed (via admin setting)" do
Setting["feature.spending_proposal_features.voting_allowed"] = nil
expect(city_sp.reason_for_not_being_votable_by(user)).to eq(:not_voting_allowed)
expect(district_sp.reason_for_not_being_votable_by(user)).to eq(:not_voting_allowed)
end
it "accepts valid votes when voting is allowed" do
Setting["feature.spending_proposal_features.voting_allowed"] = true
expect(city_sp.reason_for_not_being_votable_by(user)).to be_nil
expect(district_sp.reason_for_not_being_votable_by(user)).to be_nil
end
end
end
describe "responsible_name" do
let(:user) { create(:user, document_number: "123456") }
let!(:spending_proposal) { create(:spending_proposal, author: user) }

View File

@@ -174,6 +174,11 @@ module CommonActions
expect(page).to have_selector('.in-favor a', visible: false)
end
def expect_message_voting_not_allowed
expect(page).to have_content 'Voting phase is closed'
expect(page).to have_selector('.in-favor a', visible: false)
end
def create_featured_proposals
[create(:proposal, :with_confidence_score, cached_votes_up: 100),
create(:proposal, :with_confidence_score, cached_votes_up: 90),