diff --git a/kolibri/core/content/api.py b/kolibri/core/content/api.py index a9bfb7272f9..35682a996e0 100644 --- a/kolibri/core/content/api.py +++ b/kolibri/core/content/api.py @@ -969,8 +969,12 @@ def get_grandchild_ids(self, child_ids, depth, page_size): def get_tree_queryset(self, request, pk): # Get the model for the parent node here - we do this so that we trigger a 404 immediately if the node - # does not exist (or exists but is not available). - parent_id = pk if pk and self.get_queryset().filter(id=pk).exists() else None + # does not exist (or exists but is not available, or is filtered). + parent_id = ( + pk + if pk and self.filter_queryset(self.get_queryset()).filter(id=pk).exists() + else None + ) if parent_id is None: raise Http404 diff --git a/kolibri/core/content/test/test_content_app.py b/kolibri/core/content/test/test_content_app.py index 3be3403c021..60771c60c17 100644 --- a/kolibri/core/content/test/test_content_app.py +++ b/kolibri/core/content/test/test_content_app.py @@ -422,6 +422,14 @@ def test_contentnode_tree(self): ) self._recurse_and_assert([response.data], [root]) + def test_contentnode_tree_filtered_queryset_node(self): + root = content.ContentNode.objects.get(title="root") + response = self.client.get( + reverse("kolibri:core:contentnode_tree-detail", kwargs={"pk": root.id}) + + "?parent={}".format(uuid.uuid4().hex) + ) + self.assertEqual(response.status_code, 404) + @unittest.skipIf( getattr(settings, "DATABASES")["default"]["ENGINE"] == "django.db.backends.postgresql",