Skip to content

Commit 1c55d3c

Browse files
rtibblesbotclaude
andcommitted
feat: add library field to v2 public channel metadata API
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 8eca885 commit 1c55d3c

2 files changed

Lines changed: 50 additions & 0 deletions

File tree

contentcuration/kolibri_public/tests/test_channelmetadata_viewset.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,3 +387,45 @@ def test_labels_language_objects_have_id_and_lang_name(self):
387387
for lang in response.data["languages"]:
388388
self.assertIn("id", lang)
389389
self.assertIn("lang_name", lang)
390+
391+
392+
class ChannelMetadataLibraryFieldTestCase(StudioAPITestCase):
393+
def setUp(self):
394+
super().setUp()
395+
self.mixer = KolibriPublicMixer()
396+
self.user = testdata.user("library@test.com")
397+
self.client.force_authenticate(self.user)
398+
399+
def test_public_channel_returns_library_kolibri(self):
400+
"""
401+
A public channel in the v2 API returns library: "KOLIBRI".
402+
"""
403+
channel = self.mixer.blend(ChannelMetadata, public=True)
404+
405+
response = self.client.get(
406+
reverse_with_query(
407+
"publicchannel-detail",
408+
args=[channel.id],
409+
query={"public": "true"},
410+
),
411+
)
412+
413+
self.assertEqual(response.status_code, 200, response.content)
414+
self.assertEqual(response.data["library"], "KOLIBRI")
415+
416+
def test_non_public_channel_returns_library_community(self):
417+
"""
418+
A non-public channel in the v2 API returns library: "COMMUNITY".
419+
"""
420+
channel = self.mixer.blend(ChannelMetadata, public=False)
421+
422+
response = self.client.get(
423+
reverse_with_query(
424+
"publicchannel-detail",
425+
args=[channel.id],
426+
query={"public": "false"},
427+
),
428+
)
429+
430+
self.assertEqual(response.status_code, 200, response.content)
431+
self.assertEqual(response.data["library"], "COMMUNITY")

contentcuration/kolibri_public/views.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
from kolibri_public.search import get_contentnode_available_metadata_labels
3838
from kolibri_public.stopwords import stopwords_set
3939
from le_utils.constants import content_kinds
40+
from le_utils.constants import library as library_constants
4041
from rest_framework import status
4142
from rest_framework.decorators import action
4243
from rest_framework.filters import SearchFilter
@@ -252,6 +253,13 @@ def consolidate(self, items, queryset):
252253
item["countries"] = countries.get(item["id"], [])
253254
item["token"] = channel_tokens.get(item["id"])
254255
item["last_published"] = item["last_updated"]
256+
# v2 non-public channels are always community library channels (unlike v1
257+
# channel tokens, which return null for non-public channels).
258+
item["library"] = (
259+
library_constants.KOLIBRI
260+
if item["public"]
261+
else library_constants.COMMUNITY
262+
)
255263

256264
return items
257265

0 commit comments

Comments
 (0)