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

Add filtered queries for groups & courses

parent b125af74
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"
Pipeline #176324 failed
...@@ -6,8 +6,11 @@ from django.db.models.query_utils import Q ...@@ -6,8 +6,11 @@ from django.db.models.query_utils import Q
import graphene import graphene
from aleksis.apps.cursus.models import Course from aleksis.apps.cursus.models import Course
from aleksis.apps.cursus.schema import CourseType
from aleksis.core.models import Group, Person from aleksis.core.models import Group, Person
from aleksis.core.schema.base import FilterOrderList from aleksis.core.schema.base import FilterOrderList
from aleksis.core.schema.group import GroupType
from aleksis.core.util.core_helpers import has_person
from ..models import Documentation from ..models import Documentation
from .documentation import ( from .documentation import (
...@@ -34,6 +37,9 @@ class Query(graphene.ObjectType): ...@@ -34,6 +37,9 @@ class Query(graphene.ObjectType):
date_end=graphene.Date(required=True), date_end=graphene.Date(required=True),
) )
groups_by_person = FilterOrderList(GroupType, person=graphene.ID())
courses_of_person = FilterOrderList(CourseType, person=graphene.ID())
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(lesson_event__course__pk=course_id) Q(course__pk=course_id) | Q(lesson_event__course__pk=course_id)
...@@ -72,6 +78,39 @@ class Query(graphene.ObjectType): ...@@ -72,6 +78,39 @@ class Query(graphene.ObjectType):
own, datetime_start, datetime_end, info.context, obj_type, obj_id own, datetime_start, datetime_end, info.context, obj_type, obj_id
) )
@staticmethod
def resolve_groups_by_person(root, info, person=None):
if person:
person = Person.objects.get(pk=person)
if not info.context.user.has_perm("core.view_person_rule", person):
raise PermissionDenied()
elif has_person(info.context.user):
person = info.context.user.person
else:
raise PermissionDenied()
return Group.objects.filter(
Q(members=person) | Q(owners=person) | Q(parent_groups__owners=person)
)
@staticmethod
def resolve_courses_of_person(root, info, person=None):
if person:
person = Person.objects.get(pk=person)
if not info.context.user.has_perm("core.view_person_rule", person):
raise PermissionDenied()
elif has_person(info.context.user):
person = info.context.user.person
else:
raise PermissionDenied()
return Course.objects.filter(
Q(teachers=person)
| Q(groups__members=person)
| Q(groups__owners=person)
| Q(groups__parent_groups__owners=person)
)
class Mutation(graphene.ObjectType): class Mutation(graphene.ObjectType):
create_documentation = DocumentationCreateMutation.Field() create_documentation = DocumentationCreateMutation.Field()
......
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