Skip to content

Commit f58c6f0

Browse files
authored
fix: wrap sequence metadata view in bulk actions contextmanager (#36854)
* fix: wrap sequence metadata view in bulk actions contextmanager * style: line too long
1 parent 3d664b0 commit f58c6f0

File tree

1 file changed

+22
-19
lines changed
  • openedx/core/djangoapps/courseware_api

1 file changed

+22
-19
lines changed

openedx/core/djangoapps/courseware_api/views.py

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -605,25 +605,28 @@ def get(self, request, usage_key_string, *args, **kwargs): # lint-amnesty, pyli
605605
) if is_preview and staff_access else (
606606
ModuleStoreEnum.Branch.published_only
607607
)
608-
609-
with modulestore().branch_setting(branch_type, usage_key.course_key):
610-
sequence, _ = get_block_by_usage_id(
611-
self.request,
612-
str(usage_key.course_key),
613-
str(usage_key),
614-
disable_staff_debug_info=True,
615-
will_recheck_access=True)
616-
617-
if not hasattr(sequence, 'get_metadata'):
618-
# Looks like we were asked for metadata on something that is not a sequence (or section).
619-
return Response(status=status.HTTP_422_UNPROCESSABLE_ENTITY)
620-
621-
view = STUDENT_VIEW
622-
if request.user.is_anonymous:
623-
view = PUBLIC_VIEW
624-
625-
context = {'specific_masquerade': is_masquerading_as_specific_student(request.user, usage_key.course_key)}
626-
return Response(sequence.get_metadata(view=view, context=context))
608+
_modulestore = modulestore()
609+
with _modulestore.branch_setting(branch_type, usage_key.course_key):
610+
with _modulestore.bulk_operations(usage_key.course_key):
611+
sequence, _ = get_block_by_usage_id(
612+
self.request,
613+
str(usage_key.course_key),
614+
str(usage_key),
615+
disable_staff_debug_info=True,
616+
will_recheck_access=True)
617+
618+
if not hasattr(sequence, 'get_metadata'):
619+
# Looks like we were asked for metadata on something that is not a sequence (or section).
620+
return Response(status=status.HTTP_422_UNPROCESSABLE_ENTITY)
621+
622+
view = STUDENT_VIEW
623+
if request.user.is_anonymous:
624+
view = PUBLIC_VIEW
625+
626+
context = {
627+
'specific_masquerade': is_masquerading_as_specific_student(request.user, usage_key.course_key)
628+
}
629+
return Response(sequence.get_metadata(view=view, context=context))
627630

628631

629632
class Resume(DeveloperErrorViewMixin, APIView):

0 commit comments

Comments
 (0)