From d9b6daad34c3c2fc7ebd0c7e1f35a259e899a37c Mon Sep 17 00:00:00 2001 From: Hangzhi Yu <hangzhi@protonmail.com> Date: Mon, 8 Apr 2024 17:59:25 +0200 Subject: [PATCH] Add check if person is documentation teacher in relevant predicates --- aleksis/apps/alsijil/util/predicates.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/aleksis/apps/alsijil/util/predicates.py b/aleksis/apps/alsijil/util/predicates.py index b1d9c45e5..c2ce7d98a 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 -- GitLab