Merge branch 'master' into budget-emails

This commit is contained in:
rgarcia
2017-01-15 18:58:20 +01:00
18 changed files with 245 additions and 16 deletions

View File

@@ -155,6 +155,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
@@ -182,6 +183,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
@@ -204,13 +223,19 @@ class Budget
end
def should_show_aside?
(budget.selecting? && !unfeasible?) || (budget.balloting? && feasible?) || budget.on_hold?
(budget.selecting? && !unfeasible?) ||
(budget.balloting? && feasible?) ||
(budget.valuating? && feasible?)
end
def should_show_votes?
budget.selecting?
end
def should_show_vote_count?
budget.valuating?
end
def should_show_ballots?
budget.balloting?
end

View File

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