mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-30 21:27:17 +00:00
Add to OC permission allows adding distributors to order cycle
This commit is contained in:
@@ -8,7 +8,11 @@ module OrderCyclesHelper
|
||||
end
|
||||
|
||||
def coordinating_enterprises
|
||||
Enterprise.is_distributor.managed_by(spree_current_user).by_name
|
||||
order_cycle_hub_enterprises
|
||||
end
|
||||
|
||||
def order_cycle_hub_enterprises
|
||||
OpenFoodNetwork::Permissions.new(spree_current_user).order_cycle_enterprises.is_distributor.by_name
|
||||
end
|
||||
|
||||
def order_cycle_local_remote_class(distributor, order_cycle)
|
||||
|
||||
@@ -50,7 +50,7 @@
|
||||
%tr.products{'ng-show' => 'exchange.showProducts'}
|
||||
= render 'exchange_distributed_products_form'
|
||||
|
||||
= select_tag :new_distributor_id, options_from_collection_for_select(Enterprise.is_distributor.managed_by(spree_current_user).by_name, :id, :name), {'ng-model' => 'new_distributor_id'}
|
||||
= select_tag :new_distributor_id, options_from_collection_for_select(order_cycle_hub_enterprises, :id, :name), {'ng-model' => 'new_distributor_id'}
|
||||
= f.submit 'Add distributor', 'ng-click' => 'addDistributor($event)'
|
||||
|
||||
.actions
|
||||
|
||||
@@ -441,11 +441,16 @@ feature %q{
|
||||
let!(:supplier_permitted) { create(:supplier_enterprise, name: 'Permitted supplier') }
|
||||
let!(:distributor_managed) { create(:distributor_enterprise, name: 'Managed distributor') }
|
||||
let!(:distributor_unmanaged) { create(:distributor_enterprise, name: 'Unmanaged Distributor') }
|
||||
let!(:distributor_permitted) { create(:distributor_enterprise, name: 'Permitted distributor') }
|
||||
let!(:distributor_managed_fee) { create(:enterprise_fee, enterprise: distributor_managed, name: 'Managed distributor fee') }
|
||||
let!(:supplier_permitted_relationship) do
|
||||
create(:enterprise_relationship, parent: supplier_permitted, child: supplier_managed,
|
||||
permissions_list: [:add_to_order_cycle])
|
||||
end
|
||||
let!(:distributor_permitted_relationship) do
|
||||
create(:enterprise_relationship, parent: distributor_permitted, child: distributor_managed,
|
||||
permissions_list: [:add_to_order_cycle])
|
||||
end
|
||||
|
||||
before do
|
||||
product = create(:product, supplier: supplier_managed)
|
||||
@@ -493,6 +498,8 @@ feature %q{
|
||||
|
||||
select 'Managed distributor', from: 'new_distributor_id'
|
||||
click_button 'Add distributor'
|
||||
select 'Permitted distributor', from: 'new_distributor_id'
|
||||
click_button 'Add distributor'
|
||||
|
||||
# Should only have suppliers / distributors listed which the user is managing or
|
||||
# has E2E permission to add products to order cycles
|
||||
@@ -511,13 +518,13 @@ feature %q{
|
||||
end
|
||||
|
||||
scenario "editing an order cycle" do
|
||||
oc = create(:simple_order_cycle, { suppliers: [supplier_managed, supplier_permitted, supplier_unmanaged], coordinator: supplier_managed, distributors: [distributor_managed, distributor_unmanaged], name: 'Order Cycle 1' } )
|
||||
oc = create(:simple_order_cycle, { suppliers: [supplier_managed, supplier_permitted, supplier_unmanaged], coordinator: supplier_managed, distributors: [distributor_managed, distributor_permitted, distributor_unmanaged], name: 'Order Cycle 1' } )
|
||||
|
||||
visit edit_admin_order_cycle_path(oc)
|
||||
|
||||
# I should not see exchanges for supplier_unmanaged or distributor_unmanaged
|
||||
page.all('tr.supplier').count.should == 2
|
||||
page.all('tr.distributor').count.should == 1
|
||||
page.all('tr.distributor').count.should == 2
|
||||
|
||||
# When I save, then those exchanges should remain
|
||||
click_button 'Update'
|
||||
@@ -526,7 +533,7 @@ feature %q{
|
||||
oc.reload
|
||||
oc.suppliers.sort.should == [supplier_managed, supplier_permitted, supplier_unmanaged].sort
|
||||
oc.coordinator.should == supplier_managed
|
||||
oc.distributors.sort.should == [distributor_managed, distributor_unmanaged].sort
|
||||
oc.distributors.sort.should == [distributor_managed, distributor_permitted, distributor_unmanaged].sort
|
||||
end
|
||||
|
||||
scenario "cloning an order cycle" do
|
||||
|
||||
Reference in New Issue
Block a user