From 1b09b12c7f507b8c8b234db207983df2cbaefea5 Mon Sep 17 00:00:00 2001 From: Sagirov Eugeniy Date: Thu, 3 Oct 2024 14:22:36 +0300 Subject: [PATCH] feat: [FC-0070] Create a new Studio view for rendering whole Unit in an iframe --- .../contentstore/views/component.py | 32 +- .../views/tests/test_container_page.py | 58 ++ cms/envs/common.py | 6 + cms/static/images/pencil-icon.svg | 3 + cms/static/js/views/pages/container.js | 168 +++-- .../sass/course-unit-mfe-iframe-bundle.scss | 651 ++++++++++++++++++ .../elements/_course-unit-mfe-iframe.scss | 65 ++ .../partials/cms/theme/_variables-v1.scss | 9 + cms/templates/container_chromeless.html | 278 ++++++++ cms/urls.py | 2 + 10 files changed, 1195 insertions(+), 77 deletions(-) create mode 100644 cms/static/images/pencil-icon.svg create mode 100644 cms/static/sass/course-unit-mfe-iframe-bundle.scss create mode 100644 cms/static/sass/elements/_course-unit-mfe-iframe.scss create mode 100644 cms/templates/container_chromeless.html diff --git a/cms/djangoapps/contentstore/views/component.py b/cms/djangoapps/contentstore/views/component.py index ba767df78dc9..5b6dd30ab844 100644 --- a/cms/djangoapps/contentstore/views/component.py +++ b/cms/djangoapps/contentstore/views/component.py @@ -35,7 +35,8 @@ __all__ = [ 'container_handler', - 'component_handler' + 'component_handler', + 'container_embed_handler', ] log = logging.getLogger(__name__) @@ -141,6 +142,35 @@ def container_handler(request, usage_key_string): # pylint: disable=too-many-st return HttpResponseBadRequest("Only supports HTML requests") +@require_GET +@login_required +def container_embed_handler(request, usage_key_string): # pylint: disable=too-many-statements + """ + Returns an HttpResponse with HTML content for the container XBlock. + The returned HTML is a chromeless rendering of the XBlock. + + GET + html: returns the HTML page for editing a container + json: not currently supported + """ + + # Avoiding a circular dependency + from ..utils import get_container_handler_context + + try: + usage_key = UsageKey.from_string(usage_key_string) + except InvalidKeyError: # Raise Http404 on invalid 'usage_key_string' + return HttpResponseBadRequest() + with modulestore().bulk_operations(usage_key.course_key): + try: + course, xblock, lms_link, preview_lms_link = _get_item_in_course(request, usage_key) + except ItemNotFoundError: + raise Http404 # lint-amnesty, pylint: disable=raise-missing-from + + container_handler_context = get_container_handler_context(request, usage_key, course, xblock) + return render_to_response('container_chromeless.html', container_handler_context) + + def get_component_templates(courselike, library=False): # lint-amnesty, pylint: disable=too-many-statements """ Returns the applicable component templates that can be used by the specified course or library. diff --git a/cms/djangoapps/contentstore/views/tests/test_container_page.py b/cms/djangoapps/contentstore/views/tests/test_container_page.py index 1d5b52905357..426477e23408 100644 --- a/cms/djangoapps/contentstore/views/tests/test_container_page.py +++ b/cms/djangoapps/contentstore/views/tests/test_container_page.py @@ -242,3 +242,61 @@ def test_container_page_with_valid_and_invalid_usage_key_string(self): usage_key_string=str(self.vertical.location) ) self.assertEqual(response.status_code, 200) + + +class ContainerEmbedPageTestCase(ContainerPageTestCase): # lint-amnesty, pylint: disable=test-inherits-tests + """ + Unit tests for the container embed page. + """ + + def test_container_html(self): + assets_url = reverse( + 'assets_handler', kwargs={'course_key_string': str(self.child_container.location.course_key)} + ) + self._test_html_content( + self.child_container, + expected_section_tag=( + '