Skip to content
Snippets Groups Projects
Commit 5675ce4f authored by Hangzhi Yu's avatar Hangzhi Yu
Browse files

Add coursebook menu rule

parent ce49fbab
No related branches found
No related tags found
2 merge requests!352Draft: Resolve "Add dialog with each lesson's students",!350Resolve "Add simple course book list"
......@@ -411,7 +411,7 @@ export default {
iconActive: "mdi-book-education",
titleKey: "alsijil.coursebook.menu_title",
toolbarTitle: "alsijil.coursebook.menu_title",
permission: "core.view_calendar_feed_rule",
permission: "alsijil.view_documentations_menu_rule",
},
children: [
{
......@@ -421,7 +421,7 @@ export default {
meta: {
titleKey: "alsijil.coursebook.menu_title",
toolbarTitle: "alsijil.coursebook.menu_title",
permission: "core.view_calendar_feed_rule",
permission: "alsijil.view_documentations_menu_rule",
fullWidth: true,
},
},
......
......@@ -13,6 +13,7 @@ from aleksis.core.util.predicates import (
from .util.predicates import (
can_edit_documentation,
can_view_documentation,
can_view_any_documentation,
has_lesson_group_object_perm,
has_person_group_object_perm,
has_personal_note_group_perm,
......@@ -382,6 +383,12 @@ view_documentations_for_group_predicate = has_person & (
)
add_perm("alsijil.view_documentations_for_group_rule", view_documentations_for_group_predicate)
view_documentations_menu_predicate = has_person & (
has_global_perm("alsijil.view_documentation")
| can_view_any_documentation
)
add_perm("alsijil.view_documentations_menu_rule", view_documentations_menu_predicate)
view_documentations_for_teacher_predicate = has_person & (
has_global_perm("alsijil.view_documentation") | is_current_person
)
......
from typing import Any, Union
from django.contrib.auth.models import User
from django.db.models import Prefetch, Q
from django.utils.timezone import localdate, localtime
from rules import predicate
......@@ -417,6 +418,14 @@ def can_view_documentation(user: User, obj: Documentation):
return False
@predicate
def can_view_any_documentation(user: User):
"""Predicate which checks if the user is allowed to view any documentation."""
allowed_lesson_events = LessonEvent.objects.related_to_person(user.person)
return Documentation.objects.filter(Q(teachers=user.person) | Q(lesson_event__in=allowed_lesson_events) | Q(course__teachers=user.person)).exists()
@predicate
def can_edit_documentation(user: User, obj: Documentation):
"""Predicate which checks if the user is allowed to edit or delete a documentation."""
......
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