mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-09-12 01:03:09 +00:00
Make call to remove_user_room cleaner
This commit is contained in:
parent
86813b1a47
commit
d1365e2c9e
2 changed files with 20 additions and 26 deletions
|
@ -203,11 +203,13 @@ def all_active_assigned_interfaces_count():
|
||||||
return all_active_interfaces_count().filter(ipv4__isnull=False)
|
return all_active_interfaces_count().filter(ipv4__isnull=False)
|
||||||
|
|
||||||
|
|
||||||
def remove_user_room(room):
|
def remove_user_room(room, force=True):
|
||||||
""" Déménage de force l'ancien locataire de la chambre """
|
""" Déménage de force l'ancien locataire de la chambre """
|
||||||
try:
|
try:
|
||||||
user = Adherent.objects.get(room=room)
|
user = Adherent.objects.get(room=room)
|
||||||
except Adherent.DoesNotExist:
|
except Adherent.DoesNotExist:
|
||||||
return
|
return
|
||||||
user.room = None
|
|
||||||
user.save()
|
if force or not user.has_access():
|
||||||
|
user.room = None
|
||||||
|
user.save()
|
||||||
|
|
|
@ -351,29 +351,6 @@ class AdherentForm(FormRevMixin, FieldPermissionFormMixin, ModelForm):
|
||||||
label=_("Force the move?"), initial=False, required=False
|
label=_("Force the move?"), initial=False, required=False
|
||||||
)
|
)
|
||||||
|
|
||||||
def clean(self):
|
|
||||||
# Handle case where regular users can force move
|
|
||||||
can_force_move = OptionalUser.get_cached_value("self_force_move_disabled_user_room")
|
|
||||||
if not can_force_move:
|
|
||||||
return super(AdherentForm, self).clean()
|
|
||||||
|
|
||||||
# Ensure the user entered a proper room
|
|
||||||
room = self.cleaned_data.get("room")
|
|
||||||
if not room:
|
|
||||||
return super(AdherentForm, self).clean()
|
|
||||||
|
|
||||||
try:
|
|
||||||
# If a user already is register for this room
|
|
||||||
# but their connection has expired, allow force move
|
|
||||||
user = Adherent.objects.get(room=room)
|
|
||||||
if user and not user.has_access():
|
|
||||||
remove_user_room(room)
|
|
||||||
except Adherent.DoesNotExist:
|
|
||||||
pass
|
|
||||||
|
|
||||||
# Run standard clean process
|
|
||||||
return super(AdherentForm, self).clean()
|
|
||||||
|
|
||||||
def clean_email(self):
|
def clean_email(self):
|
||||||
if not OptionalUser.objects.first().local_email_domain in self.cleaned_data.get(
|
if not OptionalUser.objects.first().local_email_domain in self.cleaned_data.get(
|
||||||
"email"
|
"email"
|
||||||
|
@ -402,6 +379,21 @@ class AdherentForm(FormRevMixin, FieldPermissionFormMixin, ModelForm):
|
||||||
remove_user_room(room)
|
remove_user_room(room)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
def clean_room(self):
|
||||||
|
"""On supprime l'ancien user de la chambre si l'option est activée,
|
||||||
|
et que l'ancien user a une connexion désactivée"""
|
||||||
|
# Handle case where regular users can force move
|
||||||
|
room = self.cleaned_data.get("room")
|
||||||
|
can_force_move = OptionalUser.get_cached_value("self_force_move_disabled_user_room")
|
||||||
|
if not can_force_move or not room:
|
||||||
|
return room
|
||||||
|
|
||||||
|
# Remove the previous user's room, if allowed and necessary
|
||||||
|
remove_user_room(room, force=False)
|
||||||
|
|
||||||
|
# Run standard clean process
|
||||||
|
return room
|
||||||
|
|
||||||
|
|
||||||
class AdherentCreationForm(AdherentForm):
|
class AdherentCreationForm(AdherentForm):
|
||||||
"""Formulaire de création d'un user.
|
"""Formulaire de création d'un user.
|
||||||
|
|
Loading…
Reference in a new issue