From 12d7db3dd6509c969d66228e7b422a77aa79f24f Mon Sep 17 00:00:00 2001 From: Maikel Linke Date: Tue, 27 Sep 2022 11:32:40 +1000 Subject: [PATCH] More efficient enterprise access check --- app/controllers/spree/admin/search_controller.rb | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/app/controllers/spree/admin/search_controller.rb b/app/controllers/spree/admin/search_controller.rb index df96618fc0..3d4e95f0b5 100644 --- a/app/controllers/spree/admin/search_controller.rb +++ b/app/controllers/spree/admin/search_controller.rb @@ -19,12 +19,7 @@ module Spree def customers @customers = [] - enterprise_ids = if spree_current_user.admin? - Enterprise.pluck(:id) - else - spree_current_user.enterprises.pluck(:id) - end - if enterprise_ids.include? search_params[:distributor_id].to_i + if enterprises.where(id: search_params[:distributor_id].to_i).present? @customers = Customer. ransack(m: 'or', email_start: search_params[:q], first_name_start: search_params[:q], last_name_start: search_params[:q]). @@ -50,6 +45,14 @@ module Spree def search_params params.permit(:q, :distributor_id).to_h.with_indifferent_access end + + def enterprises + if spree_current_user.admin? + Enterprise.all + else + spree_current_user.enterprises + end + end end end end