fix: Publish components/container in legacy libraries migration (#37644)
- Fix the issue described in https://github.com/openedx/frontend-app-authoring/issues/2626 - Publish components and containers after migrate
This commit is contained in:
@@ -956,7 +956,7 @@ def delete_library_block_static_asset_file(usage_key, file_path, user=None):
|
||||
)
|
||||
|
||||
|
||||
def publish_component_changes(usage_key: LibraryUsageLocatorV2, user: UserType):
|
||||
def publish_component_changes(usage_key: LibraryUsageLocatorV2, user_id: int):
|
||||
"""
|
||||
Publish all pending changes in a single component.
|
||||
"""
|
||||
@@ -969,7 +969,7 @@ def publish_component_changes(usage_key: LibraryUsageLocatorV2, user: UserType):
|
||||
drafts_to_publish = authoring_api.get_all_drafts(learning_package.id).filter(entity__key=component.key)
|
||||
# Publish the component and update anything that needs to be updated (e.g. search index):
|
||||
publish_log = authoring_api.publish_from_drafts(
|
||||
learning_package.id, draft_qset=drafts_to_publish, published_by=user.id,
|
||||
learning_package.id, draft_qset=drafts_to_publish, published_by=user_id,
|
||||
)
|
||||
# Since this is a single component, it should be safe to process synchronously and in-process:
|
||||
tasks.send_events_after_publish(publish_log.pk, str(library_key))
|
||||
|
||||
@@ -575,7 +575,11 @@ def get_containers_contains_item(
|
||||
]
|
||||
|
||||
|
||||
def publish_container_changes(container_key: LibraryContainerLocator, user_id: int | None) -> None:
|
||||
def publish_container_changes(
|
||||
container_key: LibraryContainerLocator,
|
||||
user_id: int | None,
|
||||
call_post_publish_events_sync=False,
|
||||
) -> None:
|
||||
"""
|
||||
[ 🛑 UNSTABLE ] Publish all unpublished changes in a container and all its child
|
||||
containers/blocks.
|
||||
@@ -595,7 +599,10 @@ def publish_container_changes(container_key: LibraryContainerLocator, user_id: i
|
||||
)
|
||||
# Update the search index (and anything else) for the affected container + blocks
|
||||
# This is mostly synchronous but may complete some work asynchronously if there are a lot of changes.
|
||||
tasks.wait_for_post_publish_events(publish_log, library_key)
|
||||
if call_post_publish_events_sync:
|
||||
tasks.send_events_after_publish(publish_log.pk, str(library_key))
|
||||
else:
|
||||
tasks.wait_for_post_publish_events(publish_log, library_key)
|
||||
|
||||
|
||||
def copy_container(container_key: LibraryContainerLocator, user_id: int) -> UserClipboardData:
|
||||
|
||||
@@ -241,7 +241,7 @@ class LibraryBlockPublishView(APIView):
|
||||
request.user,
|
||||
authz_permissions.PUBLISH_LIBRARY_CONTENT
|
||||
)
|
||||
api.publish_component_changes(key, request.user)
|
||||
api.publish_component_changes(key, request.user.id)
|
||||
return Response({})
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user