Search customers in enterprises

This commit is contained in:
Bing Xie
2016-08-26 15:36:51 +10:00
parent 1877bea68d
commit fd32152e88
3 changed files with 10 additions and 6 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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