Skip to content

Commit

Permalink
Remove permissions for fetching user and product inside review query
Browse files Browse the repository at this point in the history
  • Loading branch information
MahirSalahin committed Aug 19, 2024
1 parent ec397ac commit 3040466
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions saleor/graphql/review/types.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import graphene
import logging
from ...review import models
from ...account.models import User
from ..account.types import User as UserType
from ...product.models import Product
from ..product.types import Product as ProductType
from ...core.utils import build_absolute_uri
from ..core.types import ModelObjectType
from ..core.scalars import DateTime
Expand All @@ -12,7 +15,6 @@
from ..meta.types import ObjectWithMetadata
from .enums import ReviewMediaType
from ..product.schema import ProductQueries
from ..account.schema import AccountQueries


class Review(ModelObjectType[models.Review]):
Expand All @@ -33,8 +35,16 @@ class Review(ModelObjectType[models.Review]):
required=True, description="Number of times the review is voted as helpful"
)

user = AccountQueries.user
product = ProductQueries.product
user = graphene.Field(
lambda: UserType,
required=True,
description="User who created the review",
)
product = graphene.Field(
lambda: ProductType,
required=True,
description="Product being reviewed",
)
media_by_id = graphene.Field(
lambda: ReviewMedia,
id=graphene.Argument(graphene.ID, description="ID of a review media."),
Expand All @@ -53,14 +63,15 @@ class Meta:

@staticmethod
def resolve_user(root: ModelObjectType[models.Review], info):
return AccountQueries.resolve_user(
root, info, id=graphene.Node.to_global_id("User", root.user)
)
return User.objects.get(pk=root.user)

@staticmethod
def resolve_product(root: ModelObjectType[models.Review], info):
return ProductQueries.resolve_product(
root, info, id=graphene.Node.to_global_id("Product", root.product)
root,
info,
id=graphene.Node.to_global_id("Product", root.product),
channel="default-channel",
)

@staticmethod
Expand Down

0 comments on commit 3040466

Please sign in to comment.