8
0
Fork 0
mirror of https://gitlab2.federez.net/re2o/re2o synced 2024-12-26 00:43:46 +00:00

Reassigne des ips au désarchivage

This commit is contained in:
Gabriel Detraz 2016-07-04 17:13:26 +02:00
parent a0c4c35fd1
commit ffb84ec97c
2 changed files with 22 additions and 6 deletions

View file

@ -11,14 +11,19 @@ from .models import NewMachineForm, EditMachineForm, EditInterfaceForm, AddInter
from .models import Machine, Interface, IpList from .models import Machine, Interface, IpList
from users.models import User from users.models import User
def unassign_ip(machine):
machine.ipv4 = None
machine.save()
def unassign_ips(user): def unassign_ips(user):
machines = Interface.objects.filter(machine=Machine.objects.filter(user=user)) machines = Interface.objects.filter(machine=Machine.objects.filter(user=user))
for machine in machines: 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 return
def free_ip(): def free_ip():
@ -32,6 +37,10 @@ def assign_ipv4(interface):
interface.ipv4 = free_ips[0] interface.ipv4 = free_ips[0]
return interface return interface
def unassign_ipv4(interface):
interface.ipv4 = None
interface.save()
def form(ctx, template, request): def form(ctx, template, request):
c = ctx c = ctx
c.update(csrf(request)) c.update(csrf(request))

View file

@ -15,7 +15,7 @@ from machines.models import Machine, Interface
from users.forms import PassForm from users.forms import PassForm
from search.models import SearchForm from search.models import SearchForm
from cotisations.views import is_adherent, end_adhesion 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 from re2o.login import makeSecret, hashNT
@ -24,6 +24,11 @@ def archive(user):
unassign_ips(user) unassign_ips(user)
return return
def unarchive(user):
""" Triger actions au desarchivage d'un user """
assign_ips(user)
return
def end_ban(user): def end_ban(user):
""" Renvoie la date de fin de ban d'un user, False sinon """ """ 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'] 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.has_changed():
if state.cleaned_data['state'] == User.STATE_ARCHIVED: if state.cleaned_data['state'] == User.STATE_ARCHIVED:
archive(user) archive(user)
else:
unarchive(user)
state.save() state.save()
messages.success(request, "Etat changé avec succès") messages.success(request, "Etat changé avec succès")
return redirect("/users/") return redirect("/users/")