Skip to content

Commit 945025a

Browse files
committed
fix: Update SyncFromUpstreamView support accept/decline containers
1 parent ddda5b5 commit 945025a

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

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

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,10 @@
9999
ComponentLinksSerializer,
100100
PublishableEntityLinksSummarySerializer,
101101
)
102-
from cms.djangoapps.contentstore.xblock_storage_handlers.view_handlers import sync_library_content
102+
from cms.djangoapps.contentstore.xblock_storage_handlers.view_handlers import (
103+
sync_library_content,
104+
get_upstream,
105+
)
103106
from cms.lib.xblock.upstream_sync import (
104107
BadDownstream,
105108
BadUpstream,
@@ -110,6 +113,7 @@
110113
decline_sync,
111114
sever_upstream_link,
112115
)
116+
from cms.lib.xblock.container_upstream_sync import decline_sync_container
113117
from common.djangoapps.student.auth import has_studio_read_access, has_studio_write_access
114118
from openedx.core.lib.api.view_utils import (
115119
DeveloperErrorViewMixin,
@@ -330,7 +334,7 @@ def post(self, request: _AuthenticatedRequest, usage_key_string: str) -> Respons
330334
raise ValidationError(detail=str(exc)) from exc
331335
# Note: We call `get_for_block` (rather than `try_get_for_block`) because if anything is wrong with the
332336
# upstream at this point, then that is completely unexpected, so it's appropriate to let the 500 happen.
333-
response = UpstreamLink.get_for_block(downstream).to_json()
337+
response = get_upstream(downstream)
334338
response["static_file_notices"] = attrs_asdict(static_file_notices)
335339
return Response(response)
336340

@@ -340,7 +344,10 @@ def delete(self, request: _AuthenticatedRequest, usage_key_string: str) -> Respo
340344
"""
341345
downstream = _load_accessible_block(request.user, usage_key_string, require_write_access=True)
342346
try:
343-
decline_sync(downstream)
347+
if downstream.usage_key.block_type == 'vertical':
348+
decline_sync_container(downstream)
349+
else:
350+
decline_sync(downstream)
344351
except (NoUpstream, BadUpstream, BadDownstream) as exc:
345352
# This is somewhat unexpected. If the upstream link is missing or invalid, then the downstream author
346353
# 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: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
from cms.djangoapps.contentstore.config.waffle import SHOW_REVIEW_RULES_FLAG
3636
from cms.djangoapps.models.settings.course_grading import CourseGradingModel
3737
from cms.lib.ai_aside_summary_config import AiAsideSummaryConfig
38-
from cms.lib.xblock.upstream_sync import BadUpstream, check_and_parse_upstream_key, sync_from_upstream
38+
from cms.lib.xblock.upstream_sync import *
3939
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 (
@@ -551,6 +551,15 @@ def sync_library_content(downstream: XBlock, request, store, remove_upstream_lin
551551
return static_file_notices
552552

553553

554+
def get_upstream(downstream: XBlock):
555+
"""
556+
Handle get upstream for containers or blocks, depending of the donwstream type.
557+
"""
558+
if downstream.usage_key.block_type == 'vertical':
559+
return ContainerUpstreamLink.get_for_container(downstream).to_json()
560+
return UpstreamLink.get_for_block(downstream).to_json()
561+
562+
554563
@login_required
555564
@expect_json
556565
def _create_block(request):

0 commit comments

Comments
 (0)