Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions openedx/core/djangoapps/content_libraries/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 "
Expand Down
47 changes: 47 additions & 0 deletions openedx/core/djangoapps/content_libraries/tests/test_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,53 @@ def test_publish_container(self) -> None:
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.
Expand Down
Loading