From 2e53f7e8dac8e625b4ded184ee72aa9688e4de40 Mon Sep 17 00:00:00 2001 From: Gabriel Detraz Date: Wed, 10 Jan 2018 18:35:13 +0100 Subject: [PATCH] Suppression de la mise en cache sur les ban et whitelist --- users/models.py | 18 +++++++----------- users/views.py | 4 ++-- 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/users/models.py b/users/models.py index f844d7dd..ca44f542 100644 --- a/users/models.py +++ b/users/models.py @@ -350,7 +350,6 @@ class User(FieldPermissionModelMixin, AbstractBaseUser, PermissionsMixin): else: return self.is_adherent() - @cached_property def end_ban(self): """ Renvoie la date de fin de ban d'un user, False sinon """ date_max = Ban.objects.filter( @@ -358,7 +357,6 @@ class User(FieldPermissionModelMixin, AbstractBaseUser, PermissionsMixin): ).aggregate(models.Max('date_end'))['date_end__max'] return date_max - @cached_property def end_whitelist(self): """ Renvoie la date de fin de whitelist d'un user, False sinon """ date_max = Whitelist.objects.filter( @@ -366,10 +364,9 @@ class User(FieldPermissionModelMixin, AbstractBaseUser, PermissionsMixin): ).aggregate(models.Max('date_end'))['date_end__max'] return date_max - @cached_property def is_ban(self): """ Renvoie si un user est banni ou non """ - end = self.end_ban + end = self.end_ban() if not end: return False elif end < DT_NOW: @@ -377,10 +374,9 @@ class User(FieldPermissionModelMixin, AbstractBaseUser, PermissionsMixin): else: return True - @cached_property def is_whitelisted(self): """ Renvoie si un user est whitelisté ou non """ - end = self.end_whitelist + end = self.end_whitelist() if not end: return False elif end < DT_NOW: @@ -391,20 +387,20 @@ class User(FieldPermissionModelMixin, AbstractBaseUser, PermissionsMixin): def has_access(self): """ 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) + and not self.is_ban() and (self.is_connected() or self.is_whitelisted()) def end_access(self): """ Renvoie la date de fin normale d'accès (adhésion ou whiteliste)""" if not self.end_connexion(): - if not self.end_whitelist: + if not self.end_whitelist(): return None else: - return self.end_whitelist + return self.end_whitelist() else: - if not self.end_whitelist: + if not self.end_whitelist(): return self.end_connexion() else: - return max(self.end_connexion(), self.end_whitelist) + return max(self.end_connexion(), self.end_whitelist()) @cached_property def solde(self): diff --git a/users/views.py b/users/views.py index fbdbc73b..bff33907 100644 --- a/users/views.py +++ b/users/views.py @@ -359,7 +359,7 @@ def add_ban(request, user, userid): 'users:profil', kwargs={'userid':str(userid)} )) - if user.is_ban: + if user.is_ban(): messages.error( request, "Attention, cet utilisateur a deja un bannissement actif" @@ -408,7 +408,7 @@ def add_whitelist(request, user, userid): 'users:profil', kwargs={'userid':str(userid)} )) - if user.is_whitelisted: + if user.is_whitelisted(): messages.error( request, "Attention, cet utilisateur a deja un accès gracieux actif"