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
20 changes: 19 additions & 1 deletion cms/djangoapps/modulestore_migrator/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -1077,7 +1077,8 @@ def _migrate_container(
entity_id=container.container_pk,
version_num=container.draft_version_num,
)
return authoring_api.create_next_container_version(

container_publishable_entity_version = authoring_api.create_next_container_version(
container.container_pk,
title=title,
entity_rows=[
Expand All @@ -1089,6 +1090,17 @@ def _migrate_container(
container_version_cls=container_type.container_model_classes[1],
).publishable_entity_version

# Publish the container
# Call post publish events synchronously to avoid
# an error when calling `wait_for_post_publish_events`
# inside a celery task.
libraries_api.publish_container_changes(
container.container_key,
context.created_by,
call_post_publish_events_sync=True,
)
return container_publishable_entity_version


def _migrate_component(
*,
Expand Down Expand Up @@ -1153,6 +1165,12 @@ def _migrate_component(
authoring_api.create_component_version_content(
component_version.pk, content_pk, key=new_path
)

# Publish the component
libraries_api.publish_component_changes(
libraries_api.library_component_usage_key(context.target_library_key, component),
context.created_by,
)
return component_version.publishable_entity_version


Expand Down
5 changes: 5 additions & 0 deletions cms/djangoapps/modulestore_migrator/tests/test_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,9 @@ def test_migrate_component_success(self):
"problem", result.componentversion.component.component_type.name
)

# The component is published
self.assertFalse(result.componentversion.component.versioning.has_unpublished_changes)

def test_migrate_component_with_static_content(self):
"""
Test _migrate_component with static file content
Expand Down Expand Up @@ -897,6 +900,8 @@ def test_migrate_container_different_container_types(self):

container_version = result.containerversion
self.assertEqual(container_version.title, f"Test {block_type.title()}")
# The container is published
self.assertFalse(authoring_api.contains_unpublished_changes(container_version.container.pk))

def test_migrate_container_replace_existing_false(self):
"""
Expand Down
4 changes: 2 additions & 2 deletions openedx/core/djangoapps/content_libraries/api/blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
"""
Expand All @@ -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))
Expand Down
11 changes: 9 additions & 2 deletions openedx/core/djangoapps/content_libraries/api/containers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ def post(self, request, usage_key_str):
request.user,
authz_permissions.PUBLISH_LIBRARY_CONTENT
)
api.publish_component_changes(key, request.user)
api.publish_component_changes(key, request.user.id)
return Response({})


Expand Down
Loading