Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Fix password reset request (issue #6071) (#6351)
manfred.madelaine8f874dd50ceb
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex dbb13a4ef3..c10a31dd09 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -14,6 +14,7 @@ All notable, unreleased changes to this project will be documented in this file.- Add editorjs sanitizer - #6456 by @IKarbowiak- Add generic FileUpload mutation - #6470 by @IKarbowiak- Multichannel MVP: Multicurrency - #6242 by @fowczarek @d-wysocki+- Fix password reset request - #6351 by @Manfred-Madelaine-pro, Ambroise and Pierre# 2.11.1diff --git a/saleor/account/error_codes.py b/saleor/account/error_codes.pyindex d2f3cfb3c1..7e833f1e18 100644--- a/saleor/account/error_codes.py+++ b/saleor/account/error_codes.py@@ -12,6 +12,7 @@ class AccountErrorCode(Enum):DELETE_STAFF_ACCOUNT = "delete_staff_account"DELETE_SUPERUSER_ACCOUNT = "delete_superuser_account"GRAPHQL_ERROR = "graphql_error"+ INACTIVE = "inactive"INVALID = "invalid"INVALID_PASSWORD = "invalid_password"LEFT_NOT_MANAGEABLE_PERMISSION = "left_not_manageable_permission"diff --git a/saleor/graphql/account/mutations/base.py b/saleor/graphql/account/mutations/base.pyindex f202684e55..87aa328e30 100644--- a/saleor/graphql/account/mutations/base.py+++ b/saleor/graphql/account/mutations/base.py@@ -138,6 +138,16 @@ class RequestPasswordReset(BaseMutation):)})++ if not user.is_active:+ raise ValidationError(+ {+ "email": ValidationError(+ "User with this email is inactive",+ code=AccountErrorCode.INACTIVE,+ )+ }+ )send_user_password_reset_email_with_url(redirect_url, user)return RequestPasswordReset()diff --git a/saleor/graphql/account/tests/test_account.py b/saleor/graphql/account/tests/test_account.pyindex e44b6f6b59..eb9574ae64 100644--- a/saleor/graphql/account/tests/test_account.py+++ b/saleor/graphql/account/tests/test_account.py@@ -3172,6 +3172,27 @@ def test_account_reset_password_invalid_email(assert not send_password_reset_email_mock.called+@patch("saleor.account.emails._send_password_reset_email")+def test_account_reset_password_user_is_inactive(+ send_password_reset_email_mock, user_api_client, customer_user+):+ user = customer_user+ user.is_active = False+ user.save()++ variables = {+ "email": customer_user.email,+ "redirectUrl": "https://www.example.com",+ }+ response = user_api_client.post_graphql(REQUEST_PASSWORD_RESET_MUTATION, variables)+ content = get_graphql_content(response)+ data = content["data"]["requestPasswordReset"]+ assert data["errors"] == [+ {"field": "email", "message": "User with this email is inactive"}+ ]+ assert not send_password_reset_email_mock.called++@patch("saleor.account.emails._send_password_reset_email")def test_account_reset_password_storefront_hosts_not_allowed(send_password_reset_email_mock, user_api_client, customer_userdiff --git a/saleor/graphql/schema.graphql b/saleor/graphql/schema.graphqlindex 8de6b6d4d5..481f9b0227 100644--- a/saleor/graphql/schema.graphql+++ b/saleor/graphql/schema.graphql@@ -47,6 +47,7 @@ enum AccountErrorCode {DELETE_STAFF_ACCOUNTDELETE_SUPERUSER_ACCOUNTGRAPHQL_ERROR+ INACTIVEINVALIDINVALID_PASSWORDLEFT_NOT_MANAGEABLE_PERMISSION