Adapt backend to enable flagging/unflagging investments

This commit is contained in:
Angel Perez
2018-06-17 23:05:18 -04:00
parent 8ef3e81e03
commit 7bb1da1804
3 changed files with 21 additions and 4 deletions

View File

@@ -3,18 +3,32 @@ module FlagActions
def flag def flag
Flag.flag(current_user, flaggable) Flag.flag(current_user, flaggable)
if controller_name == 'investments'
respond_with flaggable, template: "budgets/#{controller_name}/_refresh_flag_actions"
else
respond_with flaggable, template: "#{controller_name}/_refresh_flag_actions" respond_with flaggable, template: "#{controller_name}/_refresh_flag_actions"
end end
end
def unflag def unflag
Flag.unflag(current_user, flaggable) Flag.unflag(current_user, flaggable)
if controller_name == 'investments'
respond_with flaggable, template: "budgets/#{controller_name}/_refresh_flag_actions"
else
respond_with flaggable, template: "#{controller_name}/_refresh_flag_actions" respond_with flaggable, template: "#{controller_name}/_refresh_flag_actions"
end end
end
private private
def flaggable def flaggable
if resource_model.to_s == 'Budget::Investment'
instance_variable_get("@investment")
else
instance_variable_get("@#{resource_model.to_s.downcase}") instance_variable_get("@#{resource_model.to_s.downcase}")
end end
end
end end

View File

@@ -23,6 +23,7 @@ class Budget
include Relationable include Relationable
include Notifiable include Notifiable
include Filterable include Filterable
include Flaggable
belongs_to :author, -> { with_hidden }, class_name: 'User', foreign_key: 'author_id' belongs_to :author, -> { with_hidden }, class_name: 'User', foreign_key: 'author_id'
belongs_to :heading belongs_to :heading

View File

@@ -182,6 +182,7 @@ class User < ActiveRecord::Base
debates_ids = Debate.where(author_id: id).pluck(:id) debates_ids = Debate.where(author_id: id).pluck(:id)
comments_ids = Comment.where(user_id: id).pluck(:id) comments_ids = Comment.where(user_id: id).pluck(:id)
proposal_ids = Proposal.where(author_id: id).pluck(:id) proposal_ids = Proposal.where(author_id: id).pluck(:id)
investment_ids = Budget::Investment.where(author_id: id).pluck(:id)
proposal_notification_ids = ProposalNotification.where(author_id: id).pluck(:id) proposal_notification_ids = ProposalNotification.where(author_id: id).pluck(:id)
hide hide
@@ -189,6 +190,7 @@ class User < ActiveRecord::Base
Debate.hide_all debates_ids Debate.hide_all debates_ids
Comment.hide_all comments_ids Comment.hide_all comments_ids
Proposal.hide_all proposal_ids Proposal.hide_all proposal_ids
Budget::Investment.hide_all investment_ids
ProposalNotification.hide_all proposal_notification_ids ProposalNotification.hide_all proposal_notification_ids
end end