Skip to content

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

Create staff member from exisitng account if available

Anna Siwik95906768d01f
diff --git a/saleor/dashboard/emails.py b/saleor/dashboard/emails.py
index f85f328987..b6dcb455a0 100644
--- a/saleor/dashboard/emails.py
+++ b/saleor/dashboard/emails.py
@@ -20,3 +20,14 @@ def send_set_password_email(staff):
from_email=settings.DEFAULT_FROM_EMAIL,
recipient_list=[staff.email],
context=ctx)
+
+
+@shared_task
+def send_promote_customer_to_staff_email(staff):
+ site = Site.objects.get_current()
+ ctx = {'domain': site.domain, 'site_name': site.name}
+ send_templated_mail(
+ template_name='dashboard/staff/promote_customer',
+ from_email=settings.DEFAULT_FROM_EMAIL,
+ recipient_list=[staff.email],
+ context=ctx)
diff --git a/saleor/dashboard/staff/views.py b/saleor/dashboard/staff/views.py
index 3509a0ef9e..8df1e340be 100644
--- a/saleor/dashboard/staff/views.py
+++ b/saleor/dashboard/staff/views.py
@@ -7,7 +7,7 @@ from django.utils.translation import pgettext_lazy
from .filters import StaffFilter
from .forms import StaffForm
-from ..emails import send_set_password_email
+from ..emails import send_promote_customer_to_staff_email, send_set_password_email
from ..views import staff_member_required
from ...core.utils import get_paginator_items
from ...userprofile.models import User
@@ -48,14 +48,22 @@ def staff_details(request, pk):
@staff_member_required
@permission_required('userprofile.edit_staff')
def staff_create(request):
- staff = User()
+ try:
+ staff = User.objects.get(email=request.POST.get('email'))
+ created = False
+ except User.DoesNotExist:
+ staff = User()
+ created = True
form = StaffForm(request.POST or None, instance=staff)
if form.is_valid():
form.save()
msg = pgettext_lazy(
'Dashboard message', 'Added staff member %s') % (staff,)
messages.success(request, msg)
- send_set_password_email(staff)
+ if created:
+ send_set_password_email(staff)
+ else:
+ send_promote_customer_to_staff_email(staff)
return redirect('dashboard:staff-list')
ctx = {'form': form}
return TemplateResponse(request, 'dashboard/staff/detail.html', ctx)
diff --git a/templates/templated_email/dashboard/staff/promote_customer.email b/templates/templated_email/dashboard/staff/promote_customer.email
new file mode 100644
index 0000000000..c74b8687a1
--- /dev/null
+++ b/templates/templated_email/dashboard/staff/promote_customer.email
@@ -0,0 +1,10 @@
+{% load i18n %}
+{% block subject %}{% blocktrans %}Hello from {{ site_name }}!{% endblocktrans %}{% endblock %}
+
+{% block plain %}
+{% blocktrans %}You're receiving this e-mail because you have been promoted to staff member at {{ domain }}.{% endblocktrans %}
+
+{% blocktrans %}Thank you for using {{ site_name }}!
+{{ domain }}
+{% endblocktrans %}
+{% endblock %}