Skip to content

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

Add account prefix to password reset mutation

fowczarek5b25f5c63b28
diff --git a/saleor/graphql/account/mutations/account.py b/saleor/graphql/account/mutations/account.py
index d9a28bdd0c..386576da97 100644
--- a/saleor/graphql/account/mutations/account.py
+++ b/saleor/graphql/account/mutations/account.py
@@ -178,16 +178,16 @@ class AccountSetDefaultAddress(BaseMutation):
return cls(user=user)
-class CustomerPasswordResetInput(graphene.InputObjectType):
+class AccountPasswordResetInput(graphene.InputObjectType):
email = graphene.String(
required=True,
description=("Email of the user that will be used for password recovery."),
)
-class CustomerPasswordReset(BaseMutation):
+class AccountPasswordReset(BaseMutation):
class Arguments:
- input = CustomerPasswordResetInput(
+ input = AccountPasswordResetInput(
description="Fields required to reset customer's password", required=True
)
@@ -203,4 +203,4 @@ class CustomerPasswordReset(BaseMutation):
raise ValidationError({"email": "User with this email doesn't exist"})
site = info.context.site
send_user_password_reset_email(user, site)
- return CustomerPasswordReset()
+ return AccountPasswordReset()
diff --git a/saleor/graphql/account/mutations/deprecated_account.py b/saleor/graphql/account/mutations/deprecated_account.py
index 4330bb4e44..b13d0f5dee 100644
--- a/saleor/graphql/account/mutations/deprecated_account.py
+++ b/saleor/graphql/account/mutations/deprecated_account.py
@@ -1,11 +1,12 @@
import graphene
-from django.core.exceptions import ValidationError
+from django.core.exceptions import ObjectDoesNotExist, ValidationError
from ....account import events as account_events, models, utils
from ....checkout import AddressType
from ...account.enums import AddressTypeEnum
from ...account.types import Address, AddressInput, User
from ...core.mutations import BaseMutation, ModelMutation
+from .base import send_user_password_reset_email
from .staff import CustomerCreate, UserAddressInput
@@ -142,3 +143,31 @@ class CustomerSetDefaultAddress(BaseMutation):
utils.change_user_default_address(user, address, address_type)
return cls(user=user)
+
+
+class CustomerPasswordResetInput(graphene.InputObjectType):
+ email = graphene.String(
+ required=True,
+ description=("Email of the user that will be used for password recovery."),
+ )
+
+
+class CustomerPasswordReset(BaseMutation):
+ class Arguments:
+ input = CustomerPasswordResetInput(
+ description="Fields required to reset customer's password", required=True
+ )
+
+ class Meta:
+ description = "Resets the customer's password."
+
+ @classmethod
+ def perform_mutation(cls, _root, info, **data):
+ email = data.get("input")["email"]
+ try:
+ user = models.User.objects.get(email=email)
+ except ObjectDoesNotExist:
+ raise ValidationError({"email": "User with this email doesn't exist"})
+ site = info.context.site
+ send_user_password_reset_email(user, site)
+ return CustomerPasswordReset()
diff --git a/saleor/graphql/account/schema.py b/saleor/graphql/account/schema.py
index 51e24c7230..058227723a 100644
--- a/saleor/graphql/account/schema.py
+++ b/saleor/graphql/account/schema.py
@@ -11,11 +11,11 @@ from .mutations.account import (
AccountAddressCreate,
AccountAddressDelete,
AccountAddressUpdate,
+ AccountPasswordReset,
AccountRegister,
AccountRequestDeletion,
AccountSetDefaultAddress,
AccountUpdate,
- CustomerPasswordReset,
)
from .mutations.base import (
PasswordReset,
@@ -25,6 +25,7 @@ from .mutations.base import (
)
from .mutations.deprecated_account import (
CustomerAddressCreate,
+ CustomerPasswordReset,
CustomerRegister,
CustomerSetDefaultAddress,
LoggedUserUpdate,
@@ -135,6 +136,7 @@ class AccountMutations(graphene.ObjectType):
account_address_delete = AccountAddressDelete.Field()
account_set_default_address = AccountSetDefaultAddress.Field()
account_address_create = AccountAddressCreate.Field()
+ account_password_reset = AccountPasswordReset.Field()
staff_create = StaffCreate.Field()
staff_delete = StaffDelete.Field()
diff --git a/tests/api/test_account.py b/tests/api/test_account.py
index 87f9d5f65f..665ddd8d70 100644
--- a/tests/api/test_account.py
+++ b/tests/api/test_account.py
@@ -1723,20 +1723,37 @@ def test_address_validator_with_country_area(user_api_client):
assert not data["cityAreaChoices"]
-@patch("saleor.account.emails.send_password_reset_email.delay")
-def test_customer_reset_password(
- send_password_reset_mock, user_api_client, customer_user
-):
- query = """
- mutation CustomerPasswordReset($email: String!) {
- customerPasswordReset(input: {email: $email}) {
- errors {
- field
- message
- }
+CUSTOMER_PASSWORD_RESET_MUTATION = """
+ mutation CustomerPasswordReset($email: String!) {
+ customerPasswordReset(input: {email: $email}) {
+ errors {
+ field
+ message
}
}
- """
+ }
+"""
+
+
+ACCOUNT_PASSWORD_RESET_MUTATION = """
+ mutation AccountPasswordReset($email: String!) {
+ accountPasswordReset(input: {email: $email}) {
+ errors {
+ field
+ message
+ }
+ }
+ }
+"""
+
+
+ "query", [CUSTOMER_PASSWORD_RESET_MUTATION, ACCOUNT_PASSWORD_RESET_MUTATION]
+)
+@patch("saleor.account.emails.send_password_reset_email.delay")
+def test_account_reset_password(
+ send_password_reset_mock, user_api_client, customer_user, query
+):
# we have no user with given email
variables = {"email": "[email protected]"}
response = user_api_client.post_graphql(query, variables)