mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-27 21:06:49 +00:00
Fix Spree:Ability
This commit is contained in:
@@ -189,7 +189,9 @@ module Spree
|
||||
:seo, :group_buy_options,
|
||||
:bulk_update, :clone, :delete,
|
||||
:destroy], Spree::Product do |product|
|
||||
OpenFoodNetwork::Permissions.new(user).managed_product_enterprises.include? product.supplier
|
||||
OpenFoodNetwork::Permissions.new(user).managed_product_enterprises.include?(
|
||||
product.variants.first.supplier
|
||||
)
|
||||
end
|
||||
|
||||
can [:admin, :index, :bulk_update, :destroy, :destroy_variant, :clone], :products_v3
|
||||
@@ -198,11 +200,11 @@ module Spree
|
||||
can [:admin, :index, :read, :edit,
|
||||
:update, :search, :delete, :destroy], Spree::Variant do |variant|
|
||||
OpenFoodNetwork::Permissions.new(user).
|
||||
managed_product_enterprises.include? variant.product.supplier
|
||||
managed_product_enterprises.include? variant.supplier
|
||||
end
|
||||
|
||||
can [:admin, :index, :read, :update, :bulk_update, :bulk_reset], VariantOverride do |vo|
|
||||
next false unless vo.hub.present? && vo.variant&.product&.supplier.present?
|
||||
next false unless vo.hub.present? && vo.variant&.supplier.present?
|
||||
|
||||
hub_auth = OpenFoodNetwork::Permissions.new(user).
|
||||
variant_override_hubs.
|
||||
@@ -210,14 +212,14 @@ module Spree
|
||||
|
||||
producer_auth = OpenFoodNetwork::Permissions.new(user).
|
||||
variant_override_producers.
|
||||
include? vo.variant.product.supplier
|
||||
include? vo.variant.supplier
|
||||
|
||||
hub_auth && producer_auth
|
||||
end
|
||||
|
||||
can [:admin, :create, :update], InventoryItem do |ii|
|
||||
next false unless ii.enterprise.present? &&
|
||||
ii.variant&.product&.supplier.present?
|
||||
ii.variant&.supplier.present?
|
||||
|
||||
hub_auth = OpenFoodNetwork::Permissions.new(user).
|
||||
variant_override_hubs.
|
||||
@@ -225,7 +227,7 @@ module Spree
|
||||
|
||||
producer_auth = OpenFoodNetwork::Permissions.new(user).
|
||||
variant_override_producers.
|
||||
include? ii.variant.product.supplier
|
||||
include? ii.variant.supplier
|
||||
|
||||
hub_auth && producer_auth
|
||||
end
|
||||
|
||||
@@ -304,9 +304,9 @@ RSpec.describe Spree::Ability do
|
||||
let(:d1) { create(:distributor_enterprise) }
|
||||
let(:d2) { create(:distributor_enterprise) }
|
||||
|
||||
let(:p1) { create(:product, supplier: s1) }
|
||||
let(:p2) { create(:product, supplier: s2) }
|
||||
let(:p_related) { create(:product, supplier: s_related) }
|
||||
let(:p1) { create(:product, supplier_id: s1.id) }
|
||||
let(:p2) { create(:product, supplier_id: s2.id) }
|
||||
let(:p_related) { create(:product, supplier_id: s_related.id) }
|
||||
|
||||
let(:er1) { create(:enterprise_relationship, parent: s1, child: d1) }
|
||||
let(:er2) { create(:enterprise_relationship, parent: d1, child: s1) }
|
||||
@@ -796,8 +796,7 @@ RSpec.describe Spree::Ability do
|
||||
describe "permissions for variant overrides" do
|
||||
let!(:distributor) { create(:distributor_enterprise) }
|
||||
let!(:producer) { create(:supplier_enterprise) }
|
||||
let!(:product) { create(:product, supplier: producer) }
|
||||
let!(:variant) { create(:variant, product:) }
|
||||
let!(:variant) { create(:variant, supplier: producer) }
|
||||
let!(:variant_override) { create(:variant_override, hub: distributor, variant:) }
|
||||
|
||||
subject { user }
|
||||
|
||||
Reference in New Issue
Block a user