Add scope to get investments visible to a valuator
Using this method makes it more obvious that we're loading the same investments in the budgets index as in the investments index.
This commit is contained in:
@@ -11,7 +11,7 @@ class Valuation::Budgets::RowComponent < ApplicationComponent
|
||||
def investments
|
||||
return Budget::Investment.none unless budget.valuating_or_later?
|
||||
|
||||
budget.investments.visible_to_valuators.by_valuator(current_user.valuator)
|
||||
budget.investments.visible_to_valuator(current_user.valuator)
|
||||
end
|
||||
|
||||
def valuation_open_investments_count
|
||||
|
||||
@@ -17,7 +17,8 @@ class Valuation::BudgetInvestmentsController < Valuation::BaseController
|
||||
def index
|
||||
@heading_filters = heading_filters
|
||||
@investments = if current_user.valuator? && @budget.present?
|
||||
@budget.investments.visible_to_valuators.scoped_filter(params_for_current_valuator, @current_filter)
|
||||
@budget.investments.visible_to_valuator(current_user.valuator)
|
||||
.scoped_filter(filtered_params, @current_filter)
|
||||
.order(cached_votes_up: :desc)
|
||||
.page(params[:page])
|
||||
else
|
||||
@@ -72,7 +73,7 @@ class Valuation::BudgetInvestmentsController < Valuation::BaseController
|
||||
end
|
||||
|
||||
def heading_filters
|
||||
investments = @budget.investments.by_valuator(current_user.valuator&.id).visible_to_valuators.distinct
|
||||
investments = @budget.investments.visible_to_valuator(current_user.valuator).distinct
|
||||
investment_headings = Budget::Heading.where(id: investments.pluck(:heading_id)).sort_by(&:name)
|
||||
|
||||
all_headings_filter = [
|
||||
@@ -92,9 +93,8 @@ class Valuation::BudgetInvestmentsController < Valuation::BaseController
|
||||
end
|
||||
end
|
||||
|
||||
def params_for_current_valuator
|
||||
Budget::Investment.filter_params(params).to_h.merge({ valuator_id: current_user.valuator.id,
|
||||
budget_id: @budget.id })
|
||||
def filtered_params
|
||||
Budget::Investment.filter_params(params).to_h.except(:valuator_id).merge(budget_id: @budget.id)
|
||||
end
|
||||
|
||||
def valuation_params
|
||||
|
||||
@@ -100,6 +100,7 @@ class Budget
|
||||
scope :by_heading, ->(heading_id) { where(heading_id: heading_id) }
|
||||
scope :by_admin, ->(admin_id) { where(administrator_id: admin_id) }
|
||||
scope :by_tag, ->(tag_name) { tagged_with(tag_name).distinct }
|
||||
scope :visible_to_valuator, ->(valuator) { visible_to_valuators.by_valuator(valuator) }
|
||||
|
||||
scope :for_render, -> { includes(:heading) }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user