Skip to content

Commit

Permalink
feat: [AXIMST-410] add posibility to fetch draft item
Browse files Browse the repository at this point in the history
  • Loading branch information
ruzniaievdm committed Feb 6, 2024
1 parent 93cb201 commit a1e2897
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
13 changes: 12 additions & 1 deletion lms/djangoapps/courseware/block_render.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@
from common.djangoapps.edxmako.services import MakoService
from common.djangoapps.xblock_django.user_service import DjangoXBlockUserService
from openedx.core.lib.cache_utils import CacheService
from xmodule.modulestore import ModuleStoreEnum # lint-amnesty, pylint: disable=wrong-import-order


if TYPE_CHECKING:
from rest_framework.request import Request
Expand Down Expand Up @@ -828,7 +830,16 @@ def _get_block_by_usage_key(usage_key):
usage_key.course_key,
usage_key
)
raise Http404 from exc
try:
block = modulestore().get_item(usage_key, revision=ModuleStoreEnum.RevisionOption.draft_only)
block_orig_usage_key, block_orig_version = modulestore().get_block_original_usage(usage_key)
except ItemNotFoundError:
log.warning(
"Invalid draft location for course id %s: %s",
usage_key.course_key,
usage_key
)
raise Http404 from exc

tracking_context = {
'module': {
Expand Down
3 changes: 2 additions & 1 deletion lms/djangoapps/courseware/views/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1536,6 +1536,7 @@ def render_xblock(request, usage_key_string, check_if_enrolled=True, disable_sta
set_custom_attribute('block_type', usage_key.block_type)

requested_view = request.GET.get('view', 'student_view')
is_authoring_mfe = request.GET.get('is_authoring_mfe')
if requested_view != 'student_view' and requested_view != 'public_view': # lint-amnesty, pylint: disable=consider-using-in
return HttpResponseBadRequest(
f"Rendering of the xblock view '{bleach.clean(requested_view, strip=True)}' is not supported."
Expand Down Expand Up @@ -1651,7 +1652,7 @@ def render_xblock(request, usage_key_string, check_if_enrolled=True, disable_sta
'web_app_course_url': get_learning_mfe_home_url(course_key=course.id, url_fragment='home'),
'on_courseware_page': True,
'verified_upgrade_link': verified_upgrade_deadline_link(request.user, course=course),
'is_learning_mfe': is_learning_mfe,
'is_learning_mfe': is_authoring_mfe or is_learning_mfe,
'is_mobile_app': is_mobile_app,
'render_course_wide_assets': True,

Expand Down
7 changes: 7 additions & 0 deletions lms/templates/courseware/courseware-chromeless.html
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@
var $$course_id = "${course.id | n, js_escaped_string}";
</script>

% if block:
<script type="text/javascript">
var $$xBlockLocation = "${block.location | n, js_escaped_string}";
</script>
% endif

</%block>

<%block name="js_extra">
Expand Down Expand Up @@ -183,6 +189,7 @@

window.parent.postMessage({
type: 'plugin.resize',
location: $$xBlockLocation || '',
payload: {
width: newWidth,
height: newHeight,
Expand Down

0 comments on commit a1e2897

Please sign in to comment.