From 97593920e5a6d9adbfce7f23e5ea0a5e6d76b203 Mon Sep 17 00:00:00 2001 From: Gabriel Detraz Date: Sat, 29 Dec 2018 20:35:01 +0100 Subject: [PATCH] =?UTF-8?q?Fix=20#150=20:=20l'utilisateur=20asso=20et=20se?= =?UTF-8?q?s=20machines=20ont=20toujours=20acc=C3=A8s=20=C3=A0=20internet?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- re2o/utils.py | 17 ++++++++++++----- users/models.py | 3 ++- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/re2o/utils.py b/re2o/utils.py index 7ec4bd36..20218a81 100644 --- a/re2o/utils.py +++ b/re2o/utils.py @@ -42,7 +42,7 @@ from django.db.models import Q from cotisations.models import Cotisation, Facture, Vente from machines.models import Interface, Machine from users.models import Adherent, User, Ban, Whitelist - +from preferences.models import AssoOption def all_adherent(search_time=None): """ Fonction renvoyant tous les users adherents. Optimisee pour n'est @@ -88,11 +88,14 @@ def all_whitelisted(search_time=None): def all_has_access(search_time=None): - """ Renvoie tous les users beneficiant d'une connexion - : user adherent ou whiteliste et non banni """ + """ Return all connected users : active users and whitelisted + + asso_user defined in AssoOption pannel + ---- + Renvoie tous les users beneficiant d'une connexion + : user adherent et whiteliste non banni plus l'utilisateur asso""" if search_time is None: search_time = timezone.now() - return User.objects.filter( + filter_user = ( Q(state=User.STATE_ACTIVE) & ~Q(ban__in=Ban.objects.filter(Q(date_start__lt=search_time) & Q(date_end__gt=search_time))) & (Q(whitelist__in=Whitelist.objects.filter(Q(date_start__lt=search_time) & Q(date_end__gt=search_time))) | @@ -107,7 +110,11 @@ def all_has_access(search_time=None): ).filter(Q(date_start__lt=search_time) & Q(date_end__gt=search_time)) ) ))) - ).distinct() + ) + asso_user = AssoOption.get_cached_value('utilisateur_asso') + if asso_user: + filter_user |= Q(id=asso_user.id) + return User.objects.filter(filter_user).distinct() def filter_active_interfaces(interface_set): diff --git a/users/models.py b/users/models.py index a0985675..fe96df1e 100755 --- a/users/models.py +++ b/users/models.py @@ -475,7 +475,8 @@ class User(RevMixin, FieldPermissionModelMixin, AbstractBaseUser, """ Renvoie si un utilisateur a accès à internet """ return (self.state == User.STATE_ACTIVE and not self.is_ban() and - (self.is_connected() or self.is_whitelisted())) + (self.is_connected() or self.is_whitelisted())) \ + or self == AssoOption.get_cached_value('utilisateur_asso') def end_access(self): """ Renvoie la date de fin normale d'accès (adhésion ou whiteliste)"""