mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-12-22 23:13:46 +00:00
Fix #150 : l'utilisateur asso et ses machines ont toujours accès à internet
This commit is contained in:
parent
22c30c2775
commit
97593920e5
2 changed files with 14 additions and 6 deletions
|
@ -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):
|
||||
|
|
|
@ -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)"""
|
||||
|
|
Loading…
Reference in a new issue