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

Fix defaults of some predicates (True to False) and catch side effect of this change

parent 31fed539
No related branches found
No related tags found
1 merge request!49Resolve "Add rules and permissions"
Pipeline #4072 failed
......@@ -18,6 +18,7 @@ from .util.predicates import (
is_lesson_parent_group_owner,
is_lesson_participant,
is_lesson_teacher,
is_none,
is_own_personal_note,
is_person_group_owner,
is_person_primary_group_owner,
......@@ -29,6 +30,7 @@ from .util.predicates import (
# View lesson
view_lesson_predicate = has_person & (
has_global_perm("alsijil.view_lesson")
| is_none # View is opened as "Current lesson"
| is_lesson_teacher
| is_lesson_participant
| is_lesson_parent_group_owner
......
from typing import Union
from typing import Any, Union
from django.contrib.auth.models import User
......@@ -12,6 +12,12 @@ from aleksis.core.util.predicates import check_object_permission
from ..models import PersonalNote
@predicate
def is_none(user: User, obj: Any) -> bool:
"""Predicate that checks if the provided object is None-like."""
return bool(obj)
@predicate
def is_lesson_teacher(user: User, obj: LessonPeriod) -> bool:
"""Predicate for teachers of a lesson.
......@@ -24,7 +30,7 @@ def is_lesson_teacher(user: User, obj: LessonPeriod) -> bool:
if sub and sub in user.person.lesson_substitutions.all():
return True
return user.person in obj.lesson.teachers.all()
return True
return False
@predicate
......@@ -36,7 +42,7 @@ def is_lesson_participant(user: User, obj: LessonPeriod) -> bool:
"""
if hasattr(obj, "lesson"):
return obj.lesson.groups.filter(members=user.person).exists()
return True
return False
@predicate
......@@ -49,7 +55,7 @@ def is_lesson_parent_group_owner(user: User, obj: LessonPeriod) -> bool:
"""
if hasattr(obj, "lesson"):
return obj.lesson.groups.filter(parent_groups__owners=user.person).exists()
return True
return False
@predicate
......
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