Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Limit products visibility by user

akjanikdda91fb58616
diff --git a/saleor/graphql/api.py b/saleor/graphql/api.py
index 11c9e767f7..631175dd2a 100644
--- a/saleor/graphql/api.py
+++ b/saleor/graphql/api.py
@@ -59,8 +59,8 @@ class Query(graphene.ObjectType):
def resolve_product(self, info, id):
return get_node(info, id, only_type=Product)
- def resolve_products(self, info, **kwargs):
- return resolve_products(info)
+ def resolve_products(self, info, category_id=None, **kwargs):
+ return resolve_products(info, category_id)
def resolve_attributes(self, info, in_category=None, **kwargs):
return resolve_attributes(in_category, info)
diff --git a/saleor/graphql/product/types.py b/saleor/graphql/product/types.py
index 733b11a595..dadb74eac4 100644
--- a/saleor/graphql/product/types.py
+++ b/saleor/graphql/product/types.py
@@ -5,7 +5,8 @@ from graphene_django.filter import DjangoFilterConnectionField
from ...product import models
from ...product.templatetags.product_images import product_first_image
-from ...product.utils import get_availability, get_product_costs_data
+from ...product.utils import (
+ get_availability, get_product_costs_data, products_visible_to_user)
from ..core.decorators import permission_required
from ..core.filters import DistinctFilterSet
from ..core.types import (
@@ -254,13 +255,13 @@ def resolve_categories(info, level=None):
qs = qs.filter(level=level)
return qs.distinct()
-
def resolve_products(info, category_id):
+ user = info.context.user
if category_id is not None:
category = get_node(info, category_id, only_type=Category)
- return models.Product.objects.filter(
- category=category).distinct()
- return models.Product.objects.all().distinct()
+ return products_visible_to_user(
+ user=user).filter(category=category).distinct()
+ return products_visible_to_user(user=user).distinct()
def resolve_attributes(category_id, info):