Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Deprecate digital contents (#18761)
Mikailc900de124903
diff --git a/saleor/graphql/product/mutations/digital_contents.py b/saleor/graphql/product/mutations/digital_contents.pyindex 032b37e9ed..275cab5353 100644--- a/saleor/graphql/product/mutations/digital_contents.py+++ b/saleor/graphql/product/mutations/digital_contents.py@@ -5,6 +5,7 @@ from ....core.db.connection import allow_writerfrom ....core.exceptions import PermissionDeniedfrom ....permission.enums import ProductPermissionsfrom ....product import models+from ....product.deprecations import deprecated_digital_contentfrom ....product.error_codes import ProductErrorCodefrom ...core import ResolveInfofrom ...core.context import ChannelContext, disallow_replica_in_context@@ -116,9 +117,8 @@ class DigitalContentCreate(BaseMutation):return data@classmethod- def perform_mutation( # type: ignore[override]- cls, _root, info: ResolveInfo, /, input, variant_id: str- ):+ @deprecated_digital_content+ def perform_mutation(cls, _root, info: ResolveInfo, /, input, variant_id: str):variant = cls.get_node_or_error(info, variant_id, field="id", only_type=ProductVariant)@@ -180,10 +180,9 @@ class DigitalContentDelete(BaseMutation):permissions = (ProductPermissions.MANAGE_PRODUCTS,)@classmethod+ @deprecated_digital_content@allow_writer()- def mutate( # type: ignore[override]- cls, root, info: ResolveInfo, /, *, variant_id: str- ):+ def mutate(cls, root, info: ResolveInfo, /, *, variant_id: str):disallow_replica_in_context(info.context)if not cls.check_permissions(info.context):raise PermissionDenied(permissions=cls._meta.permissions)@@ -222,6 +221,7 @@ class DigitalContentUpdate(BaseMutation):support_private_meta_field = True@classmethod+ @deprecated_digital_contentdef clean_input(cls, info: ResolveInfo, data):use_default_settings = data.get("use_default_settings")if use_default_settings:diff --git a/saleor/graphql/product/schema.py b/saleor/graphql/product/schema.pyindex a4f24a4b41..afcb6c4b27 100644--- a/saleor/graphql/product/schema.py+++ b/saleor/graphql/product/schema.py@@ -5,6 +5,9 @@ from promise import Promisefrom ...permission.enums import ProductPermissionsfrom ...permission.utils import has_one_of_permissionsfrom ...product import models+from ...product.deprecations import (+ DEPRECATION_WARNING_MESSAGE as DEPRECATION_DIGITAL_CONTENT,+)from ...product.models import ALL_PRODUCTS_PERMISSIONSfrom ...product.search import search_productsfrom ..channel.dataloaders.by_self import ChannelBySlugLoader@@ -160,6 +163,7 @@ class ProductQueries(graphene.ObjectType):ProductPermissions.MANAGE_PRODUCTS,],doc_category=DOC_CATEGORY_PRODUCTS,+ deprecation_reason=DEPRECATION_DIGITAL_CONTENT,)digital_contents = ConnectionField(DigitalContentCountableConnection,@@ -168,6 +172,7 @@ class ProductQueries(graphene.ObjectType):ProductPermissions.MANAGE_PRODUCTS,],doc_category=DOC_CATEGORY_PRODUCTS,+ deprecation_reason=DEPRECATION_DIGITAL_CONTENT,)categories = FilterConnectionField(CategoryCountableConnection,@@ -723,11 +728,19 @@ class ProductMutations(graphene.ObjectType):product_type_reorder_attributes = ProductTypeReorderAttributes.Field()product_reorder_attribute_values = ProductReorderAttributeValues.Field()- digital_content_create = DigitalContentCreate.Field()- digital_content_delete = DigitalContentDelete.Field()- digital_content_update = DigitalContentUpdate.Field()+ digital_content_create = DigitalContentCreate.Field(+ deprecation_reason=DEPRECATION_DIGITAL_CONTENT+ )+ digital_content_delete = DigitalContentDelete.Field(+ deprecation_reason=DEPRECATION_DIGITAL_CONTENT+ )+ digital_content_update = DigitalContentUpdate.Field(+ deprecation_reason=DEPRECATION_DIGITAL_CONTENT+ )- digital_content_url_create = DigitalContentUrlCreate.Field()+ digital_content_url_create = DigitalContentUrlCreate.Field(+ deprecation_reason=DEPRECATION_DIGITAL_CONTENT+ )product_variant_create = ProductVariantCreate.Field()product_variant_delete = ProductVariantDelete.Field()diff --git a/saleor/graphql/schema.graphql b/saleor/graphql/schema.graphqlindex 47a6cb4d61..1ecf612243 100644--- a/saleor/graphql/schema.graphql+++ b/saleor/graphql/schema.graphql@@ -316,7 +316,7 @@ type Query {digitalContent("""ID of the digital content."""id: ID!- ): DigitalContent @doc(category: "Products")+ ): DigitalContent @doc(category: "Products") @deprecated(reason: "Support for Digital Content is deprecated and will be removed in Saleor v3.23.0. This functionality is legacy and undocumented, and is not part of the supported API. Users should not rely on this behavior.")"""List of digital content.@@ -339,7 +339,7 @@ type Query {Retrieve the last n elements from the list. Note that the system only allows fetching a maximum of 100 objects in a single query."""last: Int- ): DigitalContentCountableConnection @doc(category: "Products")+ ): DigitalContentCountableConnection @doc(category: "Products") @deprecated(reason: "Support for Digital Content is deprecated and will be removed in Saleor v3.23.0. This functionality is legacy and undocumented, and is not part of the supported API. Users should not rely on this behavior.")"""List of the shop's categories."""categories(@@ -16039,7 +16039,7 @@ type Mutation {"""ID of a product variant to upload digital content."""variantId: ID!- ): DigitalContentCreate @doc(category: "Products")+ ): DigitalContentCreate @doc(category: "Products") @deprecated(reason: "Support for Digital Content is deprecated and will be removed in Saleor v3.23.0. This functionality is legacy and undocumented, and is not part of the supported API. Users should not rely on this behavior.")"""Remove digital content assigned to given variant.@@ -16049,7 +16049,7 @@ type Mutation {digitalContentDelete("""ID of a product variant with digital content to remove."""variantId: ID!- ): DigitalContentDelete @doc(category: "Products")+ ): DigitalContentDelete @doc(category: "Products") @deprecated(reason: "Support for Digital Content is deprecated and will be removed in Saleor v3.23.0. This functionality is legacy and undocumented, and is not part of the supported API. Users should not rely on this behavior.")"""Updates digital content.@@ -16062,7 +16062,7 @@ type Mutation {"""ID of a product variant with digital content to update."""variantId: ID!- ): DigitalContentUpdate @doc(category: "Products")+ ): DigitalContentUpdate @doc(category: "Products") @deprecated(reason: "Support for Digital Content is deprecated and will be removed in Saleor v3.23.0. This functionality is legacy and undocumented, and is not part of the supported API. Users should not rely on this behavior.")"""Generate new URL to digital content.@@ -16072,7 +16072,7 @@ type Mutation {digitalContentUrlCreate("""Fields required to create a new url."""input: DigitalContentUrlCreateInput!- ): DigitalContentUrlCreate @doc(category: "Products")+ ): DigitalContentUrlCreate @doc(category: "Products") @deprecated(reason: "Support for Digital Content is deprecated and will be removed in Saleor v3.23.0. This functionality is legacy and undocumented, and is not part of the supported API. Users should not rely on this behavior.")"""Creates a new variant for a product.diff --git a/saleor/product/deprecations.py b/saleor/product/deprecations.pynew file mode 100644index 0000000000..533ca7ae13--- /dev/null+++ b/saleor/product/deprecations.py@@ -0,0 +1,23 @@+import functools+import warnings++from saleor.core.deprecations import SaleorDeprecationWarning++DEPRECATION_WARNING_MESSAGE = (+ "Support for Digital Content is deprecated and will be removed in Saleor v3.23.0. "+ "This functionality is legacy and undocumented, and is not part of the supported "+ "API. Users should not rely on this behavior."+)+++def deprecated_digital_content(func):+ @functools.wraps(func)+ def _inner(*args, **kwargs):+ warnings.warn(+ message=DEPRECATION_WARNING_MESSAGE,+ category=SaleorDeprecationWarning,+ stacklevel=1,+ )+ return func(*args, **kwargs)++ return _innerdiff --git a/saleor/product/views.py b/saleor/product/views.pyindex 11c1869237..6d30979770 100644--- a/saleor/product/views.py+++ b/saleor/product/views.py@@ -5,6 +5,7 @@ from django.conf import settingsfrom django.http import FileResponse, HttpResponseNotFoundfrom django.shortcuts import get_object_or_404+from .deprecations import deprecated_digital_contentfrom .models import DigitalContentUrlfrom .utils.digital_products import (digital_content_url_is_valid,@@ -12,6 +13,7 @@ from .utils.digital_products import ()+@deprecated_digital_contentdef digital_product(request, token: str) -> FileResponse | HttpResponseNotFound:"""Return the direct download link to content if given token is still valid."""