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', ))