mirror of
https://github.com/ae-utbm/sith.git
synced 2026-09-26 14:14:20 +00:00
use DatetimeField to store cgu approval
Au lieu de dire si l'utilisateur a approuvé les CGUs ou non, on dit quand est-ce qu'il les a approuvées. Si la date de la dernière approbation est antérieure à la date de la dernière révision des CGUs, alors on demande à nouveau de les approuver.
This commit is contained in:
+10
-1
@@ -44,6 +44,7 @@ from django.core.files.base import ContentFile
|
||||
from django.core.mail import send_mail
|
||||
from django.db import models, transaction
|
||||
from django.db.models import Exists, F, OuterRef, Q
|
||||
from django.db.models.aggregates import Max
|
||||
from django.urls import reverse
|
||||
from django.utils import timezone
|
||||
from django.utils.functional import cached_property
|
||||
@@ -291,7 +292,7 @@ class User(AbstractUser):
|
||||
),
|
||||
blank=True,
|
||||
)
|
||||
cgu_approved = models.BooleanField(_("ToS approved"), default=False)
|
||||
cgu_approved_at = models.DateTimeField(_("ToS approved at"), null=True, blank=False)
|
||||
godfathers = models.ManyToManyField("User", related_name="godchildren", blank=True)
|
||||
|
||||
objects = CustomUserManager()
|
||||
@@ -419,6 +420,14 @@ class User(AbstractUser):
|
||||
)
|
||||
return age
|
||||
|
||||
@cached_property
|
||||
def approved_current_cgu(self) -> bool:
|
||||
qs = PageRev.objects.filter(page___full_name=settings.SITH_CGU_PAGE)
|
||||
return (
|
||||
self.cgu_approved_at is not None
|
||||
and self.cgu_approved_at > qs.aggregate(date=Max("date"))["date"]
|
||||
)
|
||||
|
||||
def make_home(self):
|
||||
if self.home is None:
|
||||
home_root = SithFile.objects.filter(parent=None, name="users").first()
|
||||
|
||||
Reference in New Issue
Block a user