fix: Call LIBRARY_CONTAINER_PUBLISHED for parent of containers (#37622)

Calls `LIBRARY_CONTAINER_PUBLISHED` when publishing a container that is child of another container.
This commit is contained in:
Chris Chávez
2025-11-12 13:58:49 -05:00
committed by GitHub
parent d2f6bb9aa8
commit 4804c980d4
2 changed files with 56 additions and 0 deletions

View File

@@ -127,6 +127,15 @@ def send_events_after_publish(publish_log_pk: int, library_key_str: str) -> None
elif hasattr(record.entity, "container"):
container_key = api.library_container_locator(library_key, record.entity.container)
affected_containers.add(container_key)
try:
# We do need to notify listeners that the parent container(s) have changed,
# e.g. so the search index can update the "has_unpublished_changes"
for parent_container in api.get_containers_contains_item(container_key):
affected_containers.add(parent_container.container_key)
except api.ContentLibraryContainerNotFound:
# The deleted children remains in the entity, so, in this case, the container may not be found.
pass
else:
log.warning(
f"PublishableEntity {record.entity.pk} / {record.entity.key} was modified during publish operation "

View File

@@ -449,6 +449,53 @@ class ContentLibrariesEventsTestCase(ContentLibrariesRestApiTest):
c2_after = self._get_container(container2["id"])
assert c2_after["has_unpublished_changes"]
def test_publish_child_container(self):
"""
Test the events that get emitted when we publish the changes to a container that is child of another container
"""
# Create some containers
unit = self._create_container(self.lib1_key, "unit", display_name="Alpha Unit", slug=None)
subsection = self._create_container(self.lib1_key, "subsection", display_name="Bravo Subsection", slug=None)
# Add one container as child
self._add_container_children(subsection["id"], children_ids=[unit["id"]])
# At first everything is unpublished:
c1_before = self._get_container(unit["id"])
assert c1_before["has_unpublished_changes"]
c2_before = self._get_container(subsection["id"])
assert c2_before["has_unpublished_changes"]
# clear event log after the initial mock data setup is complete:
self.clear_events()
# Now publish only the unit
self._publish_container(unit["id"])
# Now it is published:
c1_after = self._get_container(unit["id"])
assert c1_after["has_unpublished_changes"] is False
# And publish events were emitted:
self.expect_new_events(
{ # An event for the unit being published:
"signal": LIBRARY_CONTAINER_PUBLISHED,
"library_container": LibraryContainerData(
container_key=LibraryContainerLocator.from_string(unit["id"]),
),
},
{ # An event for parent (subsection):
"signal": LIBRARY_CONTAINER_PUBLISHED,
"library_container": LibraryContainerData(
container_key=LibraryContainerLocator.from_string(subsection["id"]),
),
},
)
# note that subsection is still unpublished
c2_after = self._get_container(subsection["id"])
assert c2_after["has_unpublished_changes"]
def test_restore_unit(self) -> None:
"""
Test restoring a deleted unit via the "restore" API.