mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-27 01:43:22 +00:00
Adding visibility permissions for standing orders
This commit is contained in:
@@ -135,6 +135,13 @@ module OpenFoodNetwork
|
||||
Schedule.joins(:order_cycles).where(order_cycles: { id: OrderCycle.accessible_by(@user).pluck(:id) }).select("DISTINCT schedules.*")
|
||||
end
|
||||
|
||||
def editable_standing_orders
|
||||
StandingOrder.where('standing_orders.shop_id IN (?)', managed_enterprises)
|
||||
end
|
||||
|
||||
def visible_standing_orders
|
||||
editable_standing_orders
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
|
||||
@@ -140,10 +140,10 @@ FactoryGirl.define do
|
||||
|
||||
factory :standing_order, :class => StandingOrder do
|
||||
shop { FactoryGirl.create :enterprise }
|
||||
schedule
|
||||
schedule { FactoryGirl.create(:schedule, order_cycles: [create(:simple_order_cycle, coordinator: shop)]) }
|
||||
customer { create(:customer, enterprise: shop) }
|
||||
payment_method
|
||||
shipping_method
|
||||
payment_method { create(:payment_method, distributors: [shop]) }
|
||||
shipping_method { create(:shipping_method, distributors: [shop]) }
|
||||
begins_at { 1.month.ago }
|
||||
end
|
||||
|
||||
|
||||
@@ -394,5 +394,16 @@ module OpenFoodNetwork
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "finding visible standing orders" do
|
||||
let!(:so1) { create(:standing_order) }
|
||||
let!(:so2) { create(:standing_order) }
|
||||
|
||||
it "returns standing orders placed with managed shops" do
|
||||
expect(permissions).to receive(:managed_enterprises) { [so1.shop] }
|
||||
|
||||
expect(permissions.visible_standing_orders).to eq [so1]
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user