From 7faa61dff3969d9978ed4875eb33c48602f1c7b6 Mon Sep 17 00:00:00 2001 From: Gabriel Detraz Date: Mon, 31 Oct 2016 17:52:16 +0100 Subject: [PATCH] Fix le prb de destruction de droits --- users/admin.py | 2 +- users/migrations/0038_auto_20161031_0258.py | 29 +++++++++++++++++++++ users/views.py | 13 ++++++--- 3 files changed, 39 insertions(+), 5 deletions(-) create mode 100644 users/migrations/0038_auto_20161031_0258.py diff --git a/users/admin.py b/users/admin.py index da0293cc..c0bbc75d 100644 --- a/users/admin.py +++ b/users/admin.py @@ -44,7 +44,7 @@ class ListRightAdmin(VersionAdmin): class ListShellAdmin(VersionAdmin): list_display = ('shell',) -class RightAdmin(admin.ModelAdmin): +class RightAdmin(VersionAdmin): list_display = ('user', 'right') class RequestAdmin(admin.ModelAdmin): diff --git a/users/migrations/0038_auto_20161031_0258.py b/users/migrations/0038_auto_20161031_0258.py new file mode 100644 index 00000000..dc621aa0 --- /dev/null +++ b/users/migrations/0038_auto_20161031_0258.py @@ -0,0 +1,29 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('users', '0037_auto_20161028_1906'), + ] + + operations = [ + migrations.AlterField( + model_name='ldapserviceuser', + name='dn', + field=models.CharField(max_length=200), + ), + migrations.AlterField( + model_name='ldapuser', + name='dn', + field=models.CharField(max_length=200), + ), + migrations.AlterField( + model_name='ldapusergroup', + name='dn', + field=models.CharField(max_length=200), + ), + ] diff --git a/users/views.py b/users/views.py index 279d2868..8983a60f 100644 --- a/users/views.py +++ b/users/views.py @@ -173,7 +173,10 @@ def add_right(request, userid): right = right.save(commit=False) right.user = user try: - right.save() + with transaction.atomic(), reversion.create_revision(): + reversion.set_user(request.user) + reversion.set_comment("Ajout du droit %s" % right.right) + right.save() messages.success(request, "Droit ajouté") except IntegrityError: pass @@ -184,13 +187,15 @@ def add_right(request, userid): @permission_required('bureau') def del_right(request): user_right_list = DelRightForm(request.POST or None) - right_list = ListRight.objects.all() if user_right_list.is_valid(): right_del = user_right_list.cleaned_data['rights'] - right_del.delete() + with transaction.atomic(), reversion.create_revision(): + reversion.set_user(request.user) + reversion.set_comment("Retrait des droit %s" % ','.join(str(deleted_right) for deleted_right in right_del)) + right_del.delete() messages.success(request, "Droit retiré avec succès") return redirect("/users/") - return form({'user_right_list': user_right_list, 'right_list': right_list}, 'users/index_rights.html', request) + return form({'userform': user_right_list}, 'users/user.html', request) @login_required @permission_required('bofh')