From f50c2904e23ccac44ad59f586043ac9c7728e3c4 Mon Sep 17 00:00:00 2001 From: Antoine Nguyen Date: Tue, 25 Dec 2012 10:14:10 +0100 Subject: [PATCH] Leave if the old group and the one are equals. fix #354 --- modoboa/admin/forms.py | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/modoboa/admin/forms.py b/modoboa/admin/forms.py index 266b2a1d3..6a1607eaa 100644 --- a/modoboa/admin/forms.py +++ b/modoboa/admin/forms.py @@ -421,17 +421,20 @@ class AccountFormGeneral(forms.ModelForm): role = self.cleaned_data["role"] elif self.user.group == "DomainAdmins" and self.user != account: role = "SimpleUsers" - if role is not None: - account.groups.clear() - if role == "SuperAdmins": - account.is_superuser = True - self.give_all_accesses(account) - else: - if account.is_superuser: - ObjectAccess.objects.filter(user=account).delete() - account.is_superuser = False - account.groups.add(Group.objects.get(name=role)) - account.save() + + if role is None or account.group == role: + return account + + account.groups.clear() + if role == "SuperAdmins": + account.is_superuser = True + self.give_all_accesses(account) + else: + if account.is_superuser: + ObjectAccess.objects.filter(user=account).delete() + account.is_superuser = False + account.groups.add(Group.objects.get(name=role)) + account.save() return account class AccountFormMail(forms.Form, DynamicForm):