Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Add promote customer to staff feature
michal54b0f4545c49
diff --git a/saleor/dashboard/customer/forms.py b/saleor/dashboard/customer/forms.pynew file mode 100644index 0000000000..6b87d8567a--- /dev/null+++ b/saleor/dashboard/customer/forms.py@@ -0,0 +1,9 @@+from django import forms++from ...userprofile.models import User+++class StaffPromoteForm(forms.ModelForm):+ class Meta:+ model = User+ fields = ['is_staff']diff --git a/saleor/dashboard/customer/views.py b/saleor/dashboard/customer/views.pyindex 380e4c7535..2451ee2618 100644--- a/saleor/dashboard/customer/views.py+++ b/saleor/dashboard/customer/views.py@@ -9,6 +9,7 @@ from ...core.utils import get_paginator_itemsfrom ...userprofile.models import Userfrom ...settings import DASHBOARD_PAGINATE_BYfrom ..views import staff_member_required+from .forms import StaffPromoteForm@staff_member_required@@ -35,6 +36,10 @@ def customer_details(request, pk):'orders', 'addresses').select_related('default_billing_address', 'default_shipping_address')customer = get_object_or_404(queryset, pk=pk)+ form = StaffPromoteForm(request.POST or None, instance=customer)+ if form.is_valid():+ form.save()customer_orders = customer.orders.all()- ctx = {'customer': customer, 'customer_orders': customer_orders}+ ctx = {'customer': customer, 'customer_orders': customer_orders,+ 'form': form}return TemplateResponse(request, 'dashboard/customer/detail.html', ctx)diff --git a/saleor/dashboard/staff/forms.py b/saleor/dashboard/staff/forms.pyindex dca3521135..5d55c9ba80 100644--- a/saleor/dashboard/staff/forms.py+++ b/saleor/dashboard/staff/forms.py@@ -5,7 +5,7 @@ from ...userprofile.models import Userclass StaffForm(forms.ModelForm):def __init__(self, *args, **kwargs):- self.admin = kwargs.pop('admin', '1')+ self.admin = kwargs.pop('admin', None)super(StaffForm, self).__init__(*args, **kwargs)if self.admin == self.instance:self.fields['is_superuser'].widget.attrs['disabled'] = Truediff --git a/templates/dashboard/customer/detail.html b/templates/dashboard/customer/detail.htmlindex 275ccb6e1c..3a7bb224f7 100644--- a/templates/dashboard/customer/detail.html+++ b/templates/dashboard/customer/detail.html@@ -1,6 +1,7 @@{% extends "dashboard/base.html" %}{% load prices_i18n %}{% load i18n %}+{% load materializecss %}{% load status %}{% load staticfiles %}@@ -91,6 +92,26 @@</div></div><div class="col s12 l4">+ <div class="row">+ <div class="col s12 m6 p6 l12">+ <div class="card equal-height-on-med">+ <div class="card-content">+ <span class="card-title black-text">+ {% trans "Promote to staff member" context "Customer promote to staff member card title" %}+ </span>+ <form method="post">+ {% csrf_token %}+ {{ form|materializecss }}+ <div class="card-action right-align">+ <button type="submit" class="btn waves-effect waves-light">+ {% trans 'Update' context 'Dashboard update action' %}+ </button>+ </div>+ </form>+ </div>+ </div>+ </div>+ </div><div class="row"><div class="col s12 m6 p6 l12"><div class="card equal-height-on-med">