Skip to content

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

Add anonymization of user email. Enable accountRegister mutation for demo mode (#9802)

Maciej Korycinski8b814fb76a17
diff --git a/saleor/demo/settings.py b/saleor/demo/settings.py
index 9e8121dab8..2229ec0aa0 100644
--- a/saleor/demo/settings.py
+++ b/saleor/demo/settings.py
@@ -52,6 +52,7 @@ ROOT_EMAIL = os.environ.get("ROOT_EMAIL")
# (see saleor.demo.management.commands.populatedb).
INSTALLED_APPS.remove("saleor.core")
INSTALLED_APPS += ["saleor.demo", "saleor.core"]
+ENABLE_ACCOUNT_CONFIRMATION_BY_EMAIL = False
def _get_project_name_from_url(url: str) -> str:
diff --git a/saleor/graphql/middleware.py b/saleor/graphql/middleware.py
index afbca2debc..879556f99c 100644
--- a/saleor/graphql/middleware.py
+++ b/saleor/graphql/middleware.py
@@ -6,6 +6,7 @@ from .views import GraphQLView
class ReadOnlyMiddleware:
ALLOWED_MUTATIONS = [
+ "accountRegister",
"checkoutAddPromoCode",
"checkoutBillingAddressUpdate",
"checkoutComplete",
diff --git a/saleor/plugins/anonymize/plugin.py b/saleor/plugins/anonymize/plugin.py
index 7f2baf57ff..7ad3dce9f7 100644
--- a/saleor/plugins/anonymize/plugin.py
+++ b/saleor/plugins/anonymize/plugin.py
@@ -1,6 +1,10 @@
from typing import TYPE_CHECKING, Any, Optional
-from ...core.anonymize import obfuscate_address, obfuscate_email
+from django.utils import timezone
+from django.utils.crypto import get_random_string
+from faker import Faker
+
+from ...core.anonymize import obfuscate_address
from ..base_plugin import BasePlugin
from . import obfuscate_order
@@ -8,6 +12,8 @@ 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."""
@@ -43,5 +49,9 @@ class AnonymizePlugin(BasePlugin):
order.save()
def customer_created(self, customer: "User", previous_value: Any) -> Any:
- customer.email = obfuscate_email(customer.email)
+ customer.first_name = faker.first_name()
+ customer.last_name = faker.last_name()
+ timestamp = str(timezone.now())
+ email = f"{hash(timestamp + get_random_string(5))}@anonymous-demo-email"
+ customer.email = email
customer.save()