Skip to content

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

Change email template sent when customer or staff user is created via API

Aleksander Spyra3dd6c50b25e3
diff --git a/saleor/graphql/account/mutations.py b/saleor/graphql/account/mutations.py
index 18f633c891..57b2fd9516 100644
--- a/saleor/graphql/account/mutations.py
+++ b/saleor/graphql/account/mutations.py
@@ -10,6 +10,7 @@ from graphql_jwt.exceptions import PermissionDenied
from ...account import emails, models
from ...core.permissions import MODELS_PERMISSIONS, get_permissions
from ...dashboard.staff.utils import remove_staff_member
+from ...dashboard.emails import send_set_password_customer_email, send_set_password_staff_email
from ..account.i18n import I18nMixin
from ..account.types import AddressInput, User
from ..core.enums import PermissionEnum
@@ -136,11 +137,13 @@ class CustomerCreate(ModelMutation, I18nMixin):
default_billing_address.save()
instance.default_billing_address = default_billing_address
- if cleaned_input.get('send_password_email'):
- site = info.context.site
- send_user_password_reset_email(instance, site)
super().save(info, instance, cleaned_input)
+ if cleaned_input.get('send_password_email'):
+ # site = info.context.site
+ # send_user_password_reset_email(instance, site)
+ send_set_password_customer_email.delay(instance.pk)
+
class CustomerUpdate(CustomerCreate):
class Arguments:
@@ -253,8 +256,9 @@ class StaffCreate(ModelMutation):
def save(cls, info, user, cleaned_input):
user.save()
if cleaned_input.get('send_password_email'):
- site = info.context.site
- send_user_password_reset_email(user, site)
+ # site = info.context.site
+ # send_user_password_reset_email(user, site)
+ send_set_password_staff_email.delay(user.pk)
class StaffUpdate(StaffCreate):
diff --git a/tests/api/test_account.py b/tests/api/test_account.py
index 73cd200734..14a0b65592 100644
--- a/tests/api/test_account.py
+++ b/tests/api/test_account.py
@@ -352,9 +352,9 @@ def test_customer_register(user_api_client):
'User with this Email already exists.')
-@patch('saleor.account.emails.send_password_reset_email.delay')
+@patch('saleor.dashboard.emails.send_set_password_customer_email.delay')
def test_customer_create(
- send_password_reset_mock, staff_api_client, address,
+ send_set_password_customer_email_mock, staff_api_client, address,
permission_manage_users):
query = """
mutation CreateCustomer(
@@ -429,12 +429,10 @@ def test_customer_create(
assert not data['user']['isStaff']
assert data['user']['isActive']
- assert send_password_reset_mock.call_count == 1
- args, kwargs = send_password_reset_mock.call_args
- call_context = args[0]
- call_email = args[1]
- assert call_email == email
- assert 'token' in call_context
+ assert send_set_password_customer_email_mock.call_count == 1
+ args, kwargs = send_set_password_customer_email_mock.call_args
+ call_pk = args[0]
+ assert call_pk == customer.pk
def test_customer_update(
@@ -618,9 +616,9 @@ def test_customer_delete_errors(customer_user, admin_user, staff_user):
assert errors == []
-@patch('saleor.account.emails.send_password_reset_email.delay')
+@patch('saleor.dashboard.emails.send_set_password_staff_email.delay')
def test_staff_create(
- send_password_reset_mock, staff_api_client, permission_manage_staff):
+ send_set_password_staff_email_mock, staff_api_client, permission_manage_staff):
query = """
mutation CreateStaff(
$email: String, $permissions: [PermissionEnum],
@@ -661,12 +659,15 @@ def test_staff_create(
permissions = data['user']['permissions']
assert permissions[0]['code'] == 'MANAGE_PRODUCTS'
- assert send_password_reset_mock.call_count == 1
- args, kwargs = send_password_reset_mock.call_args
- call_context = args[0]
- call_email = args[1]
- assert call_email == email
- assert 'token' in call_context
+ User = get_user_model()
+ staff_user = User.objects.get(email=email)
+
+ assert staff_user.is_staff
+
+ assert send_set_password_staff_email_mock.call_count == 1
+ args, kwargs = send_set_password_staff_email_mock.call_args
+ call_pk = args[0]
+ assert call_pk == staff_user.pk
def test_staff_update(staff_api_client, permission_manage_staff):