From 794c6781fad8d290b548392a94f31a2d1b18e86f Mon Sep 17 00:00:00 2001 From: Maria Grimaldi Date: Tue, 12 Mar 2024 11:21:16 -0400 Subject: [PATCH] feat: return navigation disabled as sequence metadata (#34049) Return navigation disabled as sequence metadata when Hide From TOC is enabled, so the student cannot navigate to another sequences in the course outline. https://openedx.atlassian.net/wiki/spaces/OEPM/pages/3853975595/Feature+Enhancement+Proposal+Hide+Sections+from+course+outline --- xmodule/seq_block.py | 11 +++++++++++ xmodule/tests/test_sequence.py | 9 +++++++++ 2 files changed, 20 insertions(+) diff --git a/xmodule/seq_block.py b/xmodule/seq_block.py index 2b9aed2dd732..944c73400ab5 100644 --- a/xmodule/seq_block.py +++ b/xmodule/seq_block.py @@ -376,8 +376,19 @@ def get_metadata(self, view=STUDENT_VIEW, context=None): meta['display_name'] = self.display_name_with_default meta['format'] = getattr(self, 'format', '') meta['is_hidden_after_due'] = is_hidden_after_due + meta['navigation_disabled'] = self.is_sequence_navigation_disabled() return meta + def is_sequence_navigation_disabled(self): + """ + Returns whether the navigation to other sequences is disabled. + + As of today, this is used to disable the navigation to other sequences when the + current sequence is configured as Hide from Table of Contents. But it can be + extended to other use cases in the future. + """ + return getattr(self, "hide_from_toc", False) + @classmethod def verify_current_content_visibility(cls, date, hide_after_date): """ diff --git a/xmodule/tests/test_sequence.py b/xmodule/tests/test_sequence.py index c080be26516d..be773865a717 100644 --- a/xmodule/tests/test_sequence.py +++ b/xmodule/tests/test_sequence.py @@ -443,6 +443,15 @@ def test_get_metadata(self): assert metadata['tag'] == 'sequential' assert metadata['display_name'] == self.sequence_3_1.display_name_with_default + def test_get_metadata_navigation_disabled(self): + """Test that the sequence metadata is returned correctly when navigation is disabled""" + self.sequence_3_1.hide_from_toc = True + metadata = self.sequence_3_1.get_metadata() + assert len(metadata['items']) == 3 + assert metadata['tag'] == 'sequential' + assert metadata['display_name'] == self.sequence_3_1.display_name_with_default + assert metadata['navigation_disabled'] is True + @override_settings(FIELD_OVERRIDE_PROVIDERS=( 'openedx.features.content_type_gating.field_override.ContentTypeGatingFieldOverride', ))