Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: return navigation disabled as sequence metadata #34049

Merged
merged 1 commit into from
Mar 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions xmodule/seq_block.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand Down
9 changes: 9 additions & 0 deletions xmodule/tests/test_sequence.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
))
Expand Down
Loading