From 585c64f282a6a07c1012d726df1b7ce5f40e49b9 Mon Sep 17 00:00:00 2001 From: Matjaz Gregoric Date: Thu, 17 Dec 2015 10:01:57 +0100 Subject: [PATCH] Enable staff debug everywhere except on detached blocks. Staff markup was enabled on all block types in https://github.com/edx/edx-platform/pull/10903 This works well inside the courseware, but it breaks layout of the course about page, which is also an XModule, see: https://github.com/edx/edx-platform/pull/10903#issuecomment-164266342 This commit disables staff markup/staff debug on all blocks except blocks tagged with 'detached'. Detached blocks include course about and info pages, static tabs. --- .../courseware/tests/test_module_render.py | 35 +++++++++++++++++++ lms/templates/staff_problem_info.html | 2 +- openedx/core/lib/xblock_utils.py | 1 + 3 files changed, 37 insertions(+), 1 deletion(-) diff --git a/lms/djangoapps/courseware/tests/test_module_render.py b/lms/djangoapps/courseware/tests/test_module_render.py index cb49c0acb4..baadc137b8 100644 --- a/lms/djangoapps/courseware/tests/test_module_render.py +++ b/lms/djangoapps/courseware/tests/test_module_render.py @@ -1349,6 +1349,19 @@ class XmlViewInStudioTest(ViewInStudioTest): self.assertNotIn('View Unit in Studio', result_fragment.content) +@XBlock.tag("detached") +class DetachedXBlock(XBlock): + """ + XBlock marked with the 'detached' flag. + """ + def student_view(self, context=None): # pylint: disable=unused-argument + """ + A simple view that returns just enough to test. + """ + frag = Fragment(u"Hello there!") + return frag + + @attr('shard_1') @patch.dict('django.conf.settings.FEATURES', {'DISPLAY_DEBUG_INFO_TO_STAFF': True, 'DISPLAY_HISTOGRAMS_TO_STAFF': True}) @patch('courseware.module_render.has_access', Mock(return_value=True, autospec=True)) @@ -1404,6 +1417,28 @@ class TestStaffDebugInfo(ModuleStoreTestCase): result_fragment = module.render(STUDENT_VIEW) self.assertIn('Staff Debug', result_fragment.content) + @XBlock.register_temp_plugin(DetachedXBlock, identifier='detached-block') + def test_staff_debug_info_disabled_for_detached_blocks(self): + """Staff markup should not be present on detached blocks.""" + + descriptor = ItemFactory.create( + category='detached-block', + display_name='Detached Block' + ) + field_data_cache = FieldDataCache.cache_for_descriptor_descendents( + self.course.id, + self.user, + descriptor + ) + module = render.get_module( + self.user, + self.request, + descriptor.location, + field_data_cache, + ) + result_fragment = module.render(STUDENT_VIEW) + self.assertNotIn('Staff Debug', result_fragment.content) + @patch.dict('django.conf.settings.FEATURES', {'DISPLAY_HISTOGRAMS_TO_STAFF': False}) def test_histogram_disabled(self): module = render.get_module( diff --git a/lms/templates/staff_problem_info.html b/lms/templates/staff_problem_info.html index 9a7252584e..7117d8621c 100644 --- a/lms/templates/staff_problem_info.html +++ b/lms/templates/staff_problem_info.html @@ -6,7 +6,7 @@ from django.template.defaultfilters import escapejs ## The JS for this is defined in xqa_interface.html ${block_content} -%if location.category in ['problem','video','html','combinedopenended','library_content']: +%if 'detached' not in tags: % if edit_link:
Edit diff --git a/openedx/core/lib/xblock_utils.py b/openedx/core/lib/xblock_utils.py index 08a9b0eed4..72f55bb81b 100644 --- a/openedx/core/lib/xblock_utils.py +++ b/openedx/core/lib/xblock_utils.py @@ -293,6 +293,7 @@ def add_staff_markup(user, has_instructor_access, disable_staff_debug_info, bloc staff_context = { 'fields': field_contents, 'xml_attributes': getattr(block, 'xml_attributes', {}), + 'tags': block._class_tags, # pylint: disable=protected-access 'location': block.location, 'xqa_key': block.xqa_key, 'source_file': source_file,