Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • AlekSIS/official/AlekSIS-App-Alsijil
  • sunweaver/AlekSIS-App-Alsijil
  • 8tincsoVluke/AlekSIS-App-Alsijil
  • perfreicpo/AlekSIS-App-Alsijil
  • noifobarep/AlekSIS-App-Alsijil
  • 7ingannisdo/AlekSIS-App-Alsijil
  • unmruntartpa/AlekSIS-App-Alsijil
  • balrorebta/AlekSIS-App-Alsijil
  • comliFdifwa/AlekSIS-App-Alsijil
  • 3ranaadza/AlekSIS-App-Alsijil
10 results
Show changes
Commits on Source (12)
......@@ -4,7 +4,7 @@ from typing import Optional
from django.contrib.auth.models import User
from django.core.exceptions import PermissionDenied
from django.db import models
from django.db.models import QuerySet, Q
from django.db.models import Q, QuerySet
from django.http import HttpRequest
from django.urls import reverse
from django.utils import timezone
......@@ -171,22 +171,11 @@ class Documentation(CalendarEvent):
doc = next(existing_documentations_event, None)
if doc:
if (
(incomplete and doc.topic)
or (
not request.user.has_perm(
"alsijil.edit_participation_status_for_documentation_rule", doc
)
and not doc.participations.filter(
person__pk=request.user.person.pk, absence_reason__isnull=False
).exists()
)
or (
absences_exist
and (
not doc.participations.all()
or not [d for d in doc.participations.all() if d.absence_reason]
)
if (incomplete and doc.topic) or (
absences_exist
and (
not doc.participations.all()
or not [d for d in doc.participations.all() if d.absence_reason]
)
):
continue
......@@ -437,7 +426,11 @@ class ParticipationStatus(CalendarEvent):
@classmethod
def get_objects(
cls, request: HttpRequest | None = None, params: dict[str, any] | None = None, additional_filter: Q | None = None, **kwargs
cls,
request: HttpRequest | None = None,
params: dict[str, any] | None = None,
additional_filter: Q | None = None,
**kwargs,
) -> QuerySet:
q = additional_filter or Q()
if params:
......@@ -447,9 +440,12 @@ class ParticipationStatus(CalendarEvent):
q = q & Q(person__in=params["persons"])
elif params.get("group"):
q = q & Q(groups_of_person__in=params.get("group"))
qs = (
super()
.get_objects(request, params, additional_filter=q, select_related=["person", "absence_reason"], **kwargs)
qs = super().get_objects(
request,
params,
additional_filter=q,
select_related=["person", "absence_reason"],
**kwargs,
)
return qs
......
......@@ -14,6 +14,19 @@ from aleksis.core.registries import site_preferences_registry
alsijil = Section("alsijil", verbose_name=_("Class register"))
@site_preferences_registry.register
class InheritPrivilegesFromParentGroup(BooleanPreference):
section = alsijil
name = "inherit_privileges_from_parent_group"
default = True
verbose_name = _(
"Grant the owner of a parent group the same privileges "
"as the owners of the respective child groups "
"in regard to group role management and generating "
"full printouts of class registers."
)
@site_preferences_registry.register
class GroupOwnersCanAssignRolesToParents(BooleanPreference):
section = alsijil
......
......@@ -16,7 +16,6 @@ from .util.predicates import (
can_edit_personal_note,
can_register_absence_for_at_least_one_group,
can_register_absence_for_person,
can_view_any_documentation,
can_view_documentation,
can_view_participation_status,
can_view_personal_note,
......@@ -165,9 +164,7 @@ 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
)
view_documentations_menu_predicate = has_person
add_perm("alsijil.view_documentations_menu_rule", view_documentations_menu_predicate)
view_documentations_for_teacher_predicate = has_person & (
......
from datetime import datetime
from django.core.exceptions import PermissionDenied
from django.db.models import BooleanField, ExpressionWrapper, Q
import graphene
......@@ -76,7 +75,13 @@ class Query(graphene.ObjectType):
def resolve_documentations_by_course_id(root, info, course_id, **kwargs):
documentations = Documentation.objects.filter(
Q(course__pk=course_id) | Q(amends__course__pk=course_id)
pk__in=Documentation.objects.filter(course_id=course_id)
.values_list("id", flat=True)
.union(
Documentation.objects.filter(amends__course_id=course_id).values_list(
"id", flat=True
)
)
)
return documentations
......@@ -112,7 +117,7 @@ class Query(graphene.ObjectType):
)
)
):
raise PermissionDenied()
return []
# Find all LessonEvents for all Lessons of this Course in this date range
event_params = {
......@@ -150,16 +155,22 @@ class Query(graphene.ObjectType):
if person:
person = Person.objects.get(pk=person)
if not info.context.user.has_perm("core.view_person_rule", person):
raise PermissionDenied()
return []
elif has_person(info.context.user):
person = info.context.user.person
else:
raise PermissionDenied()
return []
return (
Group.objects.for_current_school_term_or_all()
.filter(Q(members=person) | Q(owners=person) | Q(parent_groups__owners=person))
.distinct()
.filter(
pk__in=Group.objects.filter(members=person)
.values_list("id", flat=True)
.union(Group.objects.filter(owners=person).values_list("id", flat=True))
.union(
Group.objects.filter(parent_groups__owners=person).values_list("id", flat=True)
)
)
.annotate(
is_priority=ExpressionWrapper(
Q(group_type=get_site_preferences()["alsijil__group_type_priority_coursebook"]),
......@@ -174,20 +185,24 @@ class Query(graphene.ObjectType):
if person:
person = Person.objects.get(pk=person)
if not info.context.user.has_perm("core.view_person_rule", person):
raise PermissionDenied()
return []
elif has_person(info.context.user):
person = info.context.user.person
else:
raise PermissionDenied()
return []
return Course.objects.filter(
(
Q(teachers=person)
| Q(groups__members=person)
| Q(groups__owners=person)
| Q(groups__parent_groups__owners=person)
pk__in=(
Course.objects.filter(teachers=person)
.values_list("id", flat=True)
.union(Course.objects.filter(groups__members=person).values_list("id", flat=True))
.union(Course.objects.filter(groups__owners=person).values_list("id", flat=True))
.union(
Course.objects.filter(groups__parent_groups__owners=person).values_list(
"id", flat=True
)
)
)
& Q(groups__in=Group.objects.for_current_school_term_or_all())
).distinct()
).filter(groups__in=Group.objects.for_current_school_term_or_all())
@staticmethod
def resolve_absence_creation_persons(root, info, **kwargs):
......
......@@ -108,7 +108,9 @@ class DocumentationType(PermissionsTypeMixin, DjangoFilterMixin, DjangoObjectTyp
"alsijil.view_participation_status_for_documentation_rule", root
):
if has_person(info.context.user):
return root.participations.filter(person=info.context.user.person)
return [
p for p in root.participations.all() if p.person == info.context.user.person
]
return []
return root.participations.all()
......
......@@ -119,9 +119,9 @@ class ExtendParticipationStatusToAbsenceBatchMutation(graphene.Mutation):
return participation, absence
else:
# No base absence, simply create one
# No base absence, simply create one if absence reason is given
data = dict(
reason_id=participation.absence_reason.id,
reason_id=participation.absence_reason.id if participation.absence_reason else None,
person=participation.person,
)
......