8
0
Fork 0
mirror of https://gitlab2.federez.net/re2o/re2o synced 2024-11-25 22:22:26 +00:00

Merge branch 'fix_126' into 'master'

Fix #126

Closes #126

See merge request federez/re2o!188
This commit is contained in:
klafyvel 2018-07-22 13:16:55 +02:00
commit f6a152f033
2 changed files with 12 additions and 12 deletions

View file

@ -487,16 +487,19 @@ class User(RevMixin, FieldPermissionModelMixin, AbstractBaseUser,
interface.save() interface.save()
def archive(self): def archive(self):
""" Archive l'user : appelle unassign_ips() puis passe state à """ Filling the user; no more active"""
ARCHIVE"""
self.unassign_ips() self.unassign_ips()
self.state = User.STATE_ARCHIVE
def unarchive(self): def unarchive(self):
""" Désarchive l'user : réassigne ses ip et le passe en state """Unfilling the user"""
ACTIVE"""
self.assign_ips() 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, def ldap_sync(self, base=True, access_refresh=True, mac_refresh=True,
group_refresh=False): group_refresh=False):
@ -884,6 +887,7 @@ class User(RevMixin, FieldPermissionModelMixin, AbstractBaseUser,
'force': self.can_change_force, 'force': self.can_change_force,
'selfpasswd': self.check_selfpasswd, 'selfpasswd': self.check_selfpasswd,
} }
self.__original_state = self.state
def __str__(self): def __str__(self):
return self.pseudo return self.pseudo
@ -1012,6 +1016,7 @@ def user_post_save(**kwargs):
user = kwargs['instance'] user = kwargs['instance']
if is_created: if is_created:
user.notif_inscription() user.notif_inscription()
user.state_sync()
user.ldap_sync( user.ldap_sync(
base=True, base=True,
access_refresh=True, access_refresh=True,

View file

@ -221,15 +221,10 @@ def edit_info(request, user, userid):
@login_required @login_required
@can_edit(User, 'state') @can_edit(User, 'state')
def state(request, user, userid): def state(request, user, userid):
""" Changer l'etat actif/desactivé/archivé d'un user, """ Change the state (active/unactive/archived) of a user"""
need droit bureau """
state_form = StateForm(request.POST or None, instance=user) state_form = StateForm(request.POST or None, instance=user)
if state_form.is_valid(): if state_form.is_valid():
if state_form.changed_data: 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() state_form.save()
messages.success(request, "Etat changé avec succès") messages.success(request, "Etat changé avec succès")
return redirect(reverse( return redirect(reverse(