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 ...@@ -4,7 +4,7 @@ from typing import Optional
from django.contrib.auth.models import User from django.contrib.auth.models import User
from django.core.exceptions import PermissionDenied from django.core.exceptions import PermissionDenied
from django.db import models 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.http import HttpRequest
from django.urls import reverse from django.urls import reverse
from django.utils import timezone from django.utils import timezone
...@@ -171,22 +171,11 @@ class Documentation(CalendarEvent): ...@@ -171,22 +171,11 @@ class Documentation(CalendarEvent):
doc = next(existing_documentations_event, None) doc = next(existing_documentations_event, None)
if doc: if doc:
if ( if (incomplete and doc.topic) or (
(incomplete and doc.topic) absences_exist
or ( and (
not request.user.has_perm( not doc.participations.all()
"alsijil.edit_participation_status_for_documentation_rule", doc or not [d for d in doc.participations.all() if d.absence_reason]
)
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]
)
) )
): ):
continue continue
...@@ -437,7 +426,11 @@ class ParticipationStatus(CalendarEvent): ...@@ -437,7 +426,11 @@ class ParticipationStatus(CalendarEvent):
@classmethod @classmethod
def get_objects( 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: ) -> QuerySet:
q = additional_filter or Q() q = additional_filter or Q()
if params: if params:
...@@ -447,9 +440,12 @@ class ParticipationStatus(CalendarEvent): ...@@ -447,9 +440,12 @@ class ParticipationStatus(CalendarEvent):
q = q & Q(person__in=params["persons"]) q = q & Q(person__in=params["persons"])
elif params.get("group"): elif params.get("group"):
q = q & Q(groups_of_person__in=params.get("group")) q = q & Q(groups_of_person__in=params.get("group"))
qs = ( qs = super().get_objects(
super() request,
.get_objects(request, params, additional_filter=q, select_related=["person", "absence_reason"], **kwargs) params,
additional_filter=q,
select_related=["person", "absence_reason"],
**kwargs,
) )
return qs return qs
......
...@@ -14,6 +14,19 @@ from aleksis.core.registries import site_preferences_registry ...@@ -14,6 +14,19 @@ from aleksis.core.registries import site_preferences_registry
alsijil = Section("alsijil", verbose_name=_("Class register")) 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 @site_preferences_registry.register
class GroupOwnersCanAssignRolesToParents(BooleanPreference): class GroupOwnersCanAssignRolesToParents(BooleanPreference):
section = alsijil section = alsijil
......
...@@ -16,7 +16,6 @@ from .util.predicates import ( ...@@ -16,7 +16,6 @@ from .util.predicates import (
can_edit_personal_note, can_edit_personal_note,
can_register_absence_for_at_least_one_group, can_register_absence_for_at_least_one_group,
can_register_absence_for_person, can_register_absence_for_person,
can_view_any_documentation,
can_view_documentation, can_view_documentation,
can_view_participation_status, can_view_participation_status,
can_view_personal_note, can_view_personal_note,
...@@ -165,9 +164,7 @@ view_documentations_for_group_predicate = has_person & ( ...@@ -165,9 +164,7 @@ view_documentations_for_group_predicate = has_person & (
) )
add_perm("alsijil.view_documentations_for_group_rule", view_documentations_for_group_predicate) add_perm("alsijil.view_documentations_for_group_rule", view_documentations_for_group_predicate)
view_documentations_menu_predicate = has_person & ( 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) add_perm("alsijil.view_documentations_menu_rule", view_documentations_menu_predicate)
view_documentations_for_teacher_predicate = has_person & ( view_documentations_for_teacher_predicate = has_person & (
......
from datetime import datetime from datetime import datetime
from django.core.exceptions import PermissionDenied
from django.db.models import BooleanField, ExpressionWrapper, Q from django.db.models import BooleanField, ExpressionWrapper, Q
import graphene import graphene
...@@ -76,7 +75,13 @@ class Query(graphene.ObjectType): ...@@ -76,7 +75,13 @@ class Query(graphene.ObjectType):
def resolve_documentations_by_course_id(root, info, course_id, **kwargs): def resolve_documentations_by_course_id(root, info, course_id, **kwargs):
documentations = Documentation.objects.filter( 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 return documentations
...@@ -112,7 +117,7 @@ class Query(graphene.ObjectType): ...@@ -112,7 +117,7 @@ class Query(graphene.ObjectType):
) )
) )
): ):
raise PermissionDenied() return []
# Find all LessonEvents for all Lessons of this Course in this date range # Find all LessonEvents for all Lessons of this Course in this date range
event_params = { event_params = {
...@@ -150,16 +155,22 @@ class Query(graphene.ObjectType): ...@@ -150,16 +155,22 @@ class Query(graphene.ObjectType):
if person: if person:
person = Person.objects.get(pk=person) person = Person.objects.get(pk=person)
if not info.context.user.has_perm("core.view_person_rule", person): if not info.context.user.has_perm("core.view_person_rule", person):
raise PermissionDenied() return []
elif has_person(info.context.user): elif has_person(info.context.user):
person = info.context.user.person person = info.context.user.person
else: else:
raise PermissionDenied() return []
return ( return (
Group.objects.for_current_school_term_or_all() Group.objects.for_current_school_term_or_all()
.filter(Q(members=person) | Q(owners=person) | Q(parent_groups__owners=person)) .filter(
.distinct() 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( .annotate(
is_priority=ExpressionWrapper( is_priority=ExpressionWrapper(
Q(group_type=get_site_preferences()["alsijil__group_type_priority_coursebook"]), Q(group_type=get_site_preferences()["alsijil__group_type_priority_coursebook"]),
...@@ -174,20 +185,24 @@ class Query(graphene.ObjectType): ...@@ -174,20 +185,24 @@ class Query(graphene.ObjectType):
if person: if person:
person = Person.objects.get(pk=person) person = Person.objects.get(pk=person)
if not info.context.user.has_perm("core.view_person_rule", person): if not info.context.user.has_perm("core.view_person_rule", person):
raise PermissionDenied() return []
elif has_person(info.context.user): elif has_person(info.context.user):
person = info.context.user.person person = info.context.user.person
else: else:
raise PermissionDenied() return []
return Course.objects.filter( return Course.objects.filter(
( pk__in=(
Q(teachers=person) Course.objects.filter(teachers=person)
| Q(groups__members=person) .values_list("id", flat=True)
| Q(groups__owners=person) .union(Course.objects.filter(groups__members=person).values_list("id", flat=True))
| Q(groups__parent_groups__owners=person) .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()) ).filter(groups__in=Group.objects.for_current_school_term_or_all())
).distinct()
@staticmethod @staticmethod
def resolve_absence_creation_persons(root, info, **kwargs): def resolve_absence_creation_persons(root, info, **kwargs):
......
...@@ -108,7 +108,9 @@ class DocumentationType(PermissionsTypeMixin, DjangoFilterMixin, DjangoObjectTyp ...@@ -108,7 +108,9 @@ class DocumentationType(PermissionsTypeMixin, DjangoFilterMixin, DjangoObjectTyp
"alsijil.view_participation_status_for_documentation_rule", root "alsijil.view_participation_status_for_documentation_rule", root
): ):
if has_person(info.context.user): 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 []
return root.participations.all() return root.participations.all()
......
...@@ -119,9 +119,9 @@ class ExtendParticipationStatusToAbsenceBatchMutation(graphene.Mutation): ...@@ -119,9 +119,9 @@ class ExtendParticipationStatusToAbsenceBatchMutation(graphene.Mutation):
return participation, absence return participation, absence
else: else:
# No base absence, simply create one # No base absence, simply create one if absence reason is given
data = dict( data = dict(
reason_id=participation.absence_reason.id, reason_id=participation.absence_reason.id if participation.absence_reason else None,
person=participation.person, person=participation.person,
) )
......