mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-27 06:05:19 +00:00
Add new enterprise customers search API
This commit is contained in:
@@ -16,14 +16,18 @@ Spree::Admin::SearchController.class_eval do
|
||||
render :users
|
||||
end
|
||||
|
||||
def users_with_customers_ams
|
||||
enterprise_ids = spree_current_user.enterprises.map &:id
|
||||
|
||||
customers = Customer.ransack({m: 'or', email_start: params[:q], name_start: params[:q]})
|
||||
def customers
|
||||
@customers = Customer.ransack({m: 'or', email_start: params[:q], name_start: params[:q]})
|
||||
.result(distinct: true)
|
||||
.where(enterprise_id: enterprise_ids)
|
||||
.where(enterprise_id: params[:distributor_id])
|
||||
|
||||
render json: customers, each_serializer: Api::Admin::CustomerSerializer
|
||||
render json: @customers, each_serializer: Api::Admin::CustomerSerializer
|
||||
end
|
||||
alias_method_chain :users, :customers_ams
|
||||
|
||||
def users_with_ams
|
||||
users_without_ams
|
||||
render json: @users, each_serializer: Api::Admin::UserSerializer
|
||||
end
|
||||
|
||||
alias_method_chain :users, :ams
|
||||
end
|
||||
|
||||
@@ -93,7 +93,7 @@ class AbilityDecorator
|
||||
user.enterprises.include? enterprise_fee.enterprise
|
||||
end
|
||||
|
||||
can [:admin, :known_users, :users], :search
|
||||
can [:admin, :known_users, :customers], :search
|
||||
|
||||
can [:admin, :show], :account
|
||||
|
||||
|
||||
Reference in New Issue
Block a user