mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-11-22 03:13:12 +00:00
Reassigne des ips au désarchivage
This commit is contained in:
parent
36f95c8864
commit
3bdd17a090
2 changed files with 22 additions and 6 deletions
|
@ -11,14 +11,19 @@ from .models import NewMachineForm, EditMachineForm, EditInterfaceForm, AddInter
|
|||
from .models import Machine, Interface, IpList
|
||||
from users.models import User
|
||||
|
||||
def unassign_ip(machine):
|
||||
machine.ipv4 = None
|
||||
machine.save()
|
||||
|
||||
def unassign_ips(user):
|
||||
machines = Interface.objects.filter(machine=Machine.objects.filter(user=user))
|
||||
for machine in machines:
|
||||
unassign_ip(machine)
|
||||
unassign_ipv4(machine)
|
||||
return
|
||||
|
||||
def assign_ips(user):
|
||||
""" Assign une ipv4 aux machines d'un user """
|
||||
machines = Interface.objects.filter(machine=Machine.objects.filter(user=user))
|
||||
for machine in machines:
|
||||
if not machine.ipv4:
|
||||
interface = assign_ipv4(machine)
|
||||
interface.save()
|
||||
return
|
||||
|
||||
def free_ip():
|
||||
|
@ -32,6 +37,10 @@ def assign_ipv4(interface):
|
|||
interface.ipv4 = free_ips[0]
|
||||
return interface
|
||||
|
||||
def unassign_ipv4(interface):
|
||||
interface.ipv4 = None
|
||||
interface.save()
|
||||
|
||||
def form(ctx, template, request):
|
||||
c = ctx
|
||||
c.update(csrf(request))
|
||||
|
|
|
@ -15,7 +15,7 @@ from machines.models import Machine, Interface
|
|||
from users.forms import PassForm
|
||||
from search.models import SearchForm
|
||||
from cotisations.views import is_adherent, end_adhesion
|
||||
from machines.views import unassign_ips
|
||||
from machines.views import unassign_ips, assign_ips
|
||||
|
||||
from re2o.login import makeSecret, hashNT
|
||||
|
||||
|
@ -24,6 +24,11 @@ def archive(user):
|
|||
unassign_ips(user)
|
||||
return
|
||||
|
||||
def unarchive(user):
|
||||
""" Triger actions au desarchivage d'un user """
|
||||
assign_ips(user)
|
||||
return
|
||||
|
||||
def end_ban(user):
|
||||
""" Renvoie la date de fin de ban d'un user, False sinon """
|
||||
date_max = Ban.objects.all().filter(user=user).aggregate(Max('date_end'))['date_end__max']
|
||||
|
@ -83,6 +88,8 @@ def state(request, userid):
|
|||
if state.has_changed():
|
||||
if state.cleaned_data['state'] == User.STATE_ARCHIVED:
|
||||
archive(user)
|
||||
else:
|
||||
unarchive(user)
|
||||
state.save()
|
||||
messages.success(request, "Etat changé avec succès")
|
||||
return redirect("/users/")
|
||||
|
|
Loading…
Reference in a new issue