From 356c223f77908c22074adcba15a985d40efc1b4c Mon Sep 17 00:00:00 2001
From: Hangzhi Yu <hangzhi@protonmail.com>
Date: Tue, 30 Jan 2024 18:21:26 +0100
Subject: [PATCH] Reformat

---
 .../frontend/components/Coursebook.vue        | 32 +++++++--------
 .../frontend/components/coursebook.graphql    | 14 ++++++-
 .../documentation/Documentation.vue           |  2 +-
 aleksis/apps/alsijil/frontend/index.js        | 21 +++++-----
 aleksis/apps/alsijil/models.py                | 39 +++++++++++++++----
 aleksis/apps/alsijil/rules.py                 |  4 +-
 aleksis/apps/alsijil/schema/__init__.py       | 33 +++++++++++++---
 aleksis/apps/alsijil/schema/documentation.py  |  4 +-
 8 files changed, 103 insertions(+), 46 deletions(-)

diff --git a/aleksis/apps/alsijil/frontend/components/Coursebook.vue b/aleksis/apps/alsijil/frontend/components/Coursebook.vue
index 5e0f14cab..b143434b5 100644
--- a/aleksis/apps/alsijil/frontend/components/Coursebook.vue
+++ b/aleksis/apps/alsijil/frontend/components/Coursebook.vue
@@ -5,21 +5,16 @@
     :gql-additional-query-args="gqlQueryArgs"
     :enable-create="false"
     :enable-edit="false"
-    >
+  >
     <template #default="{ items }">
-      <v-list-item
-        v-for="day in groupDocsByDay(items)"
-        two-line
-      >
+      <v-list-item v-for="day in groupDocsByDay(items)" two-line>
         <v-list-item-content>
           <v-list-item-title>{{ $d(day[0], "short") }}</v-list-item-title>
           <v-list>
             <!-- I know slice copies the array. But show me something better. -->
             <v-list-item v-for="doc in day.slice(1)">
               <v-card class="my-2">
-                <documentation
-                  :documentation="doc"
-                />
+                <documentation :documentation="doc" />
               </v-card>
             </v-list-item>
           </v-list>
@@ -85,18 +80,17 @@ export default {
   methods: {
     // => [[dt doc ...] ...]
     groupDocsByDay(docs) {
-      const byDay = docs.reduce(
-        (byDay, doc) => {
-          // This works with dummy. Does actual doc have dateStart instead?
-          const day = DateTime.fromISO(doc.datetimeStart).startOf('day');
-          byDay[day] ??= [day];
-          byDay[day].push(doc);
-          return byDay;
-        },
-        {}
-      );
+      const byDay = docs.reduce((byDay, doc) => {
+        // This works with dummy. Does actual doc have dateStart instead?
+        const day = DateTime.fromISO(doc.datetimeStart).startOf("day");
+        byDay[day] ??= [day];
+        byDay[day].push(doc);
+        return byDay;
+      }, {});
 
-      return Object.keys(byDay).sort().map(key => byDay[key]);
+      return Object.keys(byDay)
+        .sort()
+        .map((key) => byDay[key]);
     },
   },
 };
diff --git a/aleksis/apps/alsijil/frontend/components/coursebook.graphql b/aleksis/apps/alsijil/frontend/components/coursebook.graphql
index e2fb931a3..025019ebe 100644
--- a/aleksis/apps/alsijil/frontend/components/coursebook.graphql
+++ b/aleksis/apps/alsijil/frontend/components/coursebook.graphql
@@ -1,5 +1,15 @@
-query gqlDocumentationsForCoursebook($objId: ID!, $objType: String!, $dateStart: Date!, $dateEnd: Date!) {
-  items: documentationsForCoursebook(objId: $objId, objType: $objType, dateStart: $dateStart, dateEnd: $dateEnd) {
+query gqlDocumentationsForCoursebook(
+  $objId: ID!
+  $objType: String!
+  $dateStart: Date!
+  $dateEnd: Date!
+) {
+  items: documentationsForCoursebook(
+    objId: $objId
+    objType: $objType
+    dateStart: $dateStart
+    dateEnd: $dateEnd
+  ) {
     id
     course {
       id
diff --git a/aleksis/apps/alsijil/frontend/components/documentation/Documentation.vue b/aleksis/apps/alsijil/frontend/components/documentation/Documentation.vue
index ea6a840db..a8dfe5ae7 100644
--- a/aleksis/apps/alsijil/frontend/components/documentation/Documentation.vue
+++ b/aleksis/apps/alsijil/frontend/components/documentation/Documentation.vue
@@ -1,5 +1,5 @@
 <template>
- <v-card-text>{{ documentation.id }}</v-card-text>
+  <v-card-text>{{ documentation.id }}</v-card-text>
 </template>
 
 <script>
diff --git a/aleksis/apps/alsijil/frontend/index.js b/aleksis/apps/alsijil/frontend/index.js
index aff43c39a..8993d75ed 100644
--- a/aleksis/apps/alsijil/frontend/index.js
+++ b/aleksis/apps/alsijil/frontend/index.js
@@ -396,16 +396,17 @@ export default {
     {
       path: "coursebook/:objType(group|course|teacher)/:objId(\\d+)/",
       component: () => import("./components/Coursebook.vue"),
-      redirect: to => {
-        console.log('redirect to', to);
-        return { name: "alsijil.coursebook_by_obj_id_and_date",
-                 params: {
-                   objType: to.params.objType,
-                   objId: to.params.objId,
-                   dateStart: DateTime.now().toISODate(),
-                   dateEnd: DateTime.now().plus({ weeks: 1 }).toISODate(),
-                 },
-               };
+      redirect: (to) => {
+        console.log("redirect to", to);
+        return {
+          name: "alsijil.coursebook_by_obj_id_and_date",
+          params: {
+            objType: to.params.objType,
+            objId: to.params.objId,
+            dateStart: DateTime.now().toISODate(),
+            dateEnd: DateTime.now().plus({ weeks: 1 }).toISODate(),
+          },
+        };
       },
       name: "alsijil.coursebook_by_obj_id",
       props: true,
diff --git a/aleksis/apps/alsijil/models.py b/aleksis/apps/alsijil/models.py
index b38be8ad8..ea9bce99e 100644
--- a/aleksis/apps/alsijil/models.py
+++ b/aleksis/apps/alsijil/models.py
@@ -516,7 +516,14 @@ class Documentation(CalendarEvent):
         ]
 
     @classmethod
-    def get_for_coursebook(cls, obj_type: str, obj_id: str, date_start: datetime, date_end: datetime, request: HttpRequest) -> list:
+    def get_for_coursebook(
+        cls,
+        obj_type: str,
+        obj_id: str,
+        date_start: datetime,
+        date_end: datetime,
+        request: HttpRequest,
+    ) -> list:
         """Get all the documentations for an object and a time frame.
 
         obj_type may be one of TEACHER, GROUP, ROOM, COURSE
@@ -524,7 +531,16 @@ class Documentation(CalendarEvent):
 
         # 1. Find all LessonEvents for all Lessons of this Course in this date range
         #  TODO: verify that substitutions don't break this
-        events = LessonEvent.get_single_events(date_start, date_end, request, {"type": obj_type, "id": obj_id, }, with_reference_object=True)
+        events = LessonEvent.get_single_events(
+            date_start,
+            date_end,
+            request,
+            {
+                "type": obj_type,
+                "id": obj_id,
+            },
+            with_reference_object=True,
+        )
         # (1.5 filter them by permissions)
         ...
 
@@ -533,8 +549,14 @@ class Documentation(CalendarEvent):
         return [
             (
                 existing_documentations.first()
-                if (existing_documentations := (event_reference_obj := event["REFERENCE_OBJECT"]).documentation.filter(datetime_start=event["DTSTART"].dt, datetime_end=event["DTEND"].dt)).exists() else
-                cls(
+                if (
+                    existing_documentations := (
+                        event_reference_obj := event["REFERENCE_OBJECT"]
+                    ).documentation.filter(
+                        datetime_start=event["DTSTART"].dt, datetime_end=event["DTEND"].dt
+                    )
+                ).exists()
+                else cls(
                     pk=f"DUMMY;{event_reference_obj.id};{event['DTSTART'].dt.isoformat()};{event['DTEND'].dt.isoformat()}",
                     lesson_event=event_reference_obj,
                     course=event_reference_obj.course,
@@ -577,7 +599,12 @@ class ParticipationStatus(ExtensibleModel):
     )
 
     base_absence = models.ForeignKey(
-        KolegoAbsence, models.SET_NULL, blank=True, null=True, related_name="absences", verbose_name=_("Base Absence")
+        KolegoAbsence,
+        models.SET_NULL,
+        blank=True,
+        null=True,
+        related_name="absences",
+        verbose_name=_("Base Absence"),
     )
 
     def __str__(self) -> str:
@@ -599,8 +626,6 @@ class ParticipationStatus(ExtensibleModel):
         ]
 
 
-
-
 class NewPersonalNote(ExtensibleModel):
     person = models.ForeignKey(
         "core.Person", models.CASCADE, related_name="new_personal_notes", verbose_name=_("Person")
diff --git a/aleksis/apps/alsijil/rules.py b/aleksis/apps/alsijil/rules.py
index 9e564d72b..9e39fb276 100644
--- a/aleksis/apps/alsijil/rules.py
+++ b/aleksis/apps/alsijil/rules.py
@@ -385,7 +385,9 @@ add_perm("alsijil.add_documentation_for_course_rule", add_documentation_for_cour
 add_documentation_for_lesson_event_predicate = has_person & (
     has_global_perm("alsijil.add_documentation") | is_lesson_event_teacher
 )
-add_perm("alsijil.add_documentation_for_lesson_event_rule", add_documentation_for_lesson_event_predicate)
+add_perm(
+    "alsijil.add_documentation_for_lesson_event_rule", add_documentation_for_lesson_event_predicate
+)
 
 edit_documentation_predicate = has_person & (
     has_global_perm("alsijil.change_documentation") | can_edit_documentation
diff --git a/aleksis/apps/alsijil/schema/__init__.py b/aleksis/apps/alsijil/schema/__init__.py
index d1de339ab..762fe1120 100644
--- a/aleksis/apps/alsijil/schema/__init__.py
+++ b/aleksis/apps/alsijil/schema/__init__.py
@@ -26,8 +26,8 @@ class Query(graphene.ObjectType):
     )
     documentations_for_coursebook = FilterOrderList(
         DocumentationType,
-        obj_type = graphene.String(required=True),
-        obj_id = graphene.ID(required=True),
+        obj_type=graphene.String(required=True),
+        obj_id=graphene.ID(required=True),
         date_start=graphene.Date(required=True),
         date_end=graphene.Date(required=True),
     )
@@ -38,14 +38,37 @@ class Query(graphene.ObjectType):
         )
         return documentations
 
-    def resolve_documentations_for_coursebook(root, info, obj_type, obj_id, date_start, date_end, **kwargs):
+    def resolve_documentations_for_coursebook(
+        root, info, obj_type, obj_id, date_start, date_end, **kwargs
+    ):
         datetime_start = datetime.combine(date_start, datetime.min.time())
         datetime_end = datetime.combine(date_end, datetime.max.time())
 
-        if (obj_type == "COURSE" and not info.context.user.has_perm("alsijil.view_documentations_for_course_rule", Course.objects.get(id=obj_id))) or (obj_type == "GROUPS" and not info.context.user.has_perm("alsijil.view_documentations_for_group_rule", Group.objects.get(id=obj_id))) or (obj_type == "TEACHER" and not info.context.user.has_perm("alsijil.view_documentations_for_teacher_rule", Person.objects.get(id=obj_id))):
+        if (
+            (
+                obj_type == "COURSE"
+                and not info.context.user.has_perm(
+                    "alsijil.view_documentations_for_course_rule", Course.objects.get(id=obj_id)
+                )
+            )
+            or (
+                obj_type == "GROUPS"
+                and not info.context.user.has_perm(
+                    "alsijil.view_documentations_for_group_rule", Group.objects.get(id=obj_id)
+                )
+            )
+            or (
+                obj_type == "TEACHER"
+                and not info.context.user.has_perm(
+                    "alsijil.view_documentations_for_teacher_rule", Person.objects.get(id=obj_id)
+                )
+            )
+        ):
             raise PermissionsDenied()
 
-        return Documentation.get_for_coursebook(obj_type, obj_id, datetime_start, datetime_end, info.context)
+        return Documentation.get_for_coursebook(
+            obj_type, obj_id, datetime_start, datetime_end, info.context
+        )
 
 
 class Mutation(graphene.ObjectType):
diff --git a/aleksis/apps/alsijil/schema/documentation.py b/aleksis/apps/alsijil/schema/documentation.py
index a8d6925e8..408d168bc 100644
--- a/aleksis/apps/alsijil/schema/documentation.py
+++ b/aleksis/apps/alsijil/schema/documentation.py
@@ -142,7 +142,9 @@ class DocumentationCreateOrUpdateMutation(graphene.Mutation):
             dummy, lesson_event_id, datetime_start, datetime_end = id.split(";")
             lesson_event = LessonEvent.objects.get(id=lesson_event_id)
 
-            if not info.context.user.has_perm("alsijil.add_documentation_for_lesson_event_rule", lesson_event):
+            if not info.context.user.has_perm(
+                "alsijil.add_documentation_for_lesson_event_rule", lesson_event
+            ):
                 raise PermissionDenied()
 
             obj = Documentation.objects.create(
-- 
GitLab