Skip to content

Commit d664f0e

Browse files
committed
fix: update container key field usage
1 parent 956a289 commit d664f0e

2 files changed

Lines changed: 34 additions & 2 deletions

File tree

cms/djangoapps/contentstore/signals/handlers.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,14 @@
1717
CourseData,
1818
CourseScheduleData,
1919
LibraryBlockData,
20+
LibraryContainerData,
2021
XBlockData,
2122
)
2223
from openedx_events.content_authoring.signals import (
2324
COURSE_CATALOG_INFO_CHANGED,
2425
COURSE_IMPORT_COMPLETED,
2526
LIBRARY_BLOCK_DELETED,
27+
LIBRARY_CONTAINER_DELETED,
2628
XBLOCK_CREATED,
2729
XBLOCK_DELETED,
2830
XBLOCK_UPDATED,
@@ -49,6 +51,7 @@
4951
create_or_update_upstream_links,
5052
handle_create_or_update_xblock_upstream_link,
5153
handle_unlink_upstream_block,
54+
handle_unlink_upstream_container,
5255
)
5356
from .signals import GRADING_POLICY_CHANGED
5457

@@ -314,3 +317,16 @@ def unlink_upstream_block_handler(**kwargs):
314317
return
315318

316319
handle_unlink_upstream_block.delay(str(library_block.usage_key))
320+
321+
322+
@receiver(LIBRARY_CONTAINER_DELETED)
323+
def unlink_upstream_container_handler(**kwargs):
324+
"""
325+
Handle unlinking the upstream (library) container from any downstream (course) blocks.
326+
"""
327+
library_container = kwargs.get("library_container", None)
328+
if not library_container or not isinstance(library_container, LibraryContainerData): # pragma: no cover
329+
log.error("Received null or incorrect data for event")
330+
return
331+
332+
handle_unlink_upstream_container.delay(str(library_container.container_key))

cms/djangoapps/contentstore/tasks.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
from olxcleaner.reporting import report_error_summary, report_errors
3535
from opaque_keys import InvalidKeyError
3636
from opaque_keys.edx.keys import CourseKey, UsageKey
37-
from opaque_keys.edx.locator import LibraryLocator
37+
from opaque_keys.edx.locator import LibraryLocator, LibraryContainerLocator
3838
from organizations.api import add_organization_course, ensure_organization
3939
from organizations.exceptions import InvalidOrganizationException
4040
from organizations.models import Organization, OrganizationCourse
@@ -1506,7 +1506,23 @@ def handle_unlink_upstream_block(upstream_usage_key_string: str) -> None:
15061506
upstream_usage_key=upstream_usage_key,
15071507
):
15081508
make_copied_tags_editable(str(link.downstream_usage_key))
1509+
1510+
1511+
@shared_task
1512+
@set_code_owner_attribute
1513+
def handle_unlink_upstream_container(upstream_container_key_string: str) -> None:
1514+
"""
1515+
Handle updates needed to downstream blocks when the upstream link is severed.
1516+
"""
1517+
ensure_cms("handle_unlink_upstream_container may only be executed in a CMS context")
1518+
1519+
try:
1520+
upstream_container_key = LibraryContainerLocator.from_string(upstream_container_key_string)
1521+
except (InvalidKeyError):
1522+
LOGGER.exception(f'Invalid upstream container_key: {upstream_container_key_string}')
1523+
return
1524+
15091525
for link in ContainerLink.objects.filter(
1510-
upstream_usage_key=upstream_usage_key,
1526+
upstream_container_key=upstream_container_key,
15111527
):
15121528
make_copied_tags_editable(str(link.downstream_usage_key))

0 commit comments

Comments
 (0)