Skip to content

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

Fix account address update with anonymous user (#8123)

Tomasz Szymański9b9be1134613
diff --git a/saleor/graphql/account/mutations/base.py b/saleor/graphql/account/mutations/base.py
index 8e0ef149b9..91a2dcfe99 100644
--- a/saleor/graphql/account/mutations/base.py
+++ b/saleor/graphql/account/mutations/base.py
@@ -46,7 +46,7 @@ def can_edit_address(context, address):
requester = get_user_or_app_from_context(context)
if requester.has_perm(AccountPermissions.MANAGE_USERS):
return True
- if not context.app:
+ if not context.app and not context.user.is_anonymous:
return requester.addresses.filter(pk=address.pk).exists()
diff --git a/saleor/graphql/account/tests/test_account.py b/saleor/graphql/account/tests/test_account.py
index 8ec2756c42..c5c4f2dffd 100644
--- a/saleor/graphql/account/tests/test_account.py
+++ b/saleor/graphql/account/tests/test_account.py
@@ -3322,6 +3322,20 @@ def test_customer_update_own_address(
assert address_obj.city == address_data["city"].upper()
+def test_update_address_as_anonymous_user(
+ api_client, customer_user, graphql_address_data
+):
+ query = ACCOUNT_ADDRESS_UPDATE_MUTATION
+ address_obj = customer_user.addresses.first()
+
+ variables = {
+ "addressId": graphene.Node.to_global_id("Address", address_obj.id),
+ "address": graphql_address_data,
+ }
+ response = api_client.post_graphql(query, variables)
+ assert_no_permission(response)
+
+
def test_customer_update_own_address_not_updated_when_validation_fails(
user_api_client, customer_user, graphql_address_data
):