Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Add optional support for reporting resource limits via a stub field in shop (#6967)
NyanKiyoshi3f6f224fad8c
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 195c260d84..4873465fe9 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -18,6 +18,8 @@ All notable, unreleased changes to this project will be documented in this file.- Fix variant resolver on `DigitalContent` - #6983 by @fowczarek- Fix race condition on `send_fulfillment-confirmation` - #6988 by @fowczarek- Fix resolver by id and slug for product and product variant - #6985 by @d-wysocki+- Add optional support for reporting resource limits via a stub field in `shop` - #6967 by @NyanKiyoshi+### Breaking- Multichannel MVP: Multicurrency - #6242 by @fowczarek @d-wysockidiff --git a/saleor/graphql/schema.graphql b/saleor/graphql/schema.graphqlindex 0cd0fe136b..7a2054286e 100644--- a/saleor/graphql/schema.graphql+++ b/saleor/graphql/schema.graphql@@ -2328,6 +2328,19 @@ type LanguageDisplay {language: String!}+type LimitInfo {+ currentUsage: Limits!+ allowedUsage: Limits!+}++type Limits {+ channels: Int+ orders: Int+ productVariants: Int+ staffUsers: Int+ warehouses: Int+}+type Manifest {identifier: String!version: String!@@ -5049,6 +5062,7 @@ type Shop {companyAddress: AddresscustomerSetPasswordUrl: StringstaffNotificationRecipients: [StaffNotificationRecipient]+ limits: LimitInfo!version: String!}diff --git a/saleor/graphql/shop/tests/test_shop.py b/saleor/graphql/shop/tests/test_shop.pyindex 1204fae560..e7d1639f05 100644--- a/saleor/graphql/shop/tests/test_shop.py+++ b/saleor/graphql/shop/tests/test_shop.py@@ -26,6 +26,21 @@ COUNTRIES_QUERY = """}"""+LIMIT_INFO_QUERY = """+ {+ shop {+ limits {+ currentUsage {+ channels+ }+ allowedUsage {+ channels+ }+ }+ }+ }+"""+def test_query_countries(user_api_client):response = user_api_client.post_graphql(COUNTRIES_QUERY % {"attributes": ""})@@ -1297,3 +1312,25 @@ def test_version_query_as_staff_user(staff_api_client):response = staff_api_client.post_graphql(API_VERSION_QUERY)content = get_graphql_content(response)assert content["data"]["shop"]["version"] == __version__+++def test_cannot_get_shop_limit_info_when_not_staff(user_api_client):+ query = LIMIT_INFO_QUERY+ response = user_api_client.post_graphql(query)+ assert_no_permission(response)+++def test_get_shop_limit_info_returns_null_by_default(staff_api_client):+ query = LIMIT_INFO_QUERY+ response = staff_api_client.post_graphql(query)+ content = get_graphql_content(response)+ assert content == {+ "data": {+ "shop": {+ "limits": {+ "currentUsage": {"channels": None},+ "allowedUsage": {"channels": None},+ }+ }+ }+ }diff --git a/saleor/graphql/shop/types.py b/saleor/graphql/shop/types.pyindex 0622b71aa8..36530897d7 100644--- a/saleor/graphql/shop/types.py+++ b/saleor/graphql/shop/types.py@@ -19,7 +19,11 @@ from ..core.connection import CountableDjangoObjectTypefrom ..core.enums import WeightUnitsEnumfrom ..core.types.common import CountryDisplay, LanguageDisplay, Permissionfrom ..core.utils import str_to_enum-from ..decorators import permission_required, staff_member_or_app_required+from ..decorators import (+ permission_required,+ staff_member_or_app_required,+ staff_member_required,+)from ..menu.dataloaders import MenuByIdLoaderfrom ..menu.types import Menufrom ..shipping.types import ShippingMethod@@ -64,6 +68,27 @@ class ExternalAuthentication(graphene.ObjectType):name = graphene.String(description="Name of external authentication plugin.")+class Limits(graphene.ObjectType):+ channels = graphene.Int()+ orders = graphene.Int()+ product_variants = graphene.Int()+ staff_users = graphene.Int()+ warehouses = graphene.Int()+++class LimitInfo(graphene.ObjectType):+ current_usage = graphene.Field(+ Limits,+ required=True,+ description="Defines the current resource usage.",+ )+ allowed_usage = graphene.Field(+ Limits,+ required=True,+ description="Defines the allowed maximum resource usage, null means unlimited.",+ )++class Shop(graphene.ObjectType):available_payment_gateways = graphene.List(graphene.NonNull(PaymentGateway),@@ -171,6 +196,11 @@ class Shop(graphene.ObjectType):description="List of staff notification recipients.",required=False,)+ limits = graphene.Field(+ LimitInfo,+ required=True,+ description="Resource limitations and current usage if any set for a shop",+ )version = graphene.String(description="Saleor API version.", required=True)class Meta:@@ -336,6 +366,11 @@ class Shop(graphene.ObjectType):def resolve_staff_notification_recipients(_, info):return account_models.StaffNotificationRecipient.objects.all()+ @staticmethod+ @staff_member_required+ def resolve_limits(_, _info):+ return LimitInfo(current_usage=Limits(), allowed_usage=Limits())+@staticmethod@staff_member_or_app_requireddef resolve_version(_, _info):