mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-12-25 08:23:46 +00:00
Suppression de la mise en cache sur les ban et whitelist
This commit is contained in:
parent
db349bb544
commit
2e53f7e8da
2 changed files with 9 additions and 13 deletions
|
@ -350,7 +350,6 @@ class User(FieldPermissionModelMixin, AbstractBaseUser, PermissionsMixin):
|
||||||
else:
|
else:
|
||||||
return self.is_adherent()
|
return self.is_adherent()
|
||||||
|
|
||||||
@cached_property
|
|
||||||
def end_ban(self):
|
def end_ban(self):
|
||||||
""" 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.filter(
|
date_max = Ban.objects.filter(
|
||||||
|
@ -358,7 +357,6 @@ class User(FieldPermissionModelMixin, AbstractBaseUser, PermissionsMixin):
|
||||||
).aggregate(models.Max('date_end'))['date_end__max']
|
).aggregate(models.Max('date_end'))['date_end__max']
|
||||||
return date_max
|
return date_max
|
||||||
|
|
||||||
@cached_property
|
|
||||||
def end_whitelist(self):
|
def end_whitelist(self):
|
||||||
""" Renvoie la date de fin de whitelist d'un user, False sinon """
|
""" Renvoie la date de fin de whitelist d'un user, False sinon """
|
||||||
date_max = Whitelist.objects.filter(
|
date_max = Whitelist.objects.filter(
|
||||||
|
@ -366,10 +364,9 @@ class User(FieldPermissionModelMixin, AbstractBaseUser, PermissionsMixin):
|
||||||
).aggregate(models.Max('date_end'))['date_end__max']
|
).aggregate(models.Max('date_end'))['date_end__max']
|
||||||
return date_max
|
return date_max
|
||||||
|
|
||||||
@cached_property
|
|
||||||
def is_ban(self):
|
def is_ban(self):
|
||||||
""" Renvoie si un user est banni ou non """
|
""" Renvoie si un user est banni ou non """
|
||||||
end = self.end_ban
|
end = self.end_ban()
|
||||||
if not end:
|
if not end:
|
||||||
return False
|
return False
|
||||||
elif end < DT_NOW:
|
elif end < DT_NOW:
|
||||||
|
@ -377,10 +374,9 @@ class User(FieldPermissionModelMixin, AbstractBaseUser, PermissionsMixin):
|
||||||
else:
|
else:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@cached_property
|
|
||||||
def is_whitelisted(self):
|
def is_whitelisted(self):
|
||||||
""" Renvoie si un user est whitelisté ou non """
|
""" Renvoie si un user est whitelisté ou non """
|
||||||
end = self.end_whitelist
|
end = self.end_whitelist()
|
||||||
if not end:
|
if not end:
|
||||||
return False
|
return False
|
||||||
elif end < DT_NOW:
|
elif end < DT_NOW:
|
||||||
|
@ -391,20 +387,20 @@ class User(FieldPermissionModelMixin, AbstractBaseUser, PermissionsMixin):
|
||||||
def has_access(self):
|
def has_access(self):
|
||||||
""" Renvoie si un utilisateur a accès à internet """
|
""" Renvoie si un utilisateur a accès à internet """
|
||||||
return self.state == User.STATE_ACTIVE\
|
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):
|
def end_access(self):
|
||||||
""" Renvoie la date de fin normale d'accès (adhésion ou whiteliste)"""
|
""" Renvoie la date de fin normale d'accès (adhésion ou whiteliste)"""
|
||||||
if not self.end_connexion():
|
if not self.end_connexion():
|
||||||
if not self.end_whitelist:
|
if not self.end_whitelist():
|
||||||
return None
|
return None
|
||||||
else:
|
else:
|
||||||
return self.end_whitelist
|
return self.end_whitelist()
|
||||||
else:
|
else:
|
||||||
if not self.end_whitelist:
|
if not self.end_whitelist():
|
||||||
return self.end_connexion()
|
return self.end_connexion()
|
||||||
else:
|
else:
|
||||||
return max(self.end_connexion(), self.end_whitelist)
|
return max(self.end_connexion(), self.end_whitelist())
|
||||||
|
|
||||||
@cached_property
|
@cached_property
|
||||||
def solde(self):
|
def solde(self):
|
||||||
|
|
|
@ -359,7 +359,7 @@ def add_ban(request, user, userid):
|
||||||
'users:profil',
|
'users:profil',
|
||||||
kwargs={'userid':str(userid)}
|
kwargs={'userid':str(userid)}
|
||||||
))
|
))
|
||||||
if user.is_ban:
|
if user.is_ban():
|
||||||
messages.error(
|
messages.error(
|
||||||
request,
|
request,
|
||||||
"Attention, cet utilisateur a deja un bannissement actif"
|
"Attention, cet utilisateur a deja un bannissement actif"
|
||||||
|
@ -408,7 +408,7 @@ def add_whitelist(request, user, userid):
|
||||||
'users:profil',
|
'users:profil',
|
||||||
kwargs={'userid':str(userid)}
|
kwargs={'userid':str(userid)}
|
||||||
))
|
))
|
||||||
if user.is_whitelisted:
|
if user.is_whitelisted():
|
||||||
messages.error(
|
messages.error(
|
||||||
request,
|
request,
|
||||||
"Attention, cet utilisateur a deja un accès gracieux actif"
|
"Attention, cet utilisateur a deja un accès gracieux actif"
|
||||||
|
|
Loading…
Reference in a new issue