Legislation proposals adaptation in some models and initializers
This commit is contained in:
@@ -156,11 +156,11 @@ class Legislation::Proposal < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
|
|
||||||
def after_hide
|
def after_hide
|
||||||
tags.each{ |t| t.decrement_custom_counter_for('Proposal') }
|
tags.each{ |t| t.decrement_custom_counter_for('LegislationProposal') }
|
||||||
end
|
end
|
||||||
|
|
||||||
def after_restore
|
def after_restore
|
||||||
tags.each{ |t| t.increment_custom_counter_for('Proposal') }
|
tags.each{ |t| t.increment_custom_counter_for('LegislationProposal') }
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.votes_needed_for_success
|
def self.votes_needed_for_success
|
||||||
|
|||||||
@@ -97,6 +97,12 @@ class User < ActiveRecord::Base
|
|||||||
voted.each_with_object({}) { |v, h| h[v.votable_id] = v.value }
|
voted.each_with_object({}) { |v, h| h[v.votable_id] = v.value }
|
||||||
end
|
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)
|
def spending_proposal_votes(spending_proposals)
|
||||||
voted = votes.for_spending_proposals(spending_proposals)
|
voted = votes.for_spending_proposals(spending_proposals)
|
||||||
voted.each_with_object({}) { |v, h| h[v.votable_id] = v.value }
|
voted.each_with_object({}) { |v, h| h[v.votable_id] = v.value }
|
||||||
|
|||||||
@@ -5,10 +5,12 @@ class Vote < ActsAsVotable::Vote
|
|||||||
scope :public_for_api, -> do
|
scope :public_for_api, -> do
|
||||||
where(%{(votes.votable_type = 'Debate' and votes.votable_id in (?)) or
|
where(%{(votes.votable_type = 'Debate' and votes.votable_id in (?)) or
|
||||||
(votes.votable_type = 'Proposal' 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),
|
Debate.public_for_api.pluck(:id),
|
||||||
Proposal.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
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -8,10 +8,11 @@ module ActsAsTaggableOn
|
|||||||
scope :public_for_api, -> do
|
scope :public_for_api, -> do
|
||||||
where(%{taggings.tag_id in (?) and
|
where(%{taggings.tag_id in (?) and
|
||||||
(taggings.taggable_type = 'Debate' and taggings.taggable_id in (?)) or
|
(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),
|
Tag.where('kind IS NULL or kind = ?', 'category').pluck(:id),
|
||||||
Debate.public_for_api.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
|
end
|
||||||
|
|
||||||
def touch_taggable
|
def touch_taggable
|
||||||
|
|||||||
@@ -13,6 +13,10 @@ ActsAsVotable::Vote.class_eval do
|
|||||||
where(votable_type: 'SpendingProposal', votable_id: spending_proposals)
|
where(votable_type: 'SpendingProposal', votable_id: spending_proposals)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.for_spending_proposals(spending_proposals)
|
||||||
|
where(votable_type: 'LegislationProposal', votable_id: legislation_proposals)
|
||||||
|
end
|
||||||
|
|
||||||
def self.for_budget_investments(budget_investments)
|
def self.for_budget_investments(budget_investments)
|
||||||
where(votable_type: 'Budget::Investment', votable_id: budget_investments)
|
where(votable_type: 'Budget::Investment', votable_id: budget_investments)
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user