Project 'AlekSIS/official/AlekSIS-App-Stoelindeling' was moved to 'AlekSIS/onboarding/AlekSIS-App-Stoelindeling'. Please update any links and bookmarks that may still have the old path.
-
Jonathan Weth authoredJonathan Weth authored
perms.py 865 B
from django.db.models import Q
from guardian.shortcuts import get_objects_for_user
from rules import predicate
from ..models import SeatingPlan
@predicate
def is_group_owner(user, seating_plan: SeatingPlan) -> bool:
"""Predicate which checks if the user is a owner of the seating plan's group."""
return user.person in seating_plan.group.owners.all()
def get_allowed_seating_plans(user):
"""Get all seating plans the user is allowed to see."""
if not user.has_perm("stoelindeling.view_seatingplan"):
qs = SeatingPlan.objects.filter(
Q(
pk__in=get_objects_for_user(
user, "stoelindeling.view_seatingplan", SeatingPlan
).values_list("pk", flat=True)
)
| Q(group__owners=user.person)
)
return qs
return SeatingPlan.objects.all()