diff --git a/app/models/legislation/proposal.rb b/app/models/legislation/proposal.rb index 1eb82e70a..5f6706339 100644 --- a/app/models/legislation/proposal.rb +++ b/app/models/legislation/proposal.rb @@ -156,11 +156,11 @@ class Legislation::Proposal < ActiveRecord::Base end def after_hide - tags.each{ |t| t.decrement_custom_counter_for('Proposal') } + tags.each{ |t| t.decrement_custom_counter_for('LegislationProposal') } end def after_restore - tags.each{ |t| t.increment_custom_counter_for('Proposal') } + tags.each{ |t| t.increment_custom_counter_for('LegislationProposal') } end def self.votes_needed_for_success diff --git a/app/models/user.rb b/app/models/user.rb index ef6ab7832..b34897688 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -97,6 +97,12 @@ class User < ActiveRecord::Base voted.each_with_object({}) { |v, h| h[v.votable_id] = v.value } end + def legislation_proposal_votes(proposals) + voted = votes.for_proposals(proposals) + voted.each_with_object({}) { |v, h| h[v.votable_id] = v.value } + end + + def spending_proposal_votes(spending_proposals) voted = votes.for_spending_proposals(spending_proposals) voted.each_with_object({}) { |v, h| h[v.votable_id] = v.value } diff --git a/app/models/vote.rb b/app/models/vote.rb index 14b11a68d..4d4d07be0 100644 --- a/app/models/vote.rb +++ b/app/models/vote.rb @@ -5,10 +5,12 @@ class Vote < ActsAsVotable::Vote scope :public_for_api, -> do where(%{(votes.votable_type = 'Debate' and votes.votable_id in (?)) or (votes.votable_type = 'Proposal' and votes.votable_id in (?)) or - (votes.votable_type = 'Comment' and votes.votable_id in (?))}, + (votes.votable_type = 'Comment' and votes.votable_id in (?)) or + (votes.votable_type = 'LegislationProposal' and votes.votable_id in (?))}, Debate.public_for_api.pluck(:id), Proposal.public_for_api.pluck(:id), - Comment.public_for_api.pluck(:id)) + Comment.public_for_api.pluck(:id), + Legislation::Proposal.public_for_api.pluck(:id)) end end diff --git a/config/initializers/acts_as_taggable_on.rb b/config/initializers/acts_as_taggable_on.rb index 57766c8c9..9db832bef 100644 --- a/config/initializers/acts_as_taggable_on.rb +++ b/config/initializers/acts_as_taggable_on.rb @@ -8,10 +8,11 @@ module ActsAsTaggableOn scope :public_for_api, -> do where(%{taggings.tag_id in (?) and (taggings.taggable_type = 'Debate' and taggings.taggable_id in (?)) or - (taggings.taggable_type = 'Proposal' and taggings.taggable_id in (?))}, + (taggings.taggable_type = 'Proposal' and taggings.taggable_id in (?)) or taggings.taggable_type = 'LegislationProposal' and taggings.taggable_id in (?))}, Tag.where('kind IS NULL or kind = ?', 'category').pluck(:id), Debate.public_for_api.pluck(:id), - Proposal.public_for_api.pluck(:id)) + Proposal.public_for_api.pluck(:id), + Legislation::Proposal.public_for_api.pluck(:id)) end def touch_taggable diff --git a/config/initializers/vote_extensions.rb b/config/initializers/vote_extensions.rb index 06d3dde5b..1b6ae7252 100644 --- a/config/initializers/vote_extensions.rb +++ b/config/initializers/vote_extensions.rb @@ -13,6 +13,10 @@ ActsAsVotable::Vote.class_eval do where(votable_type: 'SpendingProposal', votable_id: spending_proposals) end + def self.for_spending_proposals(spending_proposals) + where(votable_type: 'LegislationProposal', votable_id: legislation_proposals) + end + def self.for_budget_investments(budget_investments) where(votable_type: 'Budget::Investment', votable_id: budget_investments) end