mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-10 03:30:22 +00:00
Search customers in enterprises
This commit is contained in:
@@ -16,10 +16,14 @@ Spree::Admin::SearchController.class_eval do
|
||||
render :users
|
||||
end
|
||||
|
||||
def users_with_customers_ams
|
||||
enterprise_ids = spree_current_user.enterprises.map &:id
|
||||
|
||||
def users_with_ams
|
||||
users_without_ams
|
||||
render json: @users, each_serializer: Api::Admin::UserSerializer
|
||||
customers = Customer.ransack({m: 'or', email_start: params[:q], name_start: params[:q]})
|
||||
.result(distinct: true)
|
||||
.where(enterprise_id: enterprise_ids)
|
||||
|
||||
render json: customers, each_serializer: Api::Admin::CustomerSerializer
|
||||
end
|
||||
alias_method_chain :users, :ams
|
||||
alias_method_chain :users, :customers_ams
|
||||
end
|
||||
|
||||
@@ -93,7 +93,7 @@ class AbilityDecorator
|
||||
user.enterprises.include? enterprise_fee.enterprise
|
||||
end
|
||||
|
||||
can [:admin, :known_users], :search
|
||||
can [:admin, :known_users, :users], :search
|
||||
|
||||
can [:admin, :show], :account
|
||||
|
||||
|
||||
@@ -498,7 +498,7 @@ module Spree
|
||||
end
|
||||
|
||||
it "should have the ability to search for users which share management of its enterprises" do
|
||||
should have_ability([:admin, :known_users], for: :search)
|
||||
should have_ability([:admin, :known_users, :users], for: :search)
|
||||
should_not have_ability([:users], for: :search)
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user