mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-28 01:53:25 +00:00
Users with only a profile-level enterprise see only menu items for enterprise management
This commit is contained in:
@@ -14,8 +14,7 @@ class AbilityDecorator
|
||||
|
||||
|
||||
def can_manage_products?(user)
|
||||
can_manage_enterprises? user
|
||||
# ( user.enterprises.map(&:type) & %w(single full) ).any?
|
||||
( user.enterprises.map(&:type) & %w(single full) ).any?
|
||||
end
|
||||
|
||||
|
||||
|
||||
@@ -83,6 +83,7 @@ FactoryGirl.define do
|
||||
|
||||
factory :enterprise, :class => Enterprise do
|
||||
sequence(:name) { |n| "Enterprise #{n}" }
|
||||
type 'full'
|
||||
description 'enterprise'
|
||||
long_description '<p>Hello, world!</p><p>This is a paragraph.</p>'
|
||||
email 'enterprise@example.com'
|
||||
|
||||
@@ -6,10 +6,12 @@ feature %q{
|
||||
} do
|
||||
include AuthenticationWorkflow
|
||||
include WebHelper
|
||||
include AdminHelper
|
||||
|
||||
let!(:user) { create_enterprise_user }
|
||||
let!(:supplier1) { create(:supplier_enterprise, name: 'Supplier 1') }
|
||||
let!(:supplier2) { create(:supplier_enterprise, name: 'Supplier 2') }
|
||||
let(:supplier_profile) { create(:supplier_enterprise, name: 'Supplier profile', type: 'profile') }
|
||||
let!(:distributor1) { create(:distributor_enterprise, name: 'Distributor 3') }
|
||||
let!(:distributor2) { create(:distributor_enterprise, name: 'Distributor 4') }
|
||||
|
||||
@@ -74,6 +76,25 @@ feature %q{
|
||||
end
|
||||
end
|
||||
|
||||
describe "with only a profile-level enterprise" do
|
||||
before do
|
||||
user.enterprise_roles.create! enterprise: supplier_profile
|
||||
login_to_admin_as user
|
||||
end
|
||||
|
||||
it "shows me only menu items for enterprise management" do
|
||||
page.should have_admin_menu_item 'Dashboard'
|
||||
page.should have_admin_menu_item 'Enterprises'
|
||||
|
||||
['Orders', 'Products', 'Reports', 'Configuration', 'Promotions', 'Users', 'Order Cycles'].each do |menu_item_name|
|
||||
page.should_not have_admin_menu_item menu_item_name
|
||||
end
|
||||
end
|
||||
|
||||
it "shows me a cut-down dashboard"
|
||||
it "shows me only profile options on the enterprises page"
|
||||
end
|
||||
|
||||
describe "system management lockdown" do
|
||||
before do
|
||||
user.enterprise_roles.create!(enterprise: supplier1)
|
||||
|
||||
@@ -6,6 +6,46 @@ module Spree
|
||||
|
||||
describe User do
|
||||
|
||||
describe "broad permissions" do
|
||||
subject { AbilityDecorator.new(user) }
|
||||
let(:user) { create(:user) }
|
||||
let(:enterprise_full) { create(:enterprise, type: 'full') }
|
||||
let(:enterprise_single) { create(:enterprise, type: 'single') }
|
||||
let(:enterprise_profile) { create(:enterprise, type: 'profile') }
|
||||
|
||||
describe "managing enterprises" do
|
||||
it "can manage enterprises when the user has at least one enterprise assigned" do
|
||||
user.enterprise_roles.create! enterprise: enterprise_full
|
||||
subject.can_manage_enterprises?(user).should be_true
|
||||
end
|
||||
|
||||
it "can't otherwise" do
|
||||
subject.can_manage_enterprises?(user).should be_false
|
||||
end
|
||||
end
|
||||
|
||||
describe "managing products" do
|
||||
it "can when a user manages a 'full' type enterprise" do
|
||||
user.enterprise_roles.create! enterprise: enterprise_full
|
||||
subject.can_manage_products?(user).should be_true
|
||||
end
|
||||
|
||||
it "can when a user manages a 'single' type enterprise" do
|
||||
user.enterprise_roles.create! enterprise: enterprise_single
|
||||
subject.can_manage_products?(user).should be_true
|
||||
end
|
||||
|
||||
it "can't when a user manages a 'profile' type enterprise" do
|
||||
user.enterprise_roles.create! enterprise: enterprise_profile
|
||||
subject.can_manage_products?(user).should be_false
|
||||
end
|
||||
|
||||
it "can't when the user manages no enterprises" do
|
||||
subject.can_manage_products?(user).should be_false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'Roles' do
|
||||
|
||||
# create enterprises
|
||||
|
||||
5
spec/support/request/admin_helper.rb
Normal file
5
spec/support/request/admin_helper.rb
Normal file
@@ -0,0 +1,5 @@
|
||||
module AdminHelper
|
||||
def have_admin_menu_item(menu_item_name)
|
||||
have_selector "ul[data-hook='admin_tabs'] li", text: menu_item_name
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user