feat: Add new publish field on container search document (#36551)

* Added publish_display_name and last_published on container search document.
* This change is used in feat: Add unit from library in course [FC-0083] frontend-app-authoring#1829 to show only published units in the unit picker, also to show the published_display_name in the picker, and avoid empty titles.
* Which edX user roles will this change impact? "Developer".
This commit is contained in:
Chris Chávez
2025-04-22 11:58:57 -05:00
committed by GitHub
parent 1608e8f9b6
commit f5e0500854
4 changed files with 20 additions and 5 deletions

View File

@@ -572,6 +572,7 @@ def searchable_doc_for_container(
Fields.block_id: container_key.container_id, # Field name isn't exact but this is the closest match
Fields.access_id: _meili_access_id_from_context_key(container_key.library_key),
Fields.publish_status: PublishStatus.never,
Fields.last_published: None,
}
try:
@@ -593,6 +594,7 @@ def searchable_doc_for_container(
Fields.modified: container.modified.timestamp(),
Fields.num_children: draft_num_children,
Fields.publish_status: publish_status,
Fields.last_published: container.last_published.timestamp() if container.last_published else None,
})
library = lib_api.get_library(container_key.library_key)
if library:
@@ -601,8 +603,8 @@ def searchable_doc_for_container(
if container.published_version_num is not None:
published_num_children = lib_api.get_container_children_count(container_key, published=True)
doc[Fields.published] = {
# Fields.published_display_name: container_published.title, TODO: set the published title
Fields.published_num_children: published_num_children,
Fields.published_display_name: container.published_display_name,
}
return doc

View File

@@ -235,6 +235,7 @@ class TestSearchApi(ModuleStoreTestCase):
"org": "org1",
"created": created_date.timestamp(),
"modified": created_date.timestamp(),
"last_published": None,
"access_id": lib_access.id,
"breadcrumbs": [{"display_name": "Library"}],
# "published" is not set since we haven't published it yet

View File

@@ -534,6 +534,7 @@ class StudioDocumentsTest(SharedModuleStoreTestCase):
"breadcrumbs": [{"display_name": "some content_library"}],
"created": 1680674828.0,
"modified": 1680674828.0,
"last_published": None,
"tags": {
"taxonomy": ["Difficulty"],
"level0": ["Difficulty > Normal"]
@@ -552,7 +553,7 @@ class StudioDocumentsTest(SharedModuleStoreTestCase):
[self.library_block.usage_key],
user_id=None,
)
library_api.publish_changes(self.library.key)
library_api.publish_changes(self.library.key)
doc = searchable_doc_for_container(self.container.container_key)
doc.update(searchable_doc_tags(self.container.container_key))
@@ -573,11 +574,15 @@ class StudioDocumentsTest(SharedModuleStoreTestCase):
"breadcrumbs": [{"display_name": "some content_library"}],
"created": 1680674828.0,
"modified": 1680674828.0,
"last_published": 1680674828.0,
"tags": {
"taxonomy": ["Difficulty"],
"level0": ["Difficulty > Normal"]
},
"published": {"num_children": 1},
"published": {
"num_children": 1,
"display_name": "A Unit in the Search Index",
},
}
def test_published_container_with_changes(self):
@@ -589,7 +594,8 @@ class StudioDocumentsTest(SharedModuleStoreTestCase):
[self.library_block.usage_key],
user_id=None,
)
library_api.publish_changes(self.library.key)
with freeze_time(self.container.created):
library_api.publish_changes(self.library.key)
block_2 = library_api.create_library_block(
self.library.key,
"html",
@@ -624,11 +630,15 @@ class StudioDocumentsTest(SharedModuleStoreTestCase):
"breadcrumbs": [{"display_name": "some content_library"}],
"created": 1680674828.0,
"modified": 1680674828.0,
"last_published": 1680674828.0,
"tags": {
"taxonomy": ["Difficulty"],
"level0": ["Difficulty > Normal"]
},
"published": {"num_children": 1},
"published": {
"num_children": 1,
"display_name": "A Unit in the Search Index",
},
}
def test_mathjax_plain_text_conversion_for_search(self):

View File

@@ -70,6 +70,7 @@ class ContainerMetadata(PublishableItem):
"""
container_key: LibraryContainerLocator
container_type: ContainerType
published_display_name: str | None
@classmethod
def from_container(cls, library_key, container: Container, associated_collections=None):
@@ -103,6 +104,7 @@ class ContainerMetadata(PublishableItem):
modified=draft.created,
draft_version_num=draft.version_num,
published_version_num=published.version_num if published else None,
published_display_name=published.title if published else None,
last_published=None if last_publish_log is None else last_publish_log.published_at,
published_by=published_by,
last_draft_created=last_draft_created,