mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-04-06 07:29:16 +00:00
Allow admins and managers to see restricted shops
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user