Skip to content

Commit d32dcc7

Browse files
committed
fix: Sync and decline sync of units
1 parent 5a97660 commit d32dcc7

File tree

3 files changed

+45
-10
lines changed

3 files changed

+45
-10
lines changed

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

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@
111111
sever_upstream_link,
112112
sync_from_upstream,
113113
)
114+
from cms.lib.xblock.container_upstream_sync import *
114115
from common.djangoapps.student.auth import has_studio_read_access, has_studio_write_access
115116
from openedx.core.lib.api.view_utils import (
116117
DeveloperErrorViewMixin,
@@ -310,11 +311,21 @@ def post(self, request: _AuthenticatedRequest, usage_key_string: str) -> Respons
310311
"""
311312
downstream = _load_accessible_block(request.user, usage_key_string, require_write_access=True)
312313
try:
313-
if downstream.usage_key.block_type == "video":
314-
# Delete all transcripts so we can copy new ones from upstream
315-
clear_transcripts(downstream)
316-
upstream = sync_from_upstream(downstream, request.user)
317-
static_file_notices = import_static_assets_for_library_sync(downstream, upstream, request)
314+
if downstream.usage_key.block_type == "vertical":
315+
UpstreamLinkClass = ContainerUpstreamLink
316+
upstream = sync_from_upstream_container(downstream, request.user)
317+
318+
# TODO support static assets on containers
319+
static_file_notices = None
320+
else:
321+
if downstream.usage_key.block_type == "video":
322+
# Delete all transcripts so we can copy new ones from upstream
323+
clear_transcripts(downstream)
324+
325+
UpstreamLinkClass = UpstreamLink
326+
upstream = sync_from_upstream(downstream, request.user)
327+
328+
static_file_notices = import_static_assets_for_library_sync(downstream, upstream, request)
318329
except UpstreamLinkException as exc:
319330
logger.exception(
320331
"Could not sync from upstream '%s' to downstream '%s'",
@@ -323,10 +334,15 @@ def post(self, request: _AuthenticatedRequest, usage_key_string: str) -> Respons
323334
)
324335
raise ValidationError(detail=str(exc)) from exc
325336
modulestore().update_item(downstream, request.user.id)
326-
# Note: We call `get_for_block` (rather than `try_get_for_block`) because if anything is wrong with the
337+
338+
# Note: We call `get_for_*` (rather than `try_get_for_*`) because if anything is wrong with the
327339
# upstream at this point, then that is completely unexpected, so it's appropriate to let the 500 happen.
328-
response = UpstreamLink.get_for_block(downstream).to_json()
329-
response["static_file_notices"] = attrs_asdict(static_file_notices)
340+
if downstream.usage_key.block_type == "vertical":
341+
response = ContainerUpstreamLink.get_for_container(downstream).to_json()
342+
else:
343+
response = UpstreamLinkClass.get_for_block(downstream).to_json()
344+
response["static_file_notices"] = attrs_asdict(static_file_notices)
345+
330346
return Response(response)
331347

332348
def delete(self, request: _AuthenticatedRequest, usage_key_string: str) -> Response:
@@ -335,7 +351,10 @@ def delete(self, request: _AuthenticatedRequest, usage_key_string: str) -> Respo
335351
"""
336352
downstream = _load_accessible_block(request.user, usage_key_string, require_write_access=True)
337353
try:
338-
decline_sync(downstream)
354+
if downstream.usage_key.block_type == "vertical":
355+
decline_sync_container(downstream)
356+
else:
357+
decline_sync(downstream)
339358
except (NoUpstream, BadUpstream, BadDownstream) as exc:
340359
# This is somewhat unexpected. If the upstream link is missing or invalid, then the downstream author
341360
# shouldn't have been prompted to accept/decline a sync in the first place. Of course, they could have just

cms/djangoapps/contentstore/xblock_storage_handlers/view_handlers.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
from cms.djangoapps.models.settings.course_grading import CourseGradingModel
3737
from cms.lib.ai_aside_summary_config import AiAsideSummaryConfig
3838
from cms.lib.xblock.upstream_sync import BadUpstream, check_and_parse_upstream_key, sync_from_upstream
39-
from cms.lib.xblock.container_upstream_sync import sync_from_upstream_container
39+
from cms.lib.xblock.container_upstream_sync import sync_from_upstream_container, ContainerUpstreamLink
4040
from common.djangoapps.static_replace import replace_static_urls
4141
from common.djangoapps.student.auth import (
4242
has_studio_read_access,
@@ -1244,6 +1244,10 @@ def create_xblock_info( # lint-amnesty, pylint: disable=too-many-statements
12441244
if is_xblock_unit:
12451245
# if xblock is a Unit we add the discussion_enabled option
12461246
xblock_info["discussion_enabled"] = xblock.discussion_enabled
1247+
1248+
# Also add upstream info
1249+
xblock_info["upstream_info"] = ContainerUpstreamLink.try_get_for_container(xblock).to_json()
1250+
12471251
if xblock.category == "sequential":
12481252
# Entrance exam subsection should be hidden. in_entrance_exam is
12491253
# inherited metadata, all children will have it.

cms/lib/xblock/container_upstream_sync.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,3 +200,15 @@ def sync_from_upstream_container(downstream: XBlock, user: User) -> tuple[XBlock
200200
downstream.upstream_version = manager.link.version_available
201201
return manager.upstream, manager.new_children_blocks
202202

203+
204+
def decline_sync_container(downstream: XBlock) -> None:
205+
"""
206+
Given an Container that is linked to upstream content, mark the latest available update as 'declined' so that its
207+
authors are not prompted (until another upstream version becomes available).
208+
209+
Does not save `downstream` to the store. That is left up to the caller.
210+
211+
If `downstream` lacks a valid+supported upstream link, this raises an UpstreamLinkException.
212+
"""
213+
upstream_link = ContainerUpstreamLink.get_for_container(downstream) # Can raise UpstreamLinkException
214+
downstream.upstream_version_declined = upstream_link.version_available

0 commit comments

Comments
 (0)