From 7abb417b0f6dc7bfb3c0cc21dc980a66ca7d0e0a Mon Sep 17 00:00:00 2001 From: Kshitij Sobti Date: Thu, 11 Mar 2021 18:38:23 +0530 Subject: [PATCH] feat: Add a waffle flag to show/hide a link to the pages and resources view The Pages and Resources view in the Course Autoring MFE is in development and this flag allows enabling a link to it from the existing Pages view in Studio using a waffle flag. --- cms/djangoapps/contentstore/config/waffle.py | 16 ++++++++++ cms/djangoapps/contentstore/utils.py | 31 +++++++++++++++---- cms/djangoapps/contentstore/views/tabs.py | 4 +-- .../contentstore/views/tests/test_tabs.py | 16 ++++++++++ cms/templates/edit-tabs.html | 5 +++ 5 files changed, 64 insertions(+), 8 deletions(-) diff --git a/cms/djangoapps/contentstore/config/waffle.py b/cms/djangoapps/contentstore/config/waffle.py index e9c1bd90cd..86d0151ae4 100644 --- a/cms/djangoapps/contentstore/config/waffle.py +++ b/cms/djangoapps/contentstore/config/waffle.py @@ -67,3 +67,19 @@ REDIRECT_TO_LIBRARY_AUTHORING_MICROFRONTEND = LegacyWaffleFlag( flag_name='library_authoring_mfe', module_name=__name__, ) + + +# .. toggle_name: studio.pages_and_resources_mfe +# .. toggle_implementation: CourseWaffleFlag +# .. toggle_default: False +# .. toggle_description: Waffle flag to link existing studio views to the new Pages and Resources experience. +# .. toggle_use_cases: temporary, open_edx +# .. toggle_creation_date: 2021-05-24 +# .. toggle_target_removal_date: 2021-12-31 +# .. toggle_warnings: Also set settings.COURSE_AUTHORING_MICROFRONTEND_URL. +# .. toggle_tickets: None +ENABLE_PAGES_AND_RESOURCES_MICROFRONTEND = CourseWaffleFlag( + waffle_namespace=waffle_flags(), + flag_name='pages_and_resources_mfe', + module_name=__name__, +) diff --git a/cms/djangoapps/contentstore/utils.py b/cms/djangoapps/contentstore/utils.py index fec962e24c..db310a6100 100644 --- a/cms/djangoapps/contentstore/utils.py +++ b/cms/djangoapps/contentstore/utils.py @@ -15,6 +15,7 @@ from opaque_keys.edx.keys import CourseKey, UsageKey from opaque_keys.edx.locator import LibraryLocator from pytz import UTC +from cms.djangoapps.contentstore.config.waffle import ENABLE_PAGES_AND_RESOURCES_MICROFRONTEND from common.djangoapps.student import auth from common.djangoapps.student.models import CourseEnrollment from common.djangoapps.student.roles import CourseInstructorRole, CourseStaffRole @@ -156,18 +157,36 @@ def get_lms_link_for_certificate_web_view(course_key, mode): ) +def get_course_authoring_url(course_module): + """ + Gets course authoring microfrontend URL + """ + return configuration_helpers.get_value_for_org( + course_module.location.org, + 'COURSE_AUTHORING_MICROFRONTEND_URL', + settings.COURSE_AUTHORING_MICROFRONTEND_URL + ) + + +def get_pages_and_resources_url(course_module): + """ + Gets course authoring microfrontend URL for Pages and Resources view. + """ + pages_and_resources_url = None + if ENABLE_PAGES_AND_RESOURCES_MICROFRONTEND.is_enabled(course_module.id): + mfe_base_url = get_course_authoring_url(course_module) + if mfe_base_url: + pages_and_resources_url = f'{mfe_base_url}/course/{course_module.id}/pages-and-resources' + return pages_and_resources_url + + def get_proctored_exam_settings_url(course_module): """ Gets course authoring microfrontend URL for links to proctored exam settings page """ course_authoring_microfrontend_url = '' - if settings.FEATURES.get('ENABLE_EXAM_SETTINGS_HTML_VIEW'): - course_authoring_microfrontend_url = configuration_helpers.get_value_for_org( - course_module.location.org, - 'COURSE_AUTHORING_MICROFRONTEND_URL', - settings.COURSE_AUTHORING_MICROFRONTEND_URL - ) + course_authoring_microfrontend_url = get_course_authoring_url(course_module) return course_authoring_microfrontend_url diff --git a/cms/djangoapps/contentstore/views/tabs.py b/cms/djangoapps/contentstore/views/tabs.py index 251771ac60..c6db72d797 100644 --- a/cms/djangoapps/contentstore/views/tabs.py +++ b/cms/djangoapps/contentstore/views/tabs.py @@ -15,8 +15,7 @@ from xmodule.modulestore import ModuleStoreEnum from xmodule.modulestore.django import modulestore from xmodule.tabs import CourseTab, CourseTabList, InvalidTabsException, StaticTab -from ..utils import get_lms_link_for_item - +from ..utils import get_lms_link_for_item, get_pages_and_resources_url __all__ = ['tabs_handler'] @@ -72,6 +71,7 @@ def tabs_handler(request, course_key_string): 'context_course': course_item, 'tabs_to_render': tabs_to_render, 'lms_link': get_lms_link_for_item(course_item.location), + 'pages_and_resources_mfe_link': get_pages_and_resources_url(course_item), }) else: return HttpResponseNotFound() diff --git a/cms/djangoapps/contentstore/views/tests/test_tabs.py b/cms/djangoapps/contentstore/views/tests/test_tabs.py index 96ae6a98cf..caeb4cfa2c 100644 --- a/cms/djangoapps/contentstore/views/tests/test_tabs.py +++ b/cms/djangoapps/contentstore/views/tests/test_tabs.py @@ -2,7 +2,10 @@ import json +import ddt +from edx_toggles.toggles.testutils import override_waffle_flag +from cms.djangoapps.contentstore.config.waffle import ENABLE_PAGES_AND_RESOURCES_MICROFRONTEND from cms.djangoapps.contentstore.tests.utils import CourseTestCase from cms.djangoapps.contentstore.utils import reverse_course_url from cms.djangoapps.contentstore.views import tabs @@ -13,6 +16,7 @@ from xmodule.tabs import CourseTabList from xmodule.x_module import STUDENT_VIEW +@ddt.ddt class TabsPageTests(CourseTestCase): """Test cases for Tabs (a.k.a Pages) page""" @@ -71,6 +75,18 @@ class TabsPageTests(CourseTestCase): resp = self.client.get_html(self.url) self.assertContains(resp, 'course-nav-list') + @ddt.data( + # toggle active, assert count + (True, 1), + (False, 0), + ) + @ddt.unpack + def test_pages_and_resources_toggle(self, toggle_active, assert_count): + """Basic check that the Pages page responds correctly""" + with override_waffle_flag(ENABLE_PAGES_AND_RESOURCES_MICROFRONTEND, active=toggle_active): + resp = self.client.get_html(self.url) + self.assertContains(resp, 'View new Pages and Resources Experience', count=assert_count) + def test_reorder_tabs(self): """Test re-ordering of tabs""" diff --git a/cms/templates/edit-tabs.html b/cms/templates/edit-tabs.html index c9e30c3223..34754f7e74 100644 --- a/cms/templates/edit-tabs.html +++ b/cms/templates/edit-tabs.html @@ -43,6 +43,11 @@ + % if pages_and_resources_mfe_link: + + % endif