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): """ diff --git a/openedx/core/djangoapps/content_libraries/tests/test_content_libraries.py b/openedx/core/djangoapps/content_libraries/tests/test_content_libraries.py index 95b7309b3cd1..b0373f91bb3c 100644 --- a/openedx/core/djangoapps/content_libraries/tests/test_content_libraries.py +++ b/openedx/core/djangoapps/content_libraries/tests/test_content_libraries.py @@ -1020,6 +1020,7 @@ def test_library_paste_clipboard(self): self.assertDictContainsEntries(self._get_library_block(paste_data["id"]), { **block_data, "id": f"lb:CL-TEST:test_lib_paste_clipboard:problem:{pasted_block_id}", + "component_key": f"xblock.v1:problem:{pasted_block_id}", })