diff --git a/app/controllers/spree/admin/search_controller.rb b/app/controllers/spree/admin/search_controller.rb index 1ddb023b3a..7032a17e22 100644 --- a/app/controllers/spree/admin/search_controller.rb +++ b/app/controllers/spree/admin/search_controller.rb @@ -18,19 +18,28 @@ module Spree end def customers - @customers = [] - if spree_current_user.enterprises.pluck(:id).include? search_params[:distributor_id].to_i - @customers = Customer. - ransack(m: 'or', email_start: search_params[:q], first_name_start: search_params[:q], - last_name_start: search_params[:q]). - result. - where(enterprise_id: search_params[:distributor_id].to_i) - end - render json: @customers, each_serializer: ::Api::Admin::CustomerSerializer + render json: load_customers, each_serializer: ::Api::Admin::CustomerSerializer end private + def load_customers + return [] unless valid_enterprise_given? + + Customer.ransack( + m: 'or', email_start: search_params[:q], + first_name_start: search_params[:q], last_name_start: search_params[:q] + ).result.where(enterprise_id: search_params[:distributor_id].to_i) + end + + def valid_enterprise_given? + return true if spree_current_user.admin? + + spree_current_user.enterprises.where( + id: search_params[:distributor_id].to_i + ).present? + end + def ransack_hash { m: 'or', diff --git a/spec/system/admin/order_spec.rb b/spec/system/admin/order_spec.rb index c25d5c13c1..ef43bd5b2d 100644 --- a/spec/system/admin/order_spec.rb +++ b/spec/system/admin/order_spec.rb @@ -755,7 +755,6 @@ describe ' end it "finds a customer by name" do - pending("issue #9684") serching_for_customers end end