From 59a9b9f795be96d47dcc14448e6fe64a0481cdb0 Mon Sep 17 00:00:00 2001
From: Lucas Brandstaetter <lucas@brandstaetter.tech>
Date: Sun, 20 Oct 2024 17:26:50 +0000
Subject: [PATCH] Add publication_date to Conference model

With this change and the model managers we can prevent content from
being displayed before the teams are ready.
Test needs to be modified to reflect the new behavior of not showing
non public information, while the conference is not public yet.
---
 src/api/serializers.py                        |  2 ++
 src/core/locale/de/LC_MESSAGES/django.po      |  6 +++++
 src/core/locale/en/LC_MESSAGES/django.po      |  6 +++++
 .../0151_conference_publication_date.py       | 23 +++++++++++++++++++
 src/core/models/base_managers.py              |  2 ++
 src/core/models/conference.py                 |  7 ++++++
 src/core/tests/assemblies.py                  |  2 +-
 7 files changed, 47 insertions(+), 1 deletion(-)
 create mode 100644 src/core/migrations/0151_conference_publication_date.py

diff --git a/src/api/serializers.py b/src/api/serializers.py
index ac19fd91e..f6a5ef970 100644
--- a/src/api/serializers.py
+++ b/src/api/serializers.py
@@ -114,6 +114,7 @@ class ConferenceSerializer(HubModelSerializer):
             'is_public',
             'start',
             'end',
+            'publication_date',
             'registration_start',
             'registration_deadline',
             'tracks',
@@ -121,6 +122,7 @@ class ConferenceSerializer(HubModelSerializer):
         staff_only_fields = [
             'is_public',
             'publication_date',
+            'registration_start',
         ]
 
 
diff --git a/src/core/locale/de/LC_MESSAGES/django.po b/src/core/locale/de/LC_MESSAGES/django.po
index 6ab69f2a6..f8d30d14d 100644
--- a/src/core/locale/de/LC_MESSAGES/django.po
+++ b/src/core/locale/de/LC_MESSAGES/django.po
@@ -673,6 +673,12 @@ msgstr "Konferenz öffentlich anzeigen"
 msgid "Conference__is_public"
 msgstr "veröffentlicht"
 
+msgid "Conference__publication_date__help"
+msgstr "Veröffentlichungszeitpunkt für Inhalte für die Öffentlichkeit"
+
+msgid "Conference__publication_date"
+msgstr "Veröffentlichungszeitpunkt"
+
 msgid "Conference__registration_start__help"
 msgstr "Start der Registrierung für Assemblies."
 
diff --git a/src/core/locale/en/LC_MESSAGES/django.po b/src/core/locale/en/LC_MESSAGES/django.po
index d6ff37c16..dc6c5f67a 100644
--- a/src/core/locale/en/LC_MESSAGES/django.po
+++ b/src/core/locale/en/LC_MESSAGES/django.po
@@ -673,6 +673,12 @@ msgstr "show this conference publically"
 msgid "Conference__is_public"
 msgstr "is public"
 
+msgid "Conference__publication_date__help"
+msgstr "From this point in time the content will be displayed to the public."
+
+msgid "Conference__publication_date"
+msgstr "publication start"
+
 msgid "Conference__registration_start__help"
 msgstr "from this point in time registration will be available"
 
diff --git a/src/core/migrations/0151_conference_publication_date.py b/src/core/migrations/0151_conference_publication_date.py
new file mode 100644
index 000000000..89763a07b
--- /dev/null
+++ b/src/core/migrations/0151_conference_publication_date.py
@@ -0,0 +1,23 @@
+# Generated by Django 5.1.2 on 2024-10-20 17:25
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ("core", "0150_conference_registration_start"),
+    ]
+
+    operations = [
+        migrations.AddField(
+            model_name="conference",
+            name="publication_date",
+            field=models.DateTimeField(
+                blank=True,
+                help_text="Conference__publication_date__help",
+                null=True,
+                verbose_name="Conference__publication_date",
+            ),
+        ),
+    ]
diff --git a/src/core/models/base_managers.py b/src/core/models/base_managers.py
index 651ba1c3b..aa2ff05a5 100644
--- a/src/core/models/base_managers.py
+++ b/src/core/models/base_managers.py
@@ -157,6 +157,8 @@ class ConferenceManagerMixin(models.Manager, Generic[_ModelType]):
         Returns:
             QuerySet[_ModelType]: A Queryset of objects that are accessible for the given conference.
         """
+        if not conference.is_published:
+            return self.get_queryset().none()
         if isinstance(member, ConferenceMember):
             return self.apply_public_filter(self.get_conference_queryset(conference), member)
         return self.apply_public_filter(self.get_conference_queryset(conference))
diff --git a/src/core/models/conference.py b/src/core/models/conference.py
index c65edfe5e..0b8be5714 100644
--- a/src/core/models/conference.py
+++ b/src/core/models/conference.py
@@ -230,6 +230,9 @@ class Conference(models.Model):
     name = models.CharField(max_length=200, help_text=_('Conference__name__help'), verbose_name=_('Conference__name'))
 
     is_public = models.BooleanField(default=False, help_text=_('Conference__is_public__help'), verbose_name=_('Conference__is_public'))
+    publication_date = models.DateTimeField(
+        blank=True, null=True, help_text=_('Conference__publication_date__help'), verbose_name=_('Conference__publication_date')
+    )
     registration_start = models.DateTimeField(
         blank=True, null=True, help_text=_('Conference__registration_start__help'), verbose_name=_('Conference__registration_start')
     )
@@ -378,6 +381,10 @@ class Conference(models.Model):
             return self.start <= timezone.now()
         return self.start <= timezone.now() <= self.end
 
+    @cached_property
+    def is_published(self):
+        return self.is_public and (self.publication_date is None or self.publication_date < timezone.now())
+
     @cached_property
     def has_ended(self):
         return self.end is not None and timezone.now() > self.end
diff --git a/src/core/tests/assemblies.py b/src/core/tests/assemblies.py
index 3150f0ef2..052e0e193 100644
--- a/src/core/tests/assemblies.py
+++ b/src/core/tests/assemblies.py
@@ -9,7 +9,7 @@ from core.models.users import PlatformUser, UserCommunicationChannel
 
 class AssembliesTestsMixin(TestCase):
     def setUp(self):
-        self.conference = Conference(slug='foo', name='Foo Conference', mail_footer='This is serious business w/ legal stuff.')
+        self.conference = Conference(slug='foo', name='Foo Conference', mail_footer='This is serious business w/ legal stuff.', is_public=True)
         self.conference.save()
 
         self.user_mgmt = PlatformUser(username='manager')
-- 
GitLab