Skip to content
Snippets Groups Projects
Verified Commit c2e98047 authored by Jonathan Weth's avatar Jonathan Weth :keyboard:
Browse files

Fix predicates for lesson teachers to check both original teachers and substitution teachers

parent d142255a
No related branches found
No related tags found
1 merge request!158Resolve "Check permission rules if they handle lessons with substitutions correctly"
Pipeline #6266 passed
......@@ -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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment