From c2e98047ca006d30bf1111dba215651a4763f186 Mon Sep 17 00:00:00 2001
From: Jonathan Weth <git@jonathanweth.de>
Date: Wed, 10 Mar 2021 19:38:55 +0100
Subject: [PATCH] Fix predicates for lesson teachers to check both original
 teachers and substitution teachers

---
 aleksis/apps/alsijil/util/predicates.py | 16 ++++++----------
 1 file changed, 6 insertions(+), 10 deletions(-)

diff --git a/aleksis/apps/alsijil/util/predicates.py b/aleksis/apps/alsijil/util/predicates.py
index 5d87d14da..8b59bb5dc 100644
--- a/aleksis/apps/alsijil/util/predicates.py
+++ b/aleksis/apps/alsijil/util/predicates.py
@@ -26,8 +26,7 @@ def is_lesson_teacher(user: User, obj: Union[LessonPeriod, Event, ExtraLesson])
     in the lesson or the substitution linked to the given LessonPeriod.
     """
     if obj:
-        sub = obj.get_substitution() if isinstance(obj, LessonPeriod) else None
-        if sub and sub in user.person.lesson_substitutions.all():
+        if isinstance(obj, LessonPeriod) and user.person in obj.lesson.teachers.all():
             return True
         return user.person in obj.get_teachers().all()
     return False
@@ -212,16 +211,13 @@ def is_personal_note_lesson_teacher(user: User, obj: PersonalNote) -> bool:
     in the lesson or the substitution linked to the LessonPeriod of the given PersonalNote.
     """
     if hasattr(obj, "register_object"):
-        if getattr(obj, "lesson_period", None):
-            sub = obj.lesson_period.get_substitution()
-            if sub and user.person in Person.objects.filter(
-                lesson_substitutions=obj.lesson_period.get_substitution()
-            ):
-                return True
+        if (
+            isinstance(obj.register_object, LessonPeriod)
+            and user.person in obj.lesson_period.lesson.teachers.all()
+        ):
+            return True
 
         return user.person in obj.register_object.get_teachers().all()
-
-        return False
     return False
 
 
-- 
GitLab