Skip to content

Commit 0615a89

Browse files
committed
feat: pr suggestions and do not import when no assets
1 parent 0b3b62c commit 0615a89

File tree

3 files changed

+18
-11
lines changed

3 files changed

+18
-11
lines changed

cms/djangoapps/contentstore/helpers.py

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers
3030
import openedx.core.djangoapps.content_staging.api as content_staging_api
3131
import openedx.core.djangoapps.content_tagging.api as content_tagging_api
32+
from openedx.core.lib.xblock_serializer.api import XBlockSerializer
33+
from openedx.core.djangoapps.content_staging.data import LIBRARY_SYNC_PURPOSE
3234

3335
from .utils import reverse_course_url, reverse_library_url, reverse_usage_url
3436

@@ -335,7 +337,7 @@ def import_staged_content_from_user_clipboard(parent_key: UsageKey, request) ->
335337
return new_xblock, notices
336338

337339

338-
def import_staged_content_for_library_sync(downstream_xblock: XBlock, lib_block: XBlock, request) -> StaticFileNotices:
340+
def import_static_assets_for_library_sync(downstream_xblock: XBlock, lib_block: XBlock, request) -> StaticFileNotices:
339341
"""
340342
Import the static assets from the library xblock to the downstream xblock
341343
through staged content. Also updates the OLX references to point to the new
@@ -346,21 +348,26 @@ def import_staged_content_for_library_sync(downstream_xblock: XBlock, lib_block:
346348
Returns a summary of changes made to static files in the destination
347349
course.
348350
"""
351+
if not XBlockSerializer(
352+
lib_block,
353+
fetch_asset_data=True,
354+
).static_files:
355+
return StaticFileNotices()
349356
if not content_staging_api:
350357
raise RuntimeError("The required content_staging app is not installed")
351-
staged_content = content_staging_api.stage_xblock_temporarily(lib_block, request.user.id)
358+
staged_content = content_staging_api.stage_xblock_temporarily(lib_block, request.user.id, LIBRARY_SYNC_PURPOSE)
352359
if not staged_content:
353360
# expired/error/loading
354361
return StaticFileNotices()
355362

356363
store = modulestore()
357-
with store.bulk_operations(downstream_xblock.context_key):
358-
# Now handle static files that need to go into Files & Uploads.
359-
# If the required files already exist, nothing will happen besides updating the olx.
360-
try:
364+
try:
365+
with store.bulk_operations(downstream_xblock.context_key):
366+
# Now handle static files that need to go into Files & Uploads.
367+
# If the required files already exist, nothing will happen besides updating the olx.
361368
notices = _insert_static_files_into_downstream_xblock(downstream_xblock, staged_content.id, request)
362-
finally:
363-
staged_content.delete()
369+
finally:
370+
staged_content.delete()
364371

365372
return notices
366373

cms/djangoapps/contentstore/rest_api/v2/views/downstreams.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@
7373
UpstreamLink, UpstreamLinkException, NoUpstream, BadUpstream, BadDownstream,
7474
fetch_customizable_fields, sync_from_upstream, decline_sync, sever_upstream_link
7575
)
76-
from cms.djangoapps.contentstore.helpers import import_staged_content_for_library_sync
76+
from cms.djangoapps.contentstore.helpers import import_static_assets_for_library_sync
7777
from common.djangoapps.student.auth import has_studio_write_access, has_studio_read_access
7878
from openedx.core.lib.api.view_utils import (
7979
DeveloperErrorViewMixin,
@@ -199,7 +199,7 @@ def post(self, request: _AuthenticatedRequest, usage_key_string: str) -> Respons
199199
downstream = _load_accessible_block(request.user, usage_key_string, require_write_access=True)
200200
try:
201201
upstream = sync_from_upstream(downstream, request.user)
202-
static_file_notices = import_staged_content_for_library_sync(downstream, upstream, request)
202+
static_file_notices = import_static_assets_for_library_sync(downstream, upstream, request)
203203
except UpstreamLinkException as exc:
204204
logger.exception(
205205
"Could not sync from upstream '%s' to downstream '%s'",

openedx/core/djangoapps/content_staging/api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ def save_xblock_to_user_clipboard(block: XBlock, user_id: int, version_num: int
166166

167167

168168
def stage_xblock_temporarily(
169-
block: XBlock, user_id: int, purpose: str = LIBRARY_SYNC_PURPOSE, version_num: int | None = None,
169+
block: XBlock, user_id: int, purpose: str, version_num: int | None = None,
170170
) -> _StagedContent:
171171
"""
172172
"Stage" an XBlock by copying it (and its associated children + static assets)

0 commit comments

Comments
 (0)