Files
nairobi/app/helpers/admin_budget_investments_helper.rb
Javi Martín 5332ae609e Filter investments only by assigned staff
In commit 74083df1 we added the possibility to assign administrators and
valuators to budgets, so they would only manage the budgets they're
assigned to.

However, when filtering projects, we were still showing all
administrators and valuators as options to filter investments. It makes
more sense to only show the valuators and administrators assigned to the
current budget.

Note this change only affects the view, and so malicious users could
technically send any other administrator or valuator ID. In this case,
they would get empty results since those administrators/valuators
wouldn't have any investments assigned, so taking this case into account
is not necessary.
2020-09-08 19:11:38 +02:00

37 lines
1.0 KiB
Ruby

module AdminBudgetInvestmentsHelper
def advanced_menu_visibility
if params[:advanced_filters].empty? &&
params["min_total_supports"].blank? &&
params["max_total_supports"].blank?
"hide"
else
""
end
end
def init_advanced_menu
params[:advanced_filters] = [] unless params[:advanced_filters]
end
def admin_select_options(budget)
budget.administrators.with_user.map { |v| [v.description_or_name, v.id] }.sort_by { |a| a[0] }
end
def valuator_or_group_select_options(budget)
valuator_group_select_options + valuator_select_options(budget)
end
def valuator_select_options(budget)
budget.valuators.order("description ASC").order("users.email ASC").includes(:user).
map { |v| [v.description_or_email, "valuator_#{v.id}"] }
end
def valuator_group_select_options
ValuatorGroup.order("name ASC").map { |g| [g.name, "group_#{g.id}"] }
end
def investment_tags_select_options(budget, context)
budget.investments.tags_on(context).order(:name).pluck(:name)
end
end