|
34 | 34 | from olxcleaner.reporting import report_error_summary, report_errors |
35 | 35 | from opaque_keys import InvalidKeyError |
36 | 36 | 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 |
38 | 38 | from organizations.api import add_organization_course, ensure_organization |
39 | 39 | from organizations.exceptions import InvalidOrganizationException |
40 | 40 | from organizations.models import Organization, OrganizationCourse |
@@ -1506,7 +1506,23 @@ def handle_unlink_upstream_block(upstream_usage_key_string: str) -> None: |
1506 | 1506 | upstream_usage_key=upstream_usage_key, |
1507 | 1507 | ): |
1508 | 1508 | 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 | + |
1509 | 1525 | for link in ContainerLink.objects.filter( |
1510 | | - upstream_usage_key=upstream_usage_key, |
| 1526 | + upstream_container_key=upstream_container_key, |
1511 | 1527 | ): |
1512 | 1528 | make_copied_tags_editable(str(link.downstream_usage_key)) |
0 commit comments