From 6f3fc983acccd3c2d33f83d1bcfb68e5f3e48d79 Mon Sep 17 00:00:00 2001 From: Hugo LEVY-FALK Date: Thu, 3 May 2018 10:26:17 +0200 Subject: [PATCH] Suppression de superuser --- users/templates/users/aff_listright.html | 2 +- users/urls.py | 3 +++ users/views.py | 10 ++++++++++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/users/templates/users/aff_listright.html b/users/templates/users/aff_listright.html index 7807c1d3..8906b38e 100644 --- a/users/templates/users/aff_listright.html +++ b/users/templates/users/aff_listright.html @@ -58,7 +58,7 @@ with this program; if not, write to the Free Software Foundation, Inc., {% for user in superuser_right %}
  • {{user}} - +
  • diff --git a/users/urls.py b/users/urls.py index 05f72be0..5d868196 100644 --- a/users/urls.py +++ b/users/urls.py @@ -43,6 +43,9 @@ urlpatterns = [ url(r'^del_group/(?P[0-9]+)/(?P[0-9]+)$', views.del_group, name='del-group'), + url(r'^del_superuser/(?P[0-9]+)$', + views.del_superuser, + name='del-superuser'), url(r'^new_serviceuser/$', views.new_serviceuser, name='new-serviceuser'), url(r'^edit_serviceuser/(?P[0-9]+)$', views.edit_serviceuser, diff --git a/users/views.py b/users/views.py index 797b3eb2..2ed4f3fb 100644 --- a/users/views.py +++ b/users/views.py @@ -294,6 +294,16 @@ def del_group(request, user, listrightid, **_kwargs): return HttpResponseRedirect(request.META.get('HTTP_REFERER')) +@login_required +@can_edit(User, 'groups') +def del_superuser(request, user, **_kwargs): + """Remove the superuser right of an user.""" + user.is_superuser = False + user.save() + messages.success(request, "%s n'est plus superuser" % user) + return HttpResponseRedirect(request.META.get('HTTP_REFERER')) + + @login_required @can_create(ServiceUser) def new_serviceuser(request):