Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
add permission to address query for service account
Krzysztof Świątek6b573522b33b
diff --git a/saleor/graphql/account/resolvers.py b/saleor/graphql/account/resolvers.pyindex c96a3fe265..87767bcddb 100644--- a/saleor/graphql/account/resolvers.py+++ b/saleor/graphql/account/resolvers.py@@ -156,7 +156,7 @@ def resolve_address(info, id):user = info.context.userservice_account = info.context.service_account_model, address_pk = graphene.Node.from_global_id(id)- if service_account:+ if service_account and service_account.has_perm(AccountPermissions.MANAGE_USERS):return models.Address.objects.filter(pk=address_pk).first()if user and not user.is_anonymous:return user.addresses.filter(id=address_pk).first()diff --git a/tests/api/test_account.py b/tests/api/test_account.pyindex 55e937b137..bb063fe1da 100644--- a/tests/api/test_account.py+++ b/tests/api/test_account.py@@ -3038,9 +3038,13 @@ def test_address_query_as_not_owner(assert not data-def test_address_query_as_service_account(- service_account_api_client, service_account, address_other_country+def test_address_query_as_service_account_with_permission(+ service_account_api_client,+ service_account,+ address_other_country,+ permission_manage_users,):+ service_account.permissions.add(permission_manage_users)variables = {"id": graphene.Node.to_global_id("Address", address_other_country.pk)}response = service_account_api_client.post_graphql(ADDRESS_QUERY, variables)content = get_graphql_content(response)@@ -3048,6 +3052,15 @@ def test_address_query_as_service_account(assert data["country"]["code"] == address_other_country.country.code+def test_address_query_as_service_account_without_permission(+ service_account_api_client, service_account, address_other_country+):++ variables = {"id": graphene.Node.to_global_id("Address", address_other_country.pk)}+ response = service_account_api_client.post_graphql(ADDRESS_QUERY, variables)+ assert_no_permission(response)++def test_address_query_as_anonymous_user(api_client, address_other_country):variables = {"id": graphene.Node.to_global_id("Address", address_other_country.pk)}response = api_client.post_graphql(ADDRESS_QUERY, variables)