Merge pull request #1349 from consul/budgets-vote-permissions
User permissions for selecting phase
This commit is contained in:
@@ -61,6 +61,10 @@ module Budgets
|
||||
def vote
|
||||
@investment.register_selection(current_user)
|
||||
load_investment_votes(@investment)
|
||||
respond_to do |format|
|
||||
format.html { redirect_to budget_investments_path(heading_id: @investment.heading.id) }
|
||||
format.js
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
@@ -34,6 +34,10 @@ class Management::Budgets::InvestmentsController < Management::BaseController
|
||||
def vote
|
||||
@investment.register_selection(managed_user)
|
||||
load_investment_votes(@investment)
|
||||
respond_to do |format|
|
||||
format.html { redirect_to management_budget_investments_path(heading_id: @investment.heading.id) }
|
||||
format.js
|
||||
end
|
||||
end
|
||||
|
||||
def print
|
||||
|
||||
@@ -146,6 +146,7 @@ class Budget
|
||||
|
||||
def reason_for_not_being_selectable_by(user)
|
||||
return permission_problem(user) if permission_problem?(user)
|
||||
return :different_heading_assigned unless valid_heading?(user)
|
||||
|
||||
return :no_selecting_allowed unless budget.selecting?
|
||||
end
|
||||
@@ -173,6 +174,24 @@ class Budget
|
||||
reason_for_not_being_selectable_by(user).blank?
|
||||
end
|
||||
|
||||
def valid_heading?(user)
|
||||
!different_heading_assigned?(user)
|
||||
end
|
||||
|
||||
def different_heading_assigned?(user)
|
||||
other_heading_ids = group.heading_ids - [heading.id]
|
||||
voted_in?(other_heading_ids, user)
|
||||
end
|
||||
|
||||
def voted_in?(heading_ids, user)
|
||||
heading_ids.include? heading_voted_by_user?(user)
|
||||
end
|
||||
|
||||
def heading_voted_by_user?(user)
|
||||
user.votes.for_budget_investments(budget.investments.where(group: group)).
|
||||
votables.map(&:heading_id).first
|
||||
end
|
||||
|
||||
def ballotable_by?(user)
|
||||
reason_for_not_being_ballotable_by(user).blank?
|
||||
end
|
||||
|
||||
@@ -103,6 +103,10 @@ class User < ActiveRecord::Base
|
||||
comment_flags.each_with_object({}){ |f, h| h[f.flaggable_id] = true }
|
||||
end
|
||||
|
||||
def voted_in_group?(group)
|
||||
votes.for_budget_investments(Budget::Investment.where(group: group)).exists?
|
||||
end
|
||||
|
||||
def administrator?
|
||||
administrator.present?
|
||||
end
|
||||
|
||||
@@ -14,12 +14,12 @@
|
||||
<%= t("budgets.investments.investment.already_supported") %>
|
||||
</div>
|
||||
<% elsif investment.should_show_votes? %>
|
||||
|
||||
<%= link_to vote_url,
|
||||
class: "button button-support small expanded",
|
||||
title: t('budgets.investments.investment.support_title'),
|
||||
method: "post",
|
||||
remote: true,
|
||||
remote: (current_user && current_user.voted_in_group?(investment.group) ? true : false),
|
||||
data: (current_user && current_user.voted_in_group?(investment.group) ? nil : { confirm: t('budgets.investments.investment.confirm_group')} ),
|
||||
"aria-hidden" => css_for_aria_hidden(reason) do %>
|
||||
<%= t("budgets.investments.investment.give_support") %>
|
||||
<% end %>
|
||||
|
||||
Reference in New Issue
Block a user