Skip to content

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

Fix channel visibility for staff users (#6492)

Filip Owczarek4f1f13fb75a8
diff --git a/saleor/graphql/channel/schema.py b/saleor/graphql/channel/schema.py
index f3740df1e1..514edf1e45 100644
--- a/saleor/graphql/channel/schema.py
+++ b/saleor/graphql/channel/schema.py
@@ -1,7 +1,6 @@
import graphene
-from ...core.permissions import ChannelPermissions
-from ..decorators import permission_required
+from ..decorators import staff_member_or_app_required
from .mutations import (
ChannelActivate,
ChannelCreate,
@@ -23,11 +22,11 @@ class ChannelQueries(graphene.ObjectType):
graphene.NonNull(Channel), description="List of all channels."
)
- @permission_required(ChannelPermissions.MANAGE_CHANNELS)
+ @staff_member_or_app_required
def resolve_channel(self, info, id=None, **kwargs):
return resolve_channel(info, id)
- @permission_required(ChannelPermissions.MANAGE_CHANNELS)
+ @staff_member_or_app_required
def resolve_channels(self, _info, **kwargs):
return resolve_channels()
diff --git a/saleor/graphql/channel/tests/test_channel_queries.py b/saleor/graphql/channel/tests/test_channel_queries.py
index 260c6cda22..ed5de515e5 100644
--- a/saleor/graphql/channel/tests/test_channel_queries.py
+++ b/saleor/graphql/channel/tests/test_channel_queries.py
@@ -13,15 +13,11 @@ query {
"""
-def test_query_channels_as_staff_user(
- staff_api_client, permission_manage_channels, channel_USD, channel_PLN
-):
+def test_query_channels_as_staff_user(staff_api_client, channel_USD, channel_PLN):
# given
# when
- response = staff_api_client.post_graphql(
- QUERY_CHANNELS, {}, permissions=(permission_manage_channels,)
- )
+ response = staff_api_client.post_graphql(QUERY_CHANNELS, {})
content = get_graphql_content(response)
# then
@@ -39,15 +35,11 @@ def test_query_channels_as_staff_user(
} in channels
-def test_query_channels_as_app(
- app_api_client, permission_manage_channels, channel_USD, channel_PLN
-):
+def test_query_channels_as_app(app_api_client, channel_USD, channel_PLN):
# given
# when
- response = app_api_client.post_graphql(
- QUERY_CHANNELS, {}, permissions=(permission_manage_channels,)
- )
+ response = app_api_client.post_graphql(QUERY_CHANNELS, {})
content = get_graphql_content(response)
# then
@@ -97,17 +89,13 @@ query getChannel($id: ID!){
"""
-def test_query_channel_as_staff_user(
- staff_api_client, permission_manage_channels, channel_USD
-):
+def test_query_channel_as_staff_user(staff_api_client, channel_USD):
# given
channel_id = graphene.Node.to_global_id("Channel", channel_USD.id)
variables = {"id": channel_id}
# when
- response = staff_api_client.post_graphql(
- QUERY_CHANNEL, variables, permissions=(permission_manage_channels,)
- )
+ response = staff_api_client.post_graphql(QUERY_CHANNEL, variables)
content = get_graphql_content(response)
# then
@@ -118,15 +106,13 @@ def test_query_channel_as_staff_user(
assert channel_data["currencyCode"] == channel_USD.currency_code
-def test_query_channel_as_app(app_api_client, permission_manage_channels, channel_USD):
+def test_query_channel_as_app(app_api_client, channel_USD):
# given
channel_id = graphene.Node.to_global_id("Channel", channel_USD.id)
variables = {"id": channel_id}
# when
- response = app_api_client.post_graphql(
- QUERY_CHANNEL, variables, permissions=(permission_manage_channels,)
- )
+ response = app_api_client.post_graphql(QUERY_CHANNEL, variables)
content = get_graphql_content(response)
# then
diff --git a/saleor/graphql/product/types/products.py b/saleor/graphql/product/types/products.py
index 05f5679568..d6a1afde88 100644
--- a/saleor/graphql/product/types/products.py
+++ b/saleor/graphql/product/types/products.py
@@ -297,16 +297,17 @@ class ProductVariant(ChannelContextTypeWithMetadata, CountableDjangoObjectType):
if not root.channel_slug:
return None
+ channel_slug = str(root.channel_slug)
context = info.context
product = ProductByIdLoader(context).load(root.node.product_id)
product_channel_listing = ProductChannelListingByProductIdAndChannelSlugLoader(
context
- ).load((root.node.product_id, root.channel_slug))
+ ).load((root.node.product_id, channel_slug))
variant_channel_listing = VariantChannelListingByVariantIdAndChannelSlugLoader(
context
- ).load((root.node.id, root.channel_slug))
+ ).load((root.node.id, channel_slug))
collections = CollectionsByProductIdLoader(context).load(root.node.product_id)
- channel = ChannelBySlugLoader(context).load(root.channel_slug)
+ channel = ChannelBySlugLoader(context).load(channel_slug)
def calculate_pricing_info(discounts):
def calculate_pricing_with_channel(channel):
@@ -582,7 +583,7 @@ class Product(ChannelContextTypeWithMetadata, CountableDjangoObjectType):
return None
context = info.context
- channel_slug = root.channel_slug
+ channel_slug = str(root.channel_slug)
product_channel_listing = ProductChannelListingByProductIdAndChannelSlugLoader(
context
).load((root.node.id, channel_slug))