Skip to content

Commit a274db0

Browse files
authored
feat: Send events when update containers [FC-0090] (#36866)
* Send `LIBRARY_CONTAINER_UPDATED` for containers that contains the updated unit/section when calling update_container
1 parent 0b48f27 commit a274db0

2 files changed

Lines changed: 195 additions & 73 deletions

File tree

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,7 @@ def update_container(
304304
container_type = ContainerType(container_key.container_type)
305305

306306
version: ContainerVersion
307+
affected_containers: list[ContainerMetadata] = []
307308

308309
match container_type:
309310
case ContainerType.Unit:
@@ -313,29 +314,44 @@ def update_container(
313314
created=created,
314315
created_by=user_id,
315316
)
317+
affected_containers = get_containers_contains_item(container_key)
316318
case ContainerType.Subsection:
317319
version = authoring_api.create_next_subsection_version(
318320
container.subsection,
319321
title=display_name,
320322
created=created,
321323
created_by=user_id,
322324
)
325+
affected_containers = get_containers_contains_item(container_key)
323326
case ContainerType.Section:
324327
version = authoring_api.create_next_section_version(
325328
container.section,
326329
title=display_name,
327330
created=created,
328331
created_by=user_id,
329332
)
333+
334+
# The `affected_containers` are not obtained, because the sections are
335+
# not contained in any container.
330336
case _:
331337
raise NotImplementedError(f"Library does not support {container_type} yet")
332338

339+
# Send event related to the updated container
333340
LIBRARY_CONTAINER_UPDATED.send_event(
334341
library_container=LibraryContainerData(
335342
container_key=container_key,
336343
)
337344
)
338345

346+
# Send events related to the containers that contains the updated container.
347+
# This is to update the children display names used in the section/subsection previews.
348+
for affected_container in affected_containers:
349+
LIBRARY_CONTAINER_UPDATED.send_event(
350+
library_container=LibraryContainerData(
351+
container_key=affected_container.container_key,
352+
)
353+
)
354+
339355
return ContainerMetadata.from_container(library_key, version.container)
340356

341357

0 commit comments

Comments
 (0)