diff --git a/aleksis/apps/alsijil/util/predicates.py b/aleksis/apps/alsijil/util/predicates.py index b1d9c45e5a22edf54e3e1eef8befcd8d0602ce69..c2ce7d98a7e8d0cd4b2f02700f2e055fb294e019 100644 --- a/aleksis/apps/alsijil/util/predicates.py +++ b/aleksis/apps/alsijil/util/predicates.py @@ -381,10 +381,23 @@ def is_lesson_event_group_owner(user: User, obj: LessonEvent): return False +@predicate +def is_documentation_teacher(user: User, obj: Documentation): + """Predicate for teachers of a documentation. + + Checks whether the person linked to the user is a teacher in the documentation. + """ + if obj: + return user.person in obj.teachers + return False + + @predicate def can_view_documentation(user: User, obj: Documentation): """Predicate which checks if the user is allowed to view a documentation.""" if obj: + if is_documentation_teacher(user, obj): + return True if obj.lesson_event: return ( is_lesson_event_teacher(user, obj.lesson_event) @@ -400,6 +413,8 @@ def can_view_documentation(user: User, obj: Documentation): def can_edit_documentation(user: User, obj: Documentation): """Predicate which checks if the user is allowed to edit or delete a documentation.""" if obj: + if is_documentation_teacher(user, obj): + return True if obj.lesson_event: return is_lesson_event_teacher(user, obj.lesson_event) | is_lesson_event_group_owner( user, obj.lesson_event