Skip to content
Snippets Groups Projects

Resolve "Check permission rules if they handle lessons with substitutions correctly"

Files
2
@@ -22,8 +22,22 @@ def is_none(user: User, obj: Any) -> bool:
def is_lesson_teacher(user: User, obj: Union[LessonPeriod, Event, ExtraLesson]) -> bool:
"""Predicate for teachers of a lesson.
Checks whether the person linked to the user is a teacher
in the lesson or the substitution linked to the given LessonPeriod.
Checks whether the person linked to the user is a teacher in the register object.
If the register object is a lesson period and has a substitution linked,
this will **only** check if the person is one of the substitution teachers.
"""
if obj:
return user.person in obj.get_teachers().all()
return False
@predicate
def is_lesson_original_teacher(user: User, obj: Union[LessonPeriod, Event, ExtraLesson]) -> bool:
"""Predicate for teachers of a lesson.
Checks whether the person linked to the user is a teacher in the register object.
If the register object is a lesson period and has a substitution linked,
this will **also** check if the person is one of the substitution teachers.
"""
if obj:
if isinstance(obj, LessonPeriod) and user.person in obj.lesson.teachers.all():
@@ -205,10 +219,26 @@ def is_own_personal_note(user: User, obj: PersonalNote) -> bool:
@predicate
def is_personal_note_lesson_teacher(user: User, obj: PersonalNote) -> bool:
"""Predicate for teachers of a lesson referred to in the lesson period of a personal note.
"""Predicate for teachers of a register object linked to a personal note.
Checks whether the person linked to the user is a teacher
in the register object linked to the personal note.
If the register object is a lesson period and has a substitution linked,
this will **only** check if the person is one of the substitution teachers.
"""
if hasattr(obj, "register_object"):
return user.person in obj.register_object.get_teachers().all()
return False
@predicate
def is_personal_note_lesson_original_teacher(user: User, obj: PersonalNote) -> bool:
"""Predicate for teachers of a register object linked to a personal note.
Checks whether the person linked to the user is a teacher
in the lesson or the substitution linked to the LessonPeriod of the given PersonalNote.
in the register object linked to the personal note.
If the register object is a lesson period and has a substitution linked,
this will **also** check if the person is one of the substitution teachers.
"""
if hasattr(obj, "register_object"):
if (
Loading