Skip to content

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

Admin can not change his is_superuser flag

michal9b2bf7443e4b
diff --git a/saleor/dashboard/staff/forms.py b/saleor/dashboard/staff/forms.py
index 5f50038b57..dca3521135 100644
--- a/saleor/dashboard/staff/forms.py
+++ b/saleor/dashboard/staff/forms.py
@@ -4,6 +4,12 @@ from ...userprofile.models import User
class StaffForm(forms.ModelForm):
+ def __init__(self, *args, **kwargs):
+ self.admin = kwargs.pop('admin', '1')
+ super(StaffForm, self).__init__(*args, **kwargs)
+ if self.admin == self.instance:
+ self.fields['is_superuser'].widget.attrs['disabled'] = True
+
class Meta:
model = User
fields = ['email', 'groups', 'is_superuser', 'is_staff',
diff --git a/saleor/dashboard/staff/views.py b/saleor/dashboard/staff/views.py
index f263cd67bf..4b977ffd50 100644
--- a/saleor/dashboard/staff/views.py
+++ b/saleor/dashboard/staff/views.py
@@ -27,13 +27,8 @@ def staff_list(request):
def staff_details(request, pk):
queryset = User.objects.filter(is_staff=True)
staff_member = get_object_or_404(queryset, pk=pk)
-
- # if int(pk) == int(request.user.pk):
- # print pk
- # print request.user.pk
- # print "Same users"
-
- form = StaffForm(request.POST or None, instance=staff_member)
+ form = StaffForm(request.POST or None, instance=staff_member,
+ admin=request.user)
if form.is_valid():
form.save()
ctx = {'staff_member': staff_member, 'form': form}
diff --git a/templates/materializecssform/field.html b/templates/materializecssform/field.html
index 8ea34328e6..66ae5ee554 100644
--- a/templates/materializecssform/field.html
+++ b/templates/materializecssform/field.html
@@ -7,7 +7,7 @@
<div class="{{ classes.single_value }}">
<p>
{% if field.auto_id %}
- <input id="{{ field.auto_id }}" name="{{ field.html_name }}" class="filled-in" type="checkbox"{% if field.value %} checked="checked" {% endif %}>
+ <input id="{{ field.auto_id }}" name="{{ field.html_name }}" class="filled-in" type="checkbox"{% if field.value %} checked="checked" {% endif %} {% if field.field.widget.attrs.disabled %} disabled {% endif %}>
<label for="{{ field.auto_id }}">
{{ field.label }}
</label>