Skip to content

Commit 8f3f50d

Browse files
ChrisChVmarlonkeating
authored andcommitted
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".
1 parent 232cc11 commit 8f3f50d

4 files changed

Lines changed: 20 additions & 5 deletions

File tree

openedx/core/djangoapps/content/search/documents.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -572,6 +572,7 @@ def searchable_doc_for_container(
572572
Fields.block_id: container_key.container_id, # Field name isn't exact but this is the closest match
573573
Fields.access_id: _meili_access_id_from_context_key(container_key.library_key),
574574
Fields.publish_status: PublishStatus.never,
575+
Fields.last_published: None,
575576
}
576577

577578
try:
@@ -593,6 +594,7 @@ def searchable_doc_for_container(
593594
Fields.modified: container.modified.timestamp(),
594595
Fields.num_children: draft_num_children,
595596
Fields.publish_status: publish_status,
597+
Fields.last_published: container.last_published.timestamp() if container.last_published else None,
596598
})
597599
library = lib_api.get_library(container_key.library_key)
598600
if library:
@@ -601,8 +603,8 @@ def searchable_doc_for_container(
601603
if container.published_version_num is not None:
602604
published_num_children = lib_api.get_container_children_count(container_key, published=True)
603605
doc[Fields.published] = {
604-
# Fields.published_display_name: container_published.title, TODO: set the published title
605606
Fields.published_num_children: published_num_children,
607+
Fields.published_display_name: container.published_display_name,
606608
}
607609

608610
return doc

openedx/core/djangoapps/content/search/tests/test_api.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,7 @@ def setUp(self):
235235
"org": "org1",
236236
"created": created_date.timestamp(),
237237
"modified": created_date.timestamp(),
238+
"last_published": None,
238239
"access_id": lib_access.id,
239240
"breadcrumbs": [{"display_name": "Library"}],
240241
# "published" is not set since we haven't published it yet

openedx/core/djangoapps/content/search/tests/test_documents.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -534,6 +534,7 @@ def test_draft_container(self):
534534
"breadcrumbs": [{"display_name": "some content_library"}],
535535
"created": 1680674828.0,
536536
"modified": 1680674828.0,
537+
"last_published": None,
537538
"tags": {
538539
"taxonomy": ["Difficulty"],
539540
"level0": ["Difficulty > Normal"]
@@ -552,7 +553,7 @@ def test_published_container(self):
552553
[self.library_block.usage_key],
553554
user_id=None,
554555
)
555-
library_api.publish_changes(self.library.key)
556+
library_api.publish_changes(self.library.key)
556557

557558
doc = searchable_doc_for_container(self.container.container_key)
558559
doc.update(searchable_doc_tags(self.container.container_key))
@@ -573,11 +574,15 @@ def test_published_container(self):
573574
"breadcrumbs": [{"display_name": "some content_library"}],
574575
"created": 1680674828.0,
575576
"modified": 1680674828.0,
577+
"last_published": 1680674828.0,
576578
"tags": {
577579
"taxonomy": ["Difficulty"],
578580
"level0": ["Difficulty > Normal"]
579581
},
580-
"published": {"num_children": 1},
582+
"published": {
583+
"num_children": 1,
584+
"display_name": "A Unit in the Search Index",
585+
},
581586
}
582587

583588
def test_published_container_with_changes(self):
@@ -589,7 +594,8 @@ def test_published_container_with_changes(self):
589594
[self.library_block.usage_key],
590595
user_id=None,
591596
)
592-
library_api.publish_changes(self.library.key)
597+
with freeze_time(self.container.created):
598+
library_api.publish_changes(self.library.key)
593599
block_2 = library_api.create_library_block(
594600
self.library.key,
595601
"html",
@@ -624,11 +630,15 @@ def test_published_container_with_changes(self):
624630
"breadcrumbs": [{"display_name": "some content_library"}],
625631
"created": 1680674828.0,
626632
"modified": 1680674828.0,
633+
"last_published": 1680674828.0,
627634
"tags": {
628635
"taxonomy": ["Difficulty"],
629636
"level0": ["Difficulty > Normal"]
630637
},
631-
"published": {"num_children": 1},
638+
"published": {
639+
"num_children": 1,
640+
"display_name": "A Unit in the Search Index",
641+
},
632642
}
633643

634644
def test_mathjax_plain_text_conversion_for_search(self):

openedx/core/djangoapps/content_libraries/api/containers.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ class ContainerMetadata(PublishableItem):
7070
"""
7171
container_key: LibraryContainerLocator
7272
container_type: ContainerType
73+
published_display_name: str | None
7374

7475
@classmethod
7576
def from_container(cls, library_key, container: Container, associated_collections=None):
@@ -103,6 +104,7 @@ def from_container(cls, library_key, container: Container, associated_collection
103104
modified=draft.created,
104105
draft_version_num=draft.version_num,
105106
published_version_num=published.version_num if published else None,
107+
published_display_name=published.title if published else None,
106108
last_published=None if last_publish_log is None else last_publish_log.published_at,
107109
published_by=published_by,
108110
last_draft_created=last_draft_created,

0 commit comments

Comments
 (0)