Enterprise user selling own produce only sees simple order cycle listing

This commit is contained in:
Rohan Mitchell
2014-10-17 10:52:36 +11:00
parent 6a6f603754
commit 694dd0c329
5 changed files with 49 additions and 15 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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