From cc6f98f92f6ab9995c20232b14b8f83b08ee2ac3 Mon Sep 17 00:00:00 2001 From: Gabriel Detraz Date: Tue, 5 Jul 2016 12:36:08 +0200 Subject: [PATCH] =?UTF-8?q?Fonction=20qui=20permet=20de=20savoir=20si=20un?= =?UTF-8?q?e=20machine=20a=20le=20droit=20=C3=A0=20internet=20ou=20non?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- machines/views.py | 6 ++++++ users/views.py | 5 +---- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/machines/views.py b/machines/views.py index f06eb5ff..5844d16c 100644 --- a/machines/views.py +++ b/machines/views.py @@ -10,6 +10,7 @@ from django.contrib import messages from .models import NewMachineForm, EditMachineForm, EditInterfaceForm, AddInterfaceForm, NewInterfaceForm from .models import Machine, Interface, IpList from users.models import User +from users.views import has_access def unassign_ips(user): machines = Interface.objects.filter(machine=Machine.objects.filter(user=user)) @@ -41,6 +42,11 @@ def unassign_ipv4(interface): interface.ipv4 = None interface.save() +def is_active(interface): + machine = interface.machine + user = machine.user + return machine.active and has_access(user) + def form(ctx, template, request): c = ctx c.update(csrf(request)) diff --git a/users/views.py b/users/views.py index d29e0621..2e00b1d7 100644 --- a/users/views.py +++ b/users/views.py @@ -62,10 +62,7 @@ def is_whitelisted(user): def has_access(user): """ Renvoie si un utilisateur a accès à internet""" - if user.state == User.STATE_ACTIVE and not is_ban(user) and ( is_adherent(user) or is_whitelisted(user)): - return True - else: - return False + return user.state == User.STATE_ACTIVE and not is_ban(user) and ( is_adherent(user) or is_whitelisted(user)) def form(ctx, template, request): c = ctx