Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow producer to edit their products on hubs' orders #13113

Open
wants to merge 22 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion app/controllers/spree/admin/variants_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,10 @@ def update
end

def search
scoper = OpenFoodNetwork::ScopeVariantsForSearch.new(variant_search_params)
scoper = OpenFoodNetwork::ScopeVariantsForSearch.new(
variant_search_params,
spree_current_user
)
@variants = scoper.search
render json: @variants, each_serializer: ::Api::Admin::VariantSerializer
end
Expand Down
10 changes: 8 additions & 2 deletions lib/open_food_network/scope_variants_for_search.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@

module OpenFoodNetwork
class ScopeVariantsForSearch
def initialize(params)
def initialize(params, spree_current_user)
@params = params
@spree_current_user = spree_current_user
end

def search
Expand All @@ -20,13 +21,14 @@ def search
scope_to_schedule if params[:schedule_id]
scope_to_order_cycle if params[:order_cycle_id]
scope_to_distributor if params[:distributor_id]
scope_to_supplier if spree_current_user.can_manage_line_items_in_orders_only?

@variants
end

private

attr_reader :params
attr_reader :params, :spree_current_user

def search_params
{ product_name_cont: params[:q], sku_cont: params[:q], product_sku_cont: params[:q] }
Expand Down Expand Up @@ -96,5 +98,9 @@ def scope_variants_to_distributor(variants, distributor)
# Filtering could be a problem on scoped variants.
variants.each { |v| scoper.scope(v) }
end

def scope_to_supplier
@variants = @variants.where(supplier_id: spree_current_user.enterprises.ids)
end
end
end