Skip to content

Commit

Permalink
feat: adds component_key to LibraryXBlockMetadata
Browse files Browse the repository at this point in the history
and its serializer so the frontend has component_keys for use with the
/collection/contents endpoint.
  • Loading branch information
pomegranited committed Aug 28, 2024
1 parent 250434f commit 0c4e872
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 0 deletions.
2 changes: 2 additions & 0 deletions openedx/core/djangoapps/content_libraries/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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,
Expand Down
3 changes: 3 additions & 0 deletions openedx/core/djangoapps/content_libraries/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}",
})


Expand Down

0 comments on commit 0c4e872

Please sign in to comment.