diff --git a/app/helpers/order_cycles_helper.rb b/app/helpers/order_cycles_helper.rb index dfd957a143..23ac74e944 100644 --- a/app/helpers/order_cycles_helper.rb +++ b/app/helpers/order_cycles_helper.rb @@ -62,6 +62,10 @@ module OrderCyclesHelper OrderCycle.active.with_distributor(@distributor).present? end + def order_cycles_simple_view + !OpenFoodNetwork::Permissions.new(spree_current_user).can_manage_complex_order_cycles? + end + def order_cycles_enabled? OpenFoodNetwork::FeatureToggle.enabled? :order_cycles end diff --git a/app/views/admin/order_cycles/_row.html.haml b/app/views/admin/order_cycles/_row.html.haml index 75e84de025..e95adff38f 100644 --- a/app/views/admin/order_cycles/_row.html.haml +++ b/app/views/admin/order_cycles/_row.html.haml @@ -4,15 +4,17 @@ %td= link_to order_cycle.name, main_app.edit_admin_order_cycle_path(order_cycle) %td= order_cycle_form.text_field :orders_open_at, :class => 'datetimepicker', :value => order_cycle.orders_open_at %td= order_cycle_form.text_field :orders_close_at, :class => 'datetimepicker', :value => order_cycle.orders_close_at - %td.suppliers - - order_cycle.suppliers.managed_by(spree_current_user).each do |s| - = s.name - %br/ - %td= order_cycle.coordinator.name - %td.distributors - - order_cycle.distributors.managed_by(spree_current_user).each do |d| - = d.name - %br/ + + - unless order_cycles_simple_view + %td.suppliers + - order_cycle.suppliers.managed_by(spree_current_user).each do |s| + = s.name + %br/ + %td= order_cycle.coordinator.name + %td.distributors + - order_cycle.distributors.managed_by(spree_current_user).each do |d| + = d.name + %br/ %td.products - variant_images = capture do diff --git a/app/views/admin/order_cycles/index.html.haml b/app/views/admin/order_cycles/index.html.haml index 1fac06f507..f649a4ab47 100644 --- a/app/views/admin/order_cycles/index.html.haml +++ b/app/views/admin/order_cycles/index.html.haml @@ -13,9 +13,10 @@ %col %col{'style' => 'width: 20%;'} %col{'style' => 'width: 20%;'} - %col - %col - %col + - unless order_cycles_simple_view + %col + %col + %col %col %col %col @@ -25,9 +26,10 @@ %th Name %th Open %th Close - %th Suppliers - %th Coordinator - %th Distributors + - unless order_cycles_simple_view + %th Suppliers + %th Coordinator + %th Distributors %th Products %th.actions %th.actions diff --git a/lib/open_food_network/permissions.rb b/lib/open_food_network/permissions.rb index 3d5df1e804..678e70941a 100644 --- a/lib/open_food_network/permissions.rb +++ b/lib/open_food_network/permissions.rb @@ -4,6 +4,12 @@ module OpenFoodNetwork @user = user end + def can_manage_complex_order_cycles? + managed_and_related_enterprises_with(:add_to_order_cycle).any? do |e| + e.sells == 'any' + end + end + # Find enterprises that an admin is allowed to add to an order cycle def order_cycle_enterprises managed_and_related_enterprises_with :add_to_order_cycle diff --git a/spec/features/admin/order_cycles_spec.rb b/spec/features/admin/order_cycles_spec.rb index febd966109..354be34671 100644 --- a/spec/features/admin/order_cycles_spec.rb +++ b/spec/features/admin/order_cycles_spec.rb @@ -572,7 +572,27 @@ feature %q{ occ = OrderCycle.last occ.name.should == "COPY OF #{oc.name}" end + end + + describe "as an enterprise user selling only my own produce" do + let(:user) { create_enterprise_user } + let(:enterprise) { create(:enterprise, is_primary_producer: true, sells: 'own') } + + use_short_wait + + before do + user.enterprise_roles.create! enterprise: enterprise + login_to_admin_as user + end + + it "shows me an index of order cycles without enterprise columns" do + create(:order_cycle, coordinator: enterprise) + visit admin_order_cycles_path + page.should_not have_selector 'th', text: 'SUPPLIERS' + page.should_not have_selector 'th', text: 'COORDINATOR' + page.should_not have_selector 'th', text: 'DISTRIBUTORS' + end end