mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Merge pull request #9686 from jibees/9684-fix-search-customer-in-order-creation-for-super-admin
Admin, New Order, Search customer: As a super admin, search for customer within all enterprises
This commit is contained in:
@@ -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',
|
||||
|
||||
@@ -755,7 +755,6 @@ describe '
|
||||
end
|
||||
|
||||
it "finds a customer by name" do
|
||||
pending("issue #9684")
|
||||
serching_for_customers
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user