aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'site/app/models/vote.rb')
-rw-r--r--site/app/models/vote.rb16
1 files changed, 13 insertions, 3 deletions
diff --git a/site/app/models/vote.rb b/site/app/models/vote.rb
index 5480f1b..c9695e9 100644
--- a/site/app/models/vote.rb
+++ b/site/app/models/vote.rb
@@ -4,6 +4,7 @@ class Vote < ActiveRecord::Base
hobo_model # Don't put anything above this
fields do
+ council_vote :boolean, :null => false, :default => false
timestamps
end
@@ -19,24 +20,33 @@ class Vote < ActiveRecord::Base
# --- Permissions --- #
def create_permitted?
+ return false if council_vote
user_is?(acting_user)
end
multi_permission(:update, :destroy) do
- user_is?(acting_user) and not user_changed?
+ return false if user_changed?
+ return false if council_vote
+ user_is?(acting_user)
end
def view_permitted?(field)
true
end
+ def council_vote_edit_permitted?
+ false
+ end
+
+ named_scope :user_for_item, lambda { |uid, iid| joins(:voting_option).where([
+ 'voting_options.agenda_item_id = ? AND votes.user_id = ?',
+ iid, uid]) }
protected
def user_voted_only_once
return if user.nil?
return if voting_option.nil?
return if voting_option.agenda_item.nil?
- other_votes = Vote.joins(:voting_option).where(['voting_options.agenda_item_id = ? AND votes.user_id = ?',
- voting_option.agenda_item_id, user_id])
+ other_votes = Vote.user_for_item(user_id, voting_option.agenda_item_id)
other_votes = other_votes.id_is_not(id) unless new_record?
if other_votes.count > 0
errors.add(:user, 'User can vote only once per agenda item.')