Skip to content

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

Update StaffPromoteForm

michalfbcf4b5641d9
diff --git a/saleor/dashboard/customer/forms.py b/saleor/dashboard/customer/forms.py
index 6b87d8567a..ac092d6d44 100644
--- a/saleor/dashboard/customer/forms.py
+++ b/saleor/dashboard/customer/forms.py
@@ -4,6 +4,12 @@ from ...userprofile.models import User
class StaffPromoteForm(forms.ModelForm):
+ def __init__(self, *args, **kwargs):
+ self.admin = kwargs.pop('admin', None)
+ super(StaffPromoteForm, self).__init__(*args, **kwargs)
+ if self.admin == self.instance or not self.admin.is_superuser:
+ self.fields['is_staff'].widget.attrs['disabled'] = True
+
class Meta:
model = User
fields = ['is_staff']
diff --git a/saleor/dashboard/customer/views.py b/saleor/dashboard/customer/views.py
index 2451ee2618..a8d9e13fa1 100644
--- a/saleor/dashboard/customer/views.py
+++ b/saleor/dashboard/customer/views.py
@@ -36,7 +36,7 @@ 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)
+ form = StaffPromoteForm(request.POST or None, instance=customer, admin=request.user)
if form.is_valid():
form.save()
customer_orders = customer.orders.all()
diff --git a/templates/dashboard/customer/detail.html b/templates/dashboard/customer/detail.html
index e6723be6a7..4baf5e6ba7 100644
--- a/templates/dashboard/customer/detail.html
+++ b/templates/dashboard/customer/detail.html
@@ -94,26 +94,24 @@
<div class="col s12 l4">
<div class="row">
- {% if user.is_superuser %}
- <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 class="col s12 m6 p6 l12">
+ <div class="card equal-height-on-med">
+ <div class="card-content">
+ <span class="card-title black-text">
+ {% trans "Staff member status" context "Customer staff member status 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" {% if not user.is_superuser %}disabled{% endif %}>
+ {% trans 'Update' context 'Dashboard update action' %}
+ </button>
+ </div>
+ </form>
</div>
</div>
- {% endif %}
+ </div>
<div class="col s12 m6 p6 l12">
<div class="card equal-height-on-med">
<div class="card-content">