Commit 1e92a6c8 by cahrens

Do not show "View in Studio" links for child verticals of verticals.

STUD-1558
parent 4a45719a
...@@ -165,7 +165,7 @@ def add_staff_markup(user, block, view, frag, context): # pylint: disable=unuse ...@@ -165,7 +165,7 @@ def add_staff_markup(user, block, view, frag, context): # pylint: disable=unuse
Does nothing if module is a SequenceModule. Does nothing if module is a SequenceModule.
""" """
# TODO: make this more general, eg use an XModule attribute instead # TODO: make this more general, eg use an XModule attribute instead
if isinstance(block, VerticalModule): if isinstance(block, VerticalModule) and (not context or not context.get('child_of_vertical', False)):
# check that the course is a mongo backed Studio course before doing work # check that the course is a mongo backed Studio course before doing work
is_mongo_course = modulestore().get_modulestore_type(block.course_id) == MONGO_MODULESTORE_TYPE is_mongo_course = modulestore().get_modulestore_type(block.course_id) == MONGO_MODULESTORE_TYPE
is_studio_course = block.course_edit_method == "Studio" is_studio_course = block.course_edit_method == "Studio"
......
...@@ -198,7 +198,7 @@ class SplitTestModule(SplitTestFields, XModule): ...@@ -198,7 +198,7 @@ class SplitTestModule(SplitTestFields, XModule):
conditions for staff. conditions for staff.
""" """
# When rendering a Studio preview, render all of the block's children # When rendering a Studio preview, render all of the block's children
if context and context['runtime_type'] == 'studio': if context and context.get('runtime_type', None) == 'studio':
return self.studio_preview_view(context) return self.studio_preview_view(context)
if self.child is None: if self.child is None:
......
...@@ -3,6 +3,7 @@ from xmodule.x_module import XModule ...@@ -3,6 +3,7 @@ from xmodule.x_module import XModule
from xmodule.seq_module import SequenceDescriptor from xmodule.seq_module import SequenceDescriptor
from xmodule.progress import Progress from xmodule.progress import Progress
from pkg_resources import resource_string from pkg_resources import resource_string
from copy import copy
# HACK: This shouldn't be hard-coded to two types # HACK: This shouldn't be hard-coded to two types
# OBSOLETE: This obsoletes 'type' # OBSOLETE: This obsoletes 'type'
...@@ -20,8 +21,11 @@ class VerticalModule(VerticalFields, XModule): ...@@ -20,8 +21,11 @@ class VerticalModule(VerticalFields, XModule):
fragment = Fragment() fragment = Fragment()
contents = [] contents = []
child_context = {} if not context else copy(context)
child_context['child_of_vertical'] = True
for child in self.get_display_items(): for child in self.get_display_items():
rendered_child = child.render('student_view', context) rendered_child = child.render('student_view', child_context)
fragment.add_frag_resources(rendered_child) fragment.add_frag_resources(rendered_child)
contents.append({ contents.append({
......
...@@ -536,7 +536,7 @@ class ViewInStudioTest(ModuleStoreTestCase): ...@@ -536,7 +536,7 @@ class ViewInStudioTest(ModuleStoreTestCase):
descriptor descriptor
) )
self.module = render.get_module( return render.get_module(
self.staff_user, self.staff_user,
self.request, self.request,
location, location,
...@@ -554,7 +554,14 @@ class ViewInStudioTest(ModuleStoreTestCase): ...@@ -554,7 +554,14 @@ class ViewInStudioTest(ModuleStoreTestCase):
category='vertical', category='vertical',
) )
self._get_module(course.id, descriptor, descriptor.location) child_descriptor = ItemFactory.create(
category='vertical',
parent_location = descriptor.location
)
self.module = self._get_module(course.id, descriptor, descriptor.location)
self.child_module = self._get_module(course.id, child_descriptor, child_descriptor.location)
def setup_xml_course(self): def setup_xml_course(self):
""" """
...@@ -565,7 +572,7 @@ class ViewInStudioTest(ModuleStoreTestCase): ...@@ -565,7 +572,7 @@ class ViewInStudioTest(ModuleStoreTestCase):
location = Location('i4x', 'edX', 'toy', 'chapter', 'Overview') location = Location('i4x', 'edX', 'toy', 'chapter', 'Overview')
descriptor = modulestore().get_instance(course_id, location) descriptor = modulestore().get_instance(course_id, location)
self._get_module(course_id, descriptor, location) self.module = self._get_module(course_id, descriptor, location)
@override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE) @override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE)
...@@ -581,6 +588,18 @@ class MongoViewInStudioTest(ViewInStudioTest): ...@@ -581,6 +588,18 @@ class MongoViewInStudioTest(ViewInStudioTest):
result_fragment = self.module.render('student_view') result_fragment = self.module.render('student_view')
self.assertIn('View Unit in Studio', result_fragment.content) self.assertIn('View Unit in Studio', result_fragment.content)
def test_view_in_studio_link_only_in_top_level_vertical(self):
"""Regular Studio courses should not see 'View in Studio' for child verticals of verticals."""
self.setup_mongo_course()
# Render the parent vertical, then check that there is only a single "View Unit in Studio" link.
result_fragment = self.module.render('student_view')
# The single "View Unit in Studio" link should appear before the first xmodule vertical definition.
parts = result_fragment.content.split('xmodule_VerticalModule')
self.assertEqual(3, len(parts), "Did not find two vertical modules")
self.assertIn('View Unit in Studio', parts[0])
self.assertNotIn('View Unit in Studio', parts[1])
self.assertNotIn('View Unit in Studio', parts[2])
def test_view_in_studio_link_xml_authored(self): def test_view_in_studio_link_xml_authored(self):
"""Courses that change 'course_edit_method' setting can hide 'View in Studio' links.""" """Courses that change 'course_edit_method' setting can hide 'View in Studio' links."""
self.setup_mongo_course(course_edit_method='XML') self.setup_mongo_course(course_edit_method='XML')
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment