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

Make allowing future coursebook entries configurable

parent 23123c71
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"
......@@ -2,7 +2,7 @@ from django.core.exceptions import ValidationError
from django.utils.translation import gettext_lazy as _
from dynamic_preferences.preferences import Section
from dynamic_preferences.types import BooleanPreference, IntegerPreference
from dynamic_preferences.types import BooleanPreference, ChoicePreference, IntegerPreference
from aleksis.core.registries import person_preferences_registry, site_preferences_registry
......@@ -157,3 +157,18 @@ class DefaultLessonDocumentationFilter(BooleanPreference):
name = "default_lesson_documentation_filter"
default = True
verbose_name = _("Filter lessons by existence of their lesson documentation on default")
@site_preferences_registry.register
class AllowEditFutureDocumentations(ChoicePreference):
"""Time range for which documentations may be edited."""
section = alsijil
name = "allow_edit_future_documentations"
default = "current_day"
choices = (
("all", _("Allow editing of all future documentations")),
("current_day", _("Allow editing of all documentations up to and including those on the current day")),
("current_time", _("Allow editing of all documentations up to and including those on the current date and time")),
)
verbose_name = _("Set time range for which documentations may be edited")
......@@ -22,6 +22,7 @@ from .util.predicates import (
is_group_member,
is_group_owner,
is_group_role_assignment_group_owner,
is_in_allowed_time_range,
is_lesson_event_group_owner,
is_lesson_event_teacher,
is_lesson_original_teacher,
......@@ -402,6 +403,6 @@ add_perm(
edit_documentation_predicate = has_person & (
has_global_perm("alsijil.change_documentation") | can_edit_documentation
)
) & is_in_allowed_time_range
add_perm("alsijil.edit_documentation_rule", edit_documentation_predicate)
add_perm("alsijil.delete_documentation_rule", edit_documentation_predicate)
from typing import Any, Union
from django.contrib.auth.models import User
from django.utils.timezone import localdate, localtime
from rules import predicate
from aleksis.apps.chronos.models import Event, ExtraLesson, LessonEvent, LessonPeriod
from aleksis.apps.cursus.models import Course
from aleksis.core.models import Group, Person
from aleksis.core.util.core_helpers import get_site_preferences
from aleksis.core.util.predicates import check_object_permission
from ..models import Documentation, PersonalNote
......@@ -407,3 +409,16 @@ def can_edit_documentation(user: User, obj: Documentation):
if obj.course:
return is_course_teacher(user, obj.course)
return False
@predicate
def is_in_allowed_time_range(user: User, obj: Documentation):
"""Predicate which checks if the documentation is in the allowed time range for editing."""
if obj:
if get_site_preferences()["alsijil__allow_edit_future_documentations"] == "all":
return True
elif get_site_preferences()["alsijil__allow_edit_future_documentations"] == "current_day" and obj.datetime_start.date() <= localdate():
return True
elif get_site_preferences()["alsijil__allow_edit_future_documentations"] == "current_time" and obj.datetime_start <= localtime():
return True
return False
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