From 11a59ee553e19ccec38324c6412259ae28c3fb26 Mon Sep 17 00:00:00 2001 From: Gabriel Detraz Date: Thu, 19 Jul 2018 20:37:01 +0200 Subject: [PATCH] Fix #126 --- users/models.py | 17 +++++++++++------ users/views.py | 7 +------ 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/users/models.py b/users/models.py index 4a10dd90..9ade4d11 100644 --- a/users/models.py +++ b/users/models.py @@ -479,16 +479,19 @@ class User(RevMixin, FieldPermissionModelMixin, AbstractBaseUser, interface.save() def archive(self): - """ Archive l'user : appelle unassign_ips() puis passe state à - ARCHIVE""" + """ Archive l'user""" self.unassign_ips() - self.state = User.STATE_ARCHIVE def unarchive(self): - """ Désarchive l'user : réassigne ses ip et le passe en state - ACTIVE""" + """ Désarchive l'user""" self.assign_ips() - self.state = User.STATE_ACTIVE + + def state_sync(self): + """Archive, or unarchive, if the user was not active/or archived before""" + if self.__original_state != self.STATE_ACTIVE and self.state == self.STATE_ACTIVE: + self.unarchive() + elif self.__original_state != self.STATE_ARCHIVE and self.state == self.STATE_ARCHIVE: + self.archive() def ldap_sync(self, base=True, access_refresh=True, mac_refresh=True, group_refresh=False): @@ -879,6 +882,7 @@ class User(RevMixin, FieldPermissionModelMixin, AbstractBaseUser, 'force': self.can_change_force, 'selfpasswd': self.check_selfpasswd, } + self.__original_state = self.state def __str__(self): return self.pseudo @@ -1007,6 +1011,7 @@ def user_post_save(**kwargs): user = kwargs['instance'] if is_created: user.notif_inscription() + user.state_sync() user.ldap_sync( base=True, access_refresh=True, diff --git a/users/views.py b/users/views.py index 0c04a2d9..bf52af57 100644 --- a/users/views.py +++ b/users/views.py @@ -221,15 +221,10 @@ def edit_info(request, user, userid): @login_required @can_edit(User, 'state') def state(request, user, userid): - """ Changer l'etat actif/desactivé/archivé d'un user, - need droit bureau """ + """ Changer l'etat actif/desactivé/archivé d'un user""" state_form = StateForm(request.POST or None, instance=user) if state_form.is_valid(): if state_form.changed_data: - if state_form.cleaned_data['state'] == User.STATE_ARCHIVE: - user.archive() - elif state_form.cleaned_data['state'] == User.STATE_ACTIVE: - user.unarchive() state_form.save() messages.success(request, "Etat changé avec succès") return redirect(reverse(