Skip to content

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

Fix reviews remarks

fowczarek73dbc98efe57
diff --git a/saleor/graphql/account/mutations.py b/saleor/graphql/account/mutations.py
index 3265c9ea95..dde0a33a16 100644
--- a/saleor/graphql/account/mutations.py
+++ b/saleor/graphql/account/mutations.py
@@ -154,8 +154,6 @@ class CustomerUpdate(CustomerCreate):
class LoggedCustomerUpdate(CustomerCreate):
class Arguments:
- id = graphene.ID(
- description='ID of a customer to update.', required=True)
input = UserAddressInput(
description='Fields required to update logged in customer.',
required=True)
@@ -172,9 +170,8 @@ class LoggedCustomerUpdate(CustomerCreate):
@classmethod
def mutate(cls, root, info, **data):
- if data['id'] == '':
- user = info.context.user
- data['id'] = graphene.Node.to_global_id('User', user.id)
+ user = info.context.user
+ data['id'] = graphene.Node.to_global_id('User', user.id)
return super().mutate(root, info, **data)
diff --git a/saleor/graphql/account/resolvers.py b/saleor/graphql/account/resolvers.py
index 81105c0e1c..1ce711d396 100644
--- a/saleor/graphql/account/resolvers.py
+++ b/saleor/graphql/account/resolvers.py
@@ -16,7 +16,7 @@ USER_SEARCH_FIELDS = (
def resolve_user(info, id):
logged_user = info.context.user
- if id == "":
+ if not id:
return logged_user
user = graphene.Node.get_node_from_global_id(info, id, User)
if logged_user.has_perm('account.manage_users') or user == logged_user:
diff --git a/saleor/graphql/schema.graphql b/saleor/graphql/schema.graphql
index 982e2fa733..d381cc5cb9 100644
--- a/saleor/graphql/schema.graphql
+++ b/saleor/graphql/schema.graphql
@@ -871,7 +871,7 @@ type Mutations {
setPassword(id: ID!, input: SetPasswordInput!): SetPassword
passwordReset(email: String!): PasswordReset
customerCreate(input: UserCreateInput!): CustomerCreate
- loggedCustomerUpdate(id: ID!, input: UserAddressInput!): LoggedCustomerUpdate
+ loggedCustomerUpdate(input: UserAddressInput!): LoggedCustomerUpdate
customerUpdate(id: ID!, input: CustomerInput!): CustomerUpdate
customerDelete(id: ID!): CustomerDelete
customerPasswordReset(input: CustomerPasswordResetInput!): CustomerPasswordReset
diff --git a/saleor/static/dashboard-next/types/globalTypes.ts b/saleor/static/dashboard-next/types/globalTypes.ts
index 8ebc524e78..12ec78e17d 100644
--- a/saleor/static/dashboard-next/types/globalTypes.ts
+++ b/saleor/static/dashboard-next/types/globalTypes.ts
@@ -181,11 +181,11 @@ export interface CollectionInput {
}
export interface CustomerInput {
+ defaultBillingAddress?: AddressInput | null;
+ defaultShippingAddress?: AddressInput | null;
email?: string | null;
isActive?: boolean | null;
note?: string | null;
- defaultBillingAddress?: AddressInput | null;
- defaultShippingAddress?: AddressInput | null;
}
export interface DraftOrderInput {
@@ -286,11 +286,11 @@ export interface StaffInput {
}
export interface UserCreateInput {
+ defaultBillingAddress?: AddressInput | null;
+ defaultShippingAddress?: AddressInput | null;
email?: string | null;
isActive?: boolean | null;
note?: string | null;
- defaultBillingAddress?: AddressInput | null;
- defaultShippingAddress?: AddressInput | null;
sendPasswordEmail?: boolean | null;
}
diff --git a/tests/api/test_account.py b/tests/api/test_account.py
index b3660a115e..b4c84ff26b 100644
--- a/tests/api/test_account.py
+++ b/tests/api/test_account.py
@@ -143,8 +143,7 @@ def test_query_user(staff_api_client, customer_user, permission_manage_users):
assert address['phone'] == user_address.phone.as_e164
-def test_non_staff_user_can_only_see_his_user_data(user_api_client,
- staff_user):
+def test_non_staff_user_can_see_his_user_data(user_api_client):
query = """
query User($id: ID!) {
user(id: $id) {
@@ -152,21 +151,30 @@ def test_non_staff_user_can_only_see_his_user_data(user_api_client,
}
}
"""
- id = graphene.Node.to_global_id('User', staff_user.id)
+ user = user_api_client.user
+ id = graphene.Node.to_global_id('User', user.id)
variables = {'id': id}
response = user_api_client.post_graphql(query, variables)
content = get_graphql_content(response)
data = content['data']['user']
- assert data is None
+ assert data['email'] == user.email
- # Ensure user can see own data
- user = user_api_client.user
- id = graphene.Node.to_global_id('User', user.id)
+
+def test_non_staff_user_can_not_see_other_users_data(user_api_client,
+ staff_user):
+ query = """
+ query User($id: ID!) {
+ user(id: $id) {
+ email
+ }
+ }
+ """
+ id = graphene.Node.to_global_id('User', staff_user.id)
variables = {'id': id}
response = user_api_client.post_graphql(query, variables)
content = get_graphql_content(response)
data = content['data']['user']
- assert data['email'] == user.email
+ assert data is None
def test_user_query_with_empty_id(user_api_client):
@@ -177,7 +185,7 @@ def test_user_query_with_empty_id(user_api_client):
}
}
"""
- variables = {'id': ""}
+ variables = {'id': ''}
response = user_api_client.post_graphql(query, variables)
content = get_graphql_content(response)
data = content['data']['user']
@@ -454,9 +462,9 @@ def test_customer_update(
def test_logged_customer_update(user_api_client, address):
query = """
- mutation UpdateCustomer($id: ID!, $billing: AddressInput,
- $shipping: AddressInput) {
- loggedCustomerUpdate(id: $id,
+ mutation UpdateLoggedCustomer($billing: AddressInput,
+ $shipping: AddressInput) {
+ loggedCustomerUpdate(
input: {
defaultBillingAddress: $billing,
defaultShippingAddress: $shipping,
@@ -466,7 +474,6 @@ def test_logged_customer_update(user_api_client, address):
message
}
user {
- id
email
defaultBillingAddress {
id
@@ -487,124 +494,13 @@ def test_logged_customer_update(user_api_client, address):
billing_address_pk = user.default_billing_address.pk
shipping_address_pk = user.default_shipping_address.pk
- id = graphene.Node.to_global_id('User', user.id)
address_data = convert_dict_keys_to_camel_case(address.as_data())
new_street_address = 'Updated street address'
address_data['streetAddress1'] = new_street_address
variables = {
- 'id': id, 'billing': address_data,
- 'shipping': address_data}
- response = user_api_client.post_graphql(query, variables)
- content = get_graphql_content(response)
-
- User = get_user_model()
- customer = User.objects.get(email=user.email)
-
- customer_billing_address = customer.default_billing_address
- customer_shipping_address = customer.default_shipping_address
-
- # check that existing instances are updated
- assert customer_billing_address.pk == billing_address_pk
- assert customer_shipping_address.pk == shipping_address_pk
-
- assert customer_billing_address.street_address_1 == new_street_address
- assert customer_shipping_address.street_address_1 == new_street_address
-
- data = content['data']['loggedCustomerUpdate']
- assert data['errors'] == []
-
-
-def test_user_without_premission_can_only_update_own_data(staff_api_client,
- customer_user,
- address):
- query = """
- mutation UpdateCustomer($id: ID!, $billing: AddressInput,
- $shipping: AddressInput) {
- loggedCustomerUpdate(id: $id,
- input: {
- defaultBillingAddress: $billing,
- defaultShippingAddress: $shipping,
- }) {
- errors {
- field
- message
- }
- user {
- id
- email
- defaultBillingAddress {
- id
- }
- defaultShippingAddress {
- id
- }
- }
- }
- }
- """
-
- assert customer_user.default_billing_address
- assert customer_user.default_shipping_address
- billing_address_pk = customer_user.default_billing_address.pk
- shipping_address_pk = customer_user.default_shipping_address.pk
-
- id = graphene.Node.to_global_id('User', customer_user.id)
- address_data = convert_dict_keys_to_camel_case(address.as_data())
-
- new_street_address = 'Updated street address'
- address_data['streetAddress1'] = new_street_address
-
- variables = {
- 'id': id, 'billing': address_data,
- 'shipping': address_data}
- response = staff_api_client.post_graphql(query, variables)
- assert_no_permission(response)
-
-
-def test_logged_customer_update_with_empty_id(user_api_client, address):
- query = """
- mutation UpdateCustomer($id: ID!, $billing: AddressInput,
- $shipping: AddressInput) {
- loggedCustomerUpdate(id: $id,
- input: {
- defaultBillingAddress: $billing,
- defaultShippingAddress: $shipping,
- }) {
- errors {
- field
- message
- }
- user {
- id
- email
- defaultBillingAddress {
- id
- }
- defaultShippingAddress {
- id
- }
- }
- }
- }
- """
-
- # this test requires addresses to be set and checks whether new address
- # instances weren't created, but the existing ones got updated
- user = user_api_client.user
- assert user.default_billing_address
- assert user.default_shipping_address
- billing_address_pk = user.default_billing_address.pk
- shipping_address_pk = user.default_shipping_address.pk
-
- address_data = convert_dict_keys_to_camel_case(address.as_data())
-
- new_street_address = 'Updated street address'
- address_data['streetAddress1'] = new_street_address
-
- variables = {
- 'id': '', 'billing': address_data,
+ 'billing': address_data,
'shipping': address_data}
response = user_api_client.post_graphql(query, variables)
content = get_graphql_content(response)