From 1ce5afa224283c119888142a3bc3ee47ebb6e1ab Mon Sep 17 00:00:00 2001
From: Michael Bauer <michael-bauer@posteo.de>
Date: Thu, 23 Jan 2025 14:19:16 +0100
Subject: [PATCH 1/3] Pass timezone to backend if recurring personal-event

Also simplify & unify with recurring.
---
 .../personal_event/PersonalEventDialog.vue    |  7 ++-
 .../personal_event/personalEvent.graphql      | 63 ++++++++-----------
 aleksis/core/schema/personal_event.py         |  9 +--
 3 files changed, 35 insertions(+), 44 deletions(-)

diff --git a/aleksis/core/frontend/components/calendar/personal_event/PersonalEventDialog.vue b/aleksis/core/frontend/components/calendar/personal_event/PersonalEventDialog.vue
index 33bd0b128..d84073050 100644
--- a/aleksis/core/frontend/components/calendar/personal_event/PersonalEventDialog.vue
+++ b/aleksis/core/frontend/components/calendar/personal_event/PersonalEventDialog.vue
@@ -255,8 +255,11 @@ export default {
         datetimeEnd: item.fullDay ? undefined : item.datetimeEnd,
         dateStart: item.fullDay ? item.dateStart : undefined,
         dateEnd: item.fullDay ? item.dateEnd : undefined,
-        recurrences: item.recurring === false ? "" : item.recurrences,
-        timezone: DateTime.local().zoneName,
+        ...(item.recurring ? {
+          // Add clients timezone only if item is recurring
+          timezone: DateTime.local().zoneName,
+          recurrences: item.recurrences,
+        } : {}),
         persons: this.checkPermission(
           "core.create_personal_event_with_invitations_rule",
         )
diff --git a/aleksis/core/frontend/components/calendar/personal_event/personalEvent.graphql b/aleksis/core/frontend/components/calendar/personal_event/personalEvent.graphql
index 695c07190..82c76524f 100644
--- a/aleksis/core/frontend/components/calendar/personal_event/personalEvent.graphql
+++ b/aleksis/core/frontend/components/calendar/personal_event/personalEvent.graphql
@@ -1,25 +1,30 @@
+fragment personalEventFields on PersonalEventType {
+  id
+  title
+  description
+  location
+
+  datetimeStart
+  datetimeEnd
+  dateStart
+  dateEnd
+  timezone
+  recurrences
+
+  persons {
+    id
+    fullName
+  }
+  groups {
+    id
+    shortName
+  }
+}
+
 mutation createPersonalEvents($input: [BatchCreatePersonalEventInput]!) {
   createPersonalEvents(input: $input) {
     items: personalEvents {
-      id
-      title
-      description
-      location
-
-      datetimeStart
-      datetimeEnd
-      dateStart
-      dateEnd
-      recurrences
-
-      persons {
-        id
-        fullName
-      }
-      groups {
-        id
-        shortName
-      }
+      ...personalEventFields 
     }
   }
 }
@@ -33,25 +38,7 @@ mutation deletePersonalEvents($ids: [ID]!) {
 mutation updatePersonalEvents($input: [BatchPatchPersonalEventInput]!) {
   updatePersonalEvents(input: $input) {
     items: personalEvents {
-      id
-      title
-      description
-      location
-
-      datetimeStart
-      datetimeEnd
-      dateStart
-      dateEnd
-      recurrences
-
-      persons {
-        id
-        fullName
-      }
-      groups {
-        id
-        shortName
-      }
+      ...personalEventFields
     }
   }
 }
diff --git a/aleksis/core/schema/personal_event.py b/aleksis/core/schema/personal_event.py
index 3bf36b2e4..c93822824 100644
--- a/aleksis/core/schema/personal_event.py
+++ b/aleksis/core/schema/personal_event.py
@@ -24,15 +24,14 @@ class PersonalEventType(DjangoObjectType):
             "location",
             "datetime_start",
             "datetime_end",
-            "timezone",
             "date_start",
             "date_end",
             "owner",
             "persons",
             "groups",
         )
-        convert_choices_to_enum = False
 
+    timezone = graphene.String()
     recurrences = graphene.String()
 
 
@@ -53,7 +52,8 @@ class PersonalEventBatchCreateMutation(PermissionBatchPatchMixin, BaseBatchCreat
             "persons",
             "groups",
         )
-        field_types = {"recurrences": graphene.String(), "location": graphene.String()}
+        field_types = {"timezone": graphene.String(), "recurrences": graphene.String(), "location": graphene.String()}
+        optional_fields = ("timezone", "recurrences")
 
     @classmethod
     def get_permissions(cls, root, info, input) -> Iterable[str]:  # noqa
@@ -102,7 +102,8 @@ class PersonalEventBatchPatchMutation(BaseBatchPatchMutation):
             "persons",
             "groups",
         )
-        field_types = {"recurrences": graphene.String(), "location": graphene.String()}
+        field_types = {"timezone": graphene.String(), "recurrences": graphene.String(), "location": graphene.String()}
+        optional_fields = ("timezone", "recurrences")
 
     @classmethod
     def get_permissions(cls, root, info, input, id, obj) -> Iterable[str]:  # noqa
-- 
GitLab


From edfeb7adc2adb862420095aec040b5cc1f828fa9 Mon Sep 17 00:00:00 2001
From: Michael Bauer <michael-bauer@posteo.de>
Date: Thu, 23 Jan 2025 15:13:30 +0100
Subject: [PATCH 2/3] Enable removal of optional recurrence for personal-events

Alternativly the frontend would need to always send the empty string.
---
 aleksis/core/schema/personal_event.py | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/aleksis/core/schema/personal_event.py b/aleksis/core/schema/personal_event.py
index c93822824..6f38ae969 100644
--- a/aleksis/core/schema/personal_event.py
+++ b/aleksis/core/schema/personal_event.py
@@ -110,3 +110,12 @@ class PersonalEventBatchPatchMutation(BaseBatchPatchMutation):
         if info.context.user.has_perm("core.edit_personal_event_rule", obj):
             return []
         return cls._meta.permissions
+
+    @classmethod
+    def before_mutate(cls, root, info, input):  # noqa
+        for event in input:
+            # Remove recurrences if none were received.
+            if not "recurrences" in event:
+                event["recurrences"] = ""
+
+        return input
-- 
GitLab


From 63c113ae612e136040ce2e15157cadd31a10f9d1 Mon Sep 17 00:00:00 2001
From: Michael Bauer <michael-bauer@posteo.de>
Date: Sat, 25 Jan 2025 16:13:33 +0100
Subject: [PATCH 3/3] Reformat

---
 .../personal_event/PersonalEventDialog.vue         | 12 +++++++-----
 .../calendar/personal_event/personalEvent.graphql  |  2 +-
 aleksis/core/schema/personal_event.py              | 14 +++++++++++---
 3 files changed, 19 insertions(+), 9 deletions(-)

diff --git a/aleksis/core/frontend/components/calendar/personal_event/PersonalEventDialog.vue b/aleksis/core/frontend/components/calendar/personal_event/PersonalEventDialog.vue
index d84073050..3c94e2d38 100644
--- a/aleksis/core/frontend/components/calendar/personal_event/PersonalEventDialog.vue
+++ b/aleksis/core/frontend/components/calendar/personal_event/PersonalEventDialog.vue
@@ -255,11 +255,13 @@ export default {
         datetimeEnd: item.fullDay ? undefined : item.datetimeEnd,
         dateStart: item.fullDay ? item.dateStart : undefined,
         dateEnd: item.fullDay ? item.dateEnd : undefined,
-        ...(item.recurring ? {
-          // Add clients timezone only if item is recurring
-          timezone: DateTime.local().zoneName,
-          recurrences: item.recurrences,
-        } : {}),
+        ...(item.recurring
+          ? {
+              // Add clients timezone only if item is recurring
+              timezone: DateTime.local().zoneName,
+              recurrences: item.recurrences,
+            }
+          : {}),
         persons: this.checkPermission(
           "core.create_personal_event_with_invitations_rule",
         )
diff --git a/aleksis/core/frontend/components/calendar/personal_event/personalEvent.graphql b/aleksis/core/frontend/components/calendar/personal_event/personalEvent.graphql
index 82c76524f..a22bc0a46 100644
--- a/aleksis/core/frontend/components/calendar/personal_event/personalEvent.graphql
+++ b/aleksis/core/frontend/components/calendar/personal_event/personalEvent.graphql
@@ -24,7 +24,7 @@ fragment personalEventFields on PersonalEventType {
 mutation createPersonalEvents($input: [BatchCreatePersonalEventInput]!) {
   createPersonalEvents(input: $input) {
     items: personalEvents {
-      ...personalEventFields 
+      ...personalEventFields
     }
   }
 }
diff --git a/aleksis/core/schema/personal_event.py b/aleksis/core/schema/personal_event.py
index 6f38ae969..e8655d160 100644
--- a/aleksis/core/schema/personal_event.py
+++ b/aleksis/core/schema/personal_event.py
@@ -52,7 +52,11 @@ class PersonalEventBatchCreateMutation(PermissionBatchPatchMixin, BaseBatchCreat
             "persons",
             "groups",
         )
-        field_types = {"timezone": graphene.String(), "recurrences": graphene.String(), "location": graphene.String()}
+        field_types = {
+            "timezone": graphene.String(),
+            "recurrences": graphene.String(),
+            "location": graphene.String(),
+        }
         optional_fields = ("timezone", "recurrences")
 
     @classmethod
@@ -102,7 +106,11 @@ class PersonalEventBatchPatchMutation(BaseBatchPatchMutation):
             "persons",
             "groups",
         )
-        field_types = {"timezone": graphene.String(), "recurrences": graphene.String(), "location": graphene.String()}
+        field_types = {
+            "timezone": graphene.String(),
+            "recurrences": graphene.String(),
+            "location": graphene.String(),
+        }
         optional_fields = ("timezone", "recurrences")
 
     @classmethod
@@ -115,7 +123,7 @@ class PersonalEventBatchPatchMutation(BaseBatchPatchMutation):
     def before_mutate(cls, root, info, input):  # noqa
         for event in input:
             # Remove recurrences if none were received.
-            if not "recurrences" in event:
+            if "recurrences" not in event:
                 event["recurrences"] = ""
 
         return input
-- 
GitLab