From 383ed5067a6fefc8006111bfa685848320253ad1 Mon Sep 17 00:00:00 2001 From: Jillian Vogel Date: Wed, 28 Aug 2024 13:31:45 +0930 Subject: [PATCH] feat: adds component_key to LibraryXBlockMetadata and its serializer so the frontend has component_keys for use with the /collection/contents endpoint. --- openedx/core/djangoapps/content_libraries/api.py | 2 ++ openedx/core/djangoapps/content_libraries/serializers.py | 3 +++ 2 files changed, 5 insertions(+) diff --git a/openedx/core/djangoapps/content_libraries/api.py b/openedx/core/djangoapps/content_libraries/api.py index 9a4ccbd6456e..a4ae815dde0f 100644 --- a/openedx/core/djangoapps/content_libraries/api.py +++ b/openedx/core/djangoapps/content_libraries/api.py @@ -206,6 +206,7 @@ class LibraryXBlockMetadata: last_published = attr.ib(default=None, type=datetime) has_unpublished_changes = attr.ib(False) tags_count = attr.ib(0) + component_key = attr.ib(default=None, type=str) @classmethod def from_component(cls, library_key, component): @@ -215,6 +216,7 @@ def from_component(cls, library_key, component): last_publish_log = component.versioning.last_publish_log return cls( + component_key=component.key, usage_key=LibraryUsageLocatorV2( library_key, component.component_type.name, diff --git a/openedx/core/djangoapps/content_libraries/serializers.py b/openedx/core/djangoapps/content_libraries/serializers.py index 7c49d4af3c2b..60892cb61ebc 100644 --- a/openedx/core/djangoapps/content_libraries/serializers.py +++ b/openedx/core/djangoapps/content_libraries/serializers.py @@ -152,6 +152,9 @@ class LibraryXBlockMetadataSerializer(serializers.Serializer): slug = serializers.CharField(write_only=True) tags_count = serializers.IntegerField(read_only=True) + # Key for the Component / PublishableEntity associated with this XBlock + component_key = serializers.CharField(read_only=True) + class LibraryXBlockTypeSerializer(serializers.Serializer): """