Products and inventory reports scopes products to visible in permissions

This commit is contained in:
Rob Harrington
2015-05-20 16:19:08 +10:00
parent 8132f07d88
commit 65a6329132

View File

@@ -9,7 +9,7 @@ module OpenFoodNetwork
def header
[
"Supplier",
"Supplier",
"Producer Suburb",
"Product",
"Product Properties",
@@ -36,6 +36,16 @@ module OpenFoodNetwork
end
end
def permissions
return @permissions unless @permissions.nil?
@permissions = OpenFoodNetwork::Permissions.new(@user)
end
def visible_products
return @visible_products unless @visible_products.nil?
@visible_products = permissions.visible_products
end
def variants
filter(child_variants) + filter(master_variants)
end
@@ -43,7 +53,7 @@ module OpenFoodNetwork
def child_variants
Spree::Variant.where(:is_master => false)
.joins(:product)
.merge(Spree::Product.managed_by(@user))
.merge(visible_products)
.order("spree_products.name")
end
@@ -53,7 +63,7 @@ module OpenFoodNetwork
.where("(select spree_variants.id from spree_variants as other_spree_variants
WHERE other_spree_variants.product_id = spree_variants.product_id
AND other_spree_variants.is_master = 'f' LIMIT 1) IS NULL")
.merge(Spree::Product.managed_by(@user))
.merge(visible_products)
.order("spree_products.name")
end