Skip to content

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

Hide private metadata in notification payloads (#9849)

Marcin Gębalaeacffa70e721
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 1ec9a04649..fe9323f972 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -2,7 +2,8 @@
All notable, unreleased changes to this project will be documented in this file. For the released changes, please visit the [Releases](https://github.com/mirumee/saleor/releases) page.
-# Unreleased
+## Unreleased
+
- Migrate order line id from int to UUID - #9637 by @IKarbowiak
- Changed the order line `id` from `int` to `UUID`, the old ids still can be used
for old order lines.
@@ -14,6 +15,12 @@ All notable, unreleased changes to this project will be documented in this file.
- Changed the order discount `id` from `int` to `UUID`, the old ids still can be used
for old order discounts.
+
+## Breaking
+
+- Hide private metadata in notification payloads - #9849 by @maarcingebala
+ - From now on, the `private_metadata` field in `NOTIFY_USER` webhook payload is deprecated and it will return an empty dictionary. This change also affects `AdminEmailPlugin`, `UserEmailPlugin`, an d `SendgridEmailPlugin`.
+
### Other changes
- Fix for sending incorrect prices to Avatax - #9633 by @korycins
- PREVIEW_FEATURE: Add mutations for managing a payment transaction attached to order/checkout. - #9564 by @korycins
diff --git a/saleor/account/notifications.py b/saleor/account/notifications.py
index 4d924b5f24..32ef7f012d 100644
--- a/saleor/account/notifications.py
+++ b/saleor/account/notifications.py
@@ -12,7 +12,7 @@ from .models import User
def get_default_user_payload(user: User):
- return {
+ payload = {
"id": to_global_id_or_none(user),
"email": user.email,
"first_name": user.first_name,
@@ -23,6 +23,10 @@ def get_default_user_payload(user: User):
"metadata": user.metadata,
"language_code": user.language_code,
}
+ # Deprecated: override private_metadata with empty dict as it shouldn't be returned
+ # in the payload (see SALEOR-7046). Should be removed in Saleor 4.0.
+ payload["private_metadata"] = {}
+ return payload
def get_user_custom_payload(user: User):
diff --git a/saleor/account/tests/test_notifications.py b/saleor/account/tests/test_notifications.py
index efb286c845..33a7ef6213 100644
--- a/saleor/account/tests/test_notifications.py
+++ b/saleor/account/tests/test_notifications.py
@@ -20,7 +20,7 @@ def test_get_default_user_payload(customer_user):
"last_name": customer_user.last_name,
"is_staff": customer_user.is_staff,
"is_active": customer_user.is_active,
- "private_metadata": customer_user.private_metadata,
+ "private_metadata": {},
"metadata": customer_user.metadata,
"language_code": customer_user.language_code,
}
diff --git a/saleor/graphql/payment/tests/queries/test_payment_sources.py b/saleor/graphql/payment/tests/queries/test_payment_sources.py
index 1bc070ce73..8bd6684180 100644
--- a/saleor/graphql/payment/tests/queries/test_payment_sources.py
+++ b/saleor/graphql/payment/tests/queries/test_payment_sources.py
@@ -23,9 +23,8 @@ def dummy_customer_id():
def test_store_payment_gateway_meta(customer_user, braintree_customer_id):
gateway_name = "braintree"
meta_key = "BRAINTREE.customer_id"
- META = {meta_key: braintree_customer_id}
store_customer_id(customer_user, gateway_name, braintree_customer_id)
- assert customer_user.private_metadata == META
+ assert customer_user.private_metadata[meta_key] == braintree_customer_id
customer_user.refresh_from_db()
assert fetch_customer_id(customer_user, gateway_name) == braintree_customer_id
diff --git a/saleor/order/notifications.py b/saleor/order/notifications.py
index 7ebe9d5637..db2fa58933 100644
--- a/saleor/order/notifications.py
+++ b/saleor/order/notifications.py
@@ -262,6 +262,9 @@ def get_default_order_payload(order: "Order", redirect_url: str = ""):
**get_discounts_payload(order),
}
)
+ # Deprecated: override private_metadata with empty dict as it shouldn't be returned
+ # in the payload (see SALEOR-7046). Should be removed in Saleor 4.0.
+ order_payload["private_metadata"] = {}
return order_payload
diff --git a/saleor/order/tests/test_notifications.py b/saleor/order/tests/test_notifications.py
index 55fcfa713a..472f9f3328 100644
--- a/saleor/order/tests/test_notifications.py
+++ b/saleor/order/tests/test_notifications.py
@@ -31,7 +31,7 @@ def test_get_custom_order_payload(order):
"id": to_global_id_or_none(order),
"number": order.id,
"private_metadata": {},
- "metadata": {},
+ "metadata": order.metadata,
"status": "unfulfilled",
"language_code": "en",
"currency": "USD",
@@ -248,7 +248,7 @@ def test_get_default_order_payload(order_line):
"collection_point_name": order.collection_point_name,
"status": order.status,
"metadata": order.metadata,
- "private_metadata": order.private_metadata,
+ "private_metadata": {},
"shipping_price_net_amount": order.shipping_price_net_amount,
"shipping_price_gross_amount": order.shipping_price_gross_amount,
"order_details_url": f"{redirect_url}?token={order.id}",
diff --git a/saleor/tests/fixtures.py b/saleor/tests/fixtures.py
index 16588c86b9..ff66c47e91 100644
--- a/saleor/tests/fixtures.py
+++ b/saleor/tests/fixtures.py
@@ -675,6 +675,8 @@ def customer_user(address): # pylint: disable=W0613
default_shipping_address=default_address,
first_name="Leslie",
last_name="Wade",
+ metadata={"key": "value"},
+ private_metadata={"secret_key": "secret_value"},
)
user.addresses.add(default_address)
user._password = "password"
@@ -781,6 +783,8 @@ def order(customer_user, channel_USD):
user_email=customer_user.email,
user=customer_user,
origin=OrderOrigin.CHECKOUT,
+ metadata={"key": "value"},
+ private_metadata={"secret_key": "secret_value"},
)
return order
diff --git a/saleor/webhook/tests/test_webhook_payloads.py b/saleor/webhook/tests/test_webhook_payloads.py
index fd9a02e24d..a93b31368f 100644
--- a/saleor/webhook/tests/test_webhook_payloads.py
+++ b/saleor/webhook/tests/test_webhook_payloads.py
@@ -722,8 +722,8 @@ def test_generate_invoice_payload(fulfilled_order):
"token": str(invoice.order.id),
"id": graphene.Node.to_global_id("Order", invoice.order.id),
"language_code": "en",
- "private_metadata": {},
- "metadata": {},
+ "private_metadata": invoice.order.private_metadata,
+ "metadata": invoice.order.metadata,
"created": ANY,
"status": "fulfilled",
"origin": OrderOrigin.CHECKOUT,