Skip to content

Commit

Permalink
Ensure that query params are validated before being used to query.
Browse files Browse the repository at this point in the history
  • Loading branch information
rtibbles committed Jun 14, 2024
1 parent 7eb53e1 commit dd6d48d
Showing 1 changed file with 7 additions and 17 deletions.
24 changes: 7 additions & 17 deletions kolibri/core/content/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -378,16 +378,6 @@ class ChannelMetadataViewSet(BaseChannelMetadataMixin, RemoteViewSet):
pass


class IdFilter(FilterSet):
ids = CharFilter(method="filter_ids")

def filter_ids(self, queryset, name, value):
return queryset.filter_by_uuids(value.split(","))

class Meta:
fields = ["ids"]


MODALITIES = set(["QUIZ"])


Expand Down Expand Up @@ -428,7 +418,8 @@ class CharInFilter(BaseInFilter, CharFilter):
]


class ContentNodeFilter(IdFilter):
class ContentNodeFilter(FilterSet):
ids = UUIDInFilter(method="filter_ids")
kind = ChoiceFilter(
method="filter_kind",
choices=(content_kinds.choices + (("content", _("Resource")),)),
Expand Down Expand Up @@ -459,6 +450,9 @@ class Meta:
model = models.ContentNode
fields = contentnode_filter_fields

def filter_ids(self, queryset, name, value):
return queryset.filter_by_uuids(value)

def filter_by_authors(self, queryset, name, value):
"""
Show content filtered by author
Expand Down Expand Up @@ -878,9 +872,8 @@ def descendants(self, request):
ids = self.request.query_params.get("ids", None)
if not ids:
return Response([])
ids = ids.split(",")
kind = self.request.query_params.get("descendant_kind", None)
nodes = models.ContentNode.objects.filter_by_uuids(ids).filter(available=True)
nodes = self.filter_queryset(self.get_queryset())
data = []
for node in nodes:

Expand All @@ -902,10 +895,7 @@ def descendants_assessments(self, request):
ids = self.request.query_params.get("ids", None)
if not ids:
return Response([])
ids = ids.split(",")
queryset = models.ContentNode.objects.filter_by_uuids(ids).filter(
available=True
)
queryset = self.filter_queryset(self.get_queryset())
data = list(
queryset.annotate(
num_assessments=SQSum(
Expand Down

0 comments on commit dd6d48d

Please sign in to comment.