Skip to content

Commit

Permalink
add producer edit ability in bulk_order
Browse files Browse the repository at this point in the history
  • Loading branch information
chahmedejaz committed Feb 1, 2025
1 parent 44ede16 commit 764ea78
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
4 changes: 3 additions & 1 deletion app/models/spree/ability.rb
Original file line number Diff line number Diff line change
Expand Up @@ -348,14 +348,16 @@ def add_manage_line_items_abilities(user)

order.variants.any? { |variant| user_enterprises_ids.include?(variant.supplier_id) }
end
can [:index, :create, :destroy, :update], Spree::LineItem do |item|
can [:admin, :index, :create, :destroy, :update], Spree::LineItem do |item|
user.enterprises.ids.include?(item.variant.supplier_id)
end

can [:index, :create, :add, :read, :edit, :update], Spree::Shipment do |shipment|
order = shipment.order
order.variants.any? { |variant| user.enterprises.ids.include?(variant.supplier_id) }
end

can [:admin, :visible], Enterprise
end

def add_relationship_management_abilities(user)
Expand Down
8 changes: 7 additions & 1 deletion app/services/permissions/order.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,13 @@ def visible_line_items

# Any line items that I can edit
def editable_line_items
Spree::LineItem.where(order_id: editable_orders.select(:id))
if @user.can_manage_line_items_in_orders_only?
Spree::LineItem.joins(:variant).where(
spree_variants: { supplier_id: @permissions.managed_enterprises.select("enterprises.id") }
)
else
Spree::LineItem.where(order_id: editable_orders.select(:id))
end
end

private
Expand Down

0 comments on commit 764ea78

Please sign in to comment.