Skip to content

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

Change send_password_email to deprecated

fowczarekeaf0d8c150b9
diff --git a/saleor/graphql/account/mutations/base.py b/saleor/graphql/account/mutations/base.py
index 4e85a88ae5..55d819c394 100644
--- a/saleor/graphql/account/mutations/base.py
+++ b/saleor/graphql/account/mutations/base.py
@@ -297,7 +297,8 @@ class CustomerInput(UserInput, UserAddressInput):
class UserCreateInput(CustomerInput):
send_password_email = graphene.Boolean(
- description="Send an email with a link to set a password."
+ # TODO Add description
+ description="DEPRECATED: XXXX, Send an email with a link to set a password."
)
redirect_url = graphene.String(
description=(
@@ -337,6 +338,8 @@ class BaseCustomerCreate(ModelMutation, I18nMixin):
)
cleaned_input[BILLING_ADDRESS_FIELD] = billing_address
+ # TODO Add description
+ # DEPRECATED: XXX
if cleaned_input.get("send_password_email"):
if not cleaned_input.get("redirect_url"):
raise ValidationError(
@@ -347,6 +350,7 @@ class BaseCustomerCreate(ModelMutation, I18nMixin):
)
}
)
+ if cleaned_input.get("redirect_url"):
validate_storefront_url(cleaned_input.get("redirect_url"))
return cleaned_input
@@ -372,7 +376,7 @@ class BaseCustomerCreate(ModelMutation, I18nMixin):
info.context.extensions.customer_created(customer=instance)
account_events.customer_account_created_event(user=instance)
- if cleaned_input.get("send_password_email"):
+ if cleaned_input.get("redirect_url"):
send_set_password_email_with_url(
cleaned_input.get("redirect_url"), instance
)
diff --git a/saleor/graphql/account/mutations/staff.py b/saleor/graphql/account/mutations/staff.py
index 64e80937a4..738d71c154 100644
--- a/saleor/graphql/account/mutations/staff.py
+++ b/saleor/graphql/account/mutations/staff.py
@@ -46,7 +46,8 @@ class StaffInput(UserInput):
class StaffCreateInput(StaffInput):
send_password_email = graphene.Boolean(
- description="Send an email with a link to set the password."
+ # TODO Add description
+ description="DEPRECATED: XXXX, Send an email with a link to set the password."
)
redirect_url = graphene.String(
description=(
@@ -172,6 +173,8 @@ class StaffCreate(ModelMutation):
def clean_input(cls, info, instance, data):
cleaned_input = super().clean_input(info, instance, data)
+ # TODO Add description
+ # DEPRECATED: XXX
if cleaned_input.get("send_password_email"):
if not cleaned_input.get("redirect_url"):
raise ValidationError(
@@ -182,6 +185,7 @@ class StaffCreate(ModelMutation):
)
}
)
+ if cleaned_input.get("redirect_url"):
validate_storefront_url(cleaned_input.get("redirect_url"))
# set is_staff to True to create a staff user
@@ -201,7 +205,7 @@ class StaffCreate(ModelMutation):
user.save()
if create_avatar:
create_user_avatar_thumbnails.delay(user_id=user.pk)
- if cleaned_input.get("send_password_email"):
+ if cleaned_input.get("redirect_url"):
send_set_password_email_with_url(
redirect_url=cleaned_input.get("redirect_url"), user=user, staff=True
)
diff --git a/tests/api/test_account.py b/tests/api/test_account.py
index 758484ae15..c0d334ec08 100644
--- a/tests/api/test_account.py
+++ b/tests/api/test_account.py
@@ -646,6 +646,11 @@ CUSTOMER_CREATE_MUTATION = """
field
message
}
+ accountErrors{
+ field
+ message
+ code
+ }
user {
id
defaultBillingAddress {
@@ -683,7 +688,6 @@ def test_customer_create(
"note": note,
"shipping": address_data,
"billing": address_data,
- "send_mail": True,
"redirect_url": "https://www.example.com",
}
@@ -727,11 +731,7 @@ def test_customer_create_send_password_with_url(
permission_manage_users,
):
- variables = {
- "email": email,
- "send_mail": True,
- "redirect_url": "https://www.example.com",
- }
+ variables = {"email": email, "redirect_url": "https://www.example.com"}
response = staff_api_client.post_graphql(
CUSTOMER_CREATE_MUTATION, variables, permissions=[permission_manage_users]
@@ -763,7 +763,7 @@ def test_customer_create_without_send_password(
User.objects.get(email=email)
-def test_customer_create_without_redirect_url(
+def test_customer_create_without_redirect_url_deprecated_send_mail_flag(
staff_api_client, permission_manage_users
):
@@ -773,20 +773,28 @@ def test_customer_create_without_redirect_url(
)
content = get_graphql_content(response)
data = content["data"]["customerCreate"]
- assert data["errors"][0]["field"] == "redirectUrl"
+ assert data["accountErrors"][0] == {
+ "field": "redirectUrl",
+ "code": AccountErrorCode.REQUIRED.name,
+ "message": ANY,
+ }
staff_user = User.objects.filter(email=email)
assert not staff_user
def test_customer_create_with_invalid_url(staff_api_client, permission_manage_users):
- variables = {"email": email, "send_mail": True, "redirect_url": "invalid"}
+ variables = {"email": email, "redirect_url": "invalid"}
response = staff_api_client.post_graphql(
CUSTOMER_CREATE_MUTATION, variables, permissions=[permission_manage_users]
)
content = get_graphql_content(response)
data = content["data"]["customerCreate"]
- assert data["errors"][0]["field"] == "redirectUrl"
+ assert data["accountErrors"][0] == {
+ "field": "redirectUrl",
+ "code": AccountErrorCode.INVALID.name,
+ "message": ANY,
+ }
staff_user = User.objects.filter(email=email)
assert not staff_user
@@ -795,17 +803,17 @@ def test_customer_create_with_not_allowed_url(
staff_api_client, permission_manage_users
):
- variables = {
- "email": email,
- "send_mail": True,
- "redirectUrl": "https://www.fake.com",
- }
+ variables = {"email": email, "redirect_url": "https://www.fake.com"}
response = staff_api_client.post_graphql(
CUSTOMER_CREATE_MUTATION, variables, permissions=[permission_manage_users]
)
content = get_graphql_content(response)
data = content["data"]["customerCreate"]
- assert data["errors"][0]["field"] == "redirectUrl"
+ assert data["accountErrors"][0] == {
+ "field": "redirectUrl",
+ "code": AccountErrorCode.INVALID.name,
+ "message": ANY,
+ }
staff_user = User.objects.filter(email=email)
assert not staff_user
@@ -1386,7 +1394,6 @@ def test_staff_create(
variables = {
"email": email,
"permissions": [PermissionEnum.MANAGE_PRODUCTS.name],
- "send_mail": True,
"redirect_url": "https://www.example.com",
}
@@ -1423,11 +1430,7 @@ def test_staff_create_send_password_with_url(
permission_manage_staff,
):
- variables = {
- "email": email,
- "send_mail": True,
- "redirect_url": "https://www.example.com",
- }
+ variables = {"email": email, "redirect_url": "https://www.example.com"}
response = staff_api_client.post_graphql(
STAFF_CREATE_MUTATION, variables, permissions=[permission_manage_staff]
@@ -1459,7 +1462,7 @@ def test_staff_create_without_send_password(
User.objects.get(email=email)
-def test_staff_create_without_redirect_url(
+def test_staff_create_without_redirect_url_deprecated_send_mail_flag(
staff_api_client, media_root, permission_manage_staff
):
@@ -1469,7 +1472,11 @@ def test_staff_create_without_redirect_url(
)
content = get_graphql_content(response)
data = content["data"]["staffCreate"]
- assert data["errors"][0]["field"] == "redirectUrl"
+ assert data["accountErrors"][0] == {
+ "field": "redirectUrl",
+ "code": AccountErrorCode.REQUIRED.name,
+ "message": ANY,
+ }
staff_user = User.objects.filter(email=email)
assert not staff_user
@@ -1478,13 +1485,17 @@ def test_staff_create_with_invalid_url(
staff_api_client, media_root, permission_manage_staff
):
- variables = {"email": email, "send_mail": True, "redirect_url": "invalid"}
+ variables = {"email": email, "redirect_url": "invalid"}
response = staff_api_client.post_graphql(
STAFF_CREATE_MUTATION, variables, permissions=[permission_manage_staff]
)
content = get_graphql_content(response)
data = content["data"]["staffCreate"]
- assert data["errors"][0]["field"] == "redirectUrl"
+ assert data["accountErrors"][0] == {
+ "field": "redirectUrl",
+ "code": AccountErrorCode.INVALID.name,
+ "message": ANY,
+ }
staff_user = User.objects.filter(email=email)
assert not staff_user
@@ -1492,18 +1503,18 @@ def test_staff_create_with_invalid_url(
def test_staff_create_with_not_allowed_url(
staff_api_client, media_root, permission_manage_staff
):
- email = "[email protected]"
- variables = {
- "email": email,
- "send_mail": True,
- "redirectUrl": "https://www.fake.com",
- }
+ email = "[email protected]"
+ variables = {"email": email, "redirect_url": "https://www.fake.com"}
response = staff_api_client.post_graphql(
STAFF_CREATE_MUTATION, variables, permissions=[permission_manage_staff]
)
content = get_graphql_content(response)
data = content["data"]["staffCreate"]
- assert data["errors"][0]["field"] == "redirectUrl"
+ assert data["accountErrors"][0] == {
+ "field": "redirectUrl",
+ "code": AccountErrorCode.INVALID.name,
+ "message": ANY,
+ }
staff_user = User.objects.filter(email=email)
assert not staff_user