Allow admins and managers to see restricted shops

This commit is contained in:
Maikel Linke
2016-03-25 12:04:26 +11:00
parent 5149c5118b
commit c4f499d518
2 changed files with 31 additions and 2 deletions

View File

@@ -9,8 +9,14 @@ module ShopHelper
end
def require_customer?
current_distributor.require_login? && !(
spree_current_user.andand.customer_of current_distributor
current_distributor.require_login? && !user_is_related_to_distributor?
end
def user_is_related_to_distributor?
spree_current_user.present? && (
spree_current_user.admin? ||
spree_current_user.enterprises.include?(current_distributor) ||
spree_current_user.customer_of(current_distributor)
)
end
end

View File

@@ -301,6 +301,29 @@ feature "As a consumer I want to shop with a distributor", js: true do
expect(page).to have_content product.name
end
end
context "as a manager" do
let!(:role) { create(:enterprise_role, user: user, enterprise: distributor) }
it "shows just products" do
visit shop_path
expect(page).to have_no_content "This shop is for customers only."
expect(page).to have_content product.name
end
end
context "as the owner" do
before do
distributor.owner = user
distributor.save!
end
it "shows just products" do
visit shop_path
expect(page).to have_no_content "This shop is for customers only."
expect(page).to have_content product.name
end
end
end
end
end