Skip to content

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

Remove the anonymize plugin

Ania Warzecha5590b2fae6db
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 87fc80b90b..5bd44fa8ce 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -9,6 +9,7 @@ All notable, unreleased changes to this project will be documented in this file.
- Include transaction item in refund flow - #15590 by @korycins
### Breaking changes
+- Remove the `anonymize` plugin. Use `saleor/core/utils/anonymization` code instead. - by @aniav
### GraphQL API
- Add `translatableContent` to all translation types; add translated object id to all translatable content types - #15617 by @zedzior
diff --git a/saleor/plugins/anonymize/__init__.py b/saleor/plugins/anonymize/__init__.py
deleted file mode 100644
index 96f8c81b10..0000000000
--- a/saleor/plugins/anonymize/__init__.py
+++ /dev/null
@@ -1,12 +0,0 @@
-from ...core.anonymize import obfuscate_address, obfuscate_email
-
-
-def obfuscate_order(order):
- order.user_email = obfuscate_email(order.user_email)
- if order.shipping_address:
- order.shipping_address = obfuscate_address(order.shipping_address)
- order.shipping_address.save()
- if order.billing_address:
- order.billing_address = obfuscate_address(order.billing_address)
- order.billing_address.save()
- return order
diff --git a/saleor/plugins/anonymize/plugin.py b/saleor/plugins/anonymize/plugin.py
deleted file mode 100644
index a3f7550802..0000000000
--- a/saleor/plugins/anonymize/plugin.py
+++ /dev/null
@@ -1,70 +0,0 @@
-from typing import TYPE_CHECKING, Any, Optional
-
-from django.utils import timezone
-from django.utils.crypto import get_random_string
-from faker import Faker
-
-from ...account import search
-from ...core.anonymize import obfuscate_address
-from ...core.postgres import FlatConcatSearchVector
-from ...order.search import prepare_order_search_vector_value
-from ..base_plugin import BasePlugin
-from . import obfuscate_order
-
-if TYPE_CHECKING:
- from ...account.models import Address, User
- from ...order.models import Order
-
-faker = Faker()
-
-
-class AnonymizePlugin(BasePlugin):
- """Anonymize all user data in the checkout, user profile and its orders."""
-
- PLUGIN_NAME = "Anonymize"
- PLUGIN_ID = "mirumee.anonymize"
- DEFAULT_ACTIVE = True
- PLUGIN_DESCRIPTION = (
- "Anonymize customer's personal data in the checkout, such as shipping "
- "or billing address, email and phone number."
- )
- CONFIGURATION_PER_CHANNEL = False
-
- def __init__(self, *args, **kwargs):
- super().__init__(*args, **kwargs)
- self.active = True
-
- def change_user_address(
- self,
- address: "Address",
- address_type: Optional[str],
- user: Optional["User"],
- save: bool,
- previous_value: "Address",
- ) -> "Address":
- if address.phone:
- address.phone = "" # type: ignore
- address = obfuscate_address(address)
- if save:
- address.save()
- return address
-
- def order_created(self, order: "Order", previous_value: Any):
- order = obfuscate_order(order)
- order.search_vector = FlatConcatSearchVector(
- *prepare_order_search_vector_value(order)
- )
- order.save()
-
- def customer_created(self, customer: "User", previous_value: Any) -> Any:
- customer.first_name = faker.first_name()
- customer.last_name = faker.last_name()
- timestamp = str(timezone.now())
- email = (
- f"{hash(timestamp + get_random_string(length=5))}@anonymous-demo-email.com"
- )
- customer.email = email
- customer.search_document = search.prepare_user_search_document_value(
- customer, attach_addresses_data=False
- )
- customer.save()
diff --git a/saleor/plugins/tests/test_plugins.py b/saleor/plugins/tests/test_plugins.py
index df4a4fcd5c..50fadcb851 100644
--- a/saleor/plugins/tests/test_plugins.py
+++ b/saleor/plugins/tests/test_plugins.py
@@ -1,4 +1,3 @@
-from ..anonymize.plugin import AnonymizePlugin
from ..base_plugin import ConfigurationTypeField
from ..manager import get_plugins_manager
from ..tests.sample_plugins import PluginSample
@@ -231,17 +230,3 @@ def test_base_plugin__append_config_structure_to_config(settings):
]
plugin._append_config_structure(config)
assert config == config_with_structure
-
-
-def test_change_user_address_in_anonymize_plugin_reset_phone(address, settings):
- settings.PLUGINS = ["saleor.plugins.anonymize.plugin.AnonymizePlugin"]
- manager = get_plugins_manager(allow_replica=False)
- anonymize_plugin = manager.get_plugin(AnonymizePlugin.PLUGIN_ID)
-
- # ensure that phone is set
- assert address.phone
-
- new_address = anonymize_plugin.change_user_address(
- address=address, address_type=None, user=None, save=True, previous_value=address
- )
- assert not new_address.phone