aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoachim Filip Ignacy Bartosik <jbartosik@gmail.com>2011-06-29 21:05:59 +0200
committerJoachim Filip Ignacy Bartosik <jbartosik@gmail.com>2011-07-06 16:49:50 +0200
commit18d211a14161638795cc0641646e0d454f97959c (patch)
treee2749d8abd282c45e6a9f12a9ba454395b6baa81 /site/app/models/agenda.rb
parentAllow all users to vote (diff)
downloadcouncil-webapp-18d211a14161638795cc0641646e0d454f97959c.tar.gz
council-webapp-18d211a14161638795cc0641646e0d454f97959c.tar.bz2
council-webapp-18d211a14161638795cc0641646e0d454f97959c.zip
Distinguish votes made during council voting and community voice
* Add council_vote to Vote model. * Users can create votes only with council_vote = false inside application. * Votes created from data from council meeting have council_vote = true. * Update council member vote after meeting if [s]he made one using web app.
Diffstat (limited to 'site/app/models/agenda.rb')
-rw-r--r--site/app/models/agenda.rb12
1 files changed, 11 insertions, 1 deletions
diff --git a/site/app/models/agenda.rb b/site/app/models/agenda.rb
index c15b12e..ca40b57 100644
--- a/site/app/models/agenda.rb
+++ b/site/app/models/agenda.rb
@@ -90,7 +90,17 @@ class Agenda < ActiveRecord::Base
for voter in votes.keys
option = VotingOption.first :conditions => { :agenda_item_id => item.id, :description => votes[voter] }
user = ::User.find_by_irc_nick voter
- Vote.create! :voting_option => option, :user => user
+ old_vote = Vote.user_for_item(user.id, item.id).first
+ if old_vote.nil?
+ Vote.create! :voting_option => option, :user => user, :council_vote => true
+ else
+ # Result of Vote.user_for_item is read only so reload it
+ # Reload method won't work so use find.
+ old_vote = Vote.find(old_vote)
+ old_vote.voting_option = option
+ old_vote.council_vote = true
+ old_vote.save!
+ end
end
end
end