-
Notifications
You must be signed in to change notification settings - Fork 4.2k
feat: content gating navigation API #37534
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
Draft
sundarthapa2u
wants to merge
1
commit into
openedx:master
Choose a base branch
from
edx:sundar/content-gating
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -472,15 +472,28 @@ def get(self, request, *args, **kwargs): | |
| course_blocks = cache.get(cache_key) | ||
|
|
||
| if not course_blocks: | ||
| if getattr(enrollment, 'is_active', False) or bool(staff_access): | ||
| course_blocks = get_course_outline_block_tree(request, course_key_string, request.user) | ||
| elif allow_public_outline or allow_public or user_is_masquerading: | ||
| course_blocks = get_course_outline_block_tree(request, course_key_string, None) | ||
| all_blocks = get_course_outline_block_tree(request, course_key_string, None) | ||
| visible_blocks = get_course_outline_block_tree(request, course_key_string, request.user) | ||
| visible_ids = set() | ||
|
|
||
| def collect_ids(block): | ||
| visible_ids.add(block['id']) | ||
| for child in block.get('children', []): | ||
| collect_ids(child) | ||
|
Comment on lines
+479
to
+482
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This can be made significantly more efficient. This PR changes from traversing the entire course tree twice to traversing four times times. I'm going to challenge you to think about modifying the get or filter steps to preserve the metadata you want. |
||
|
|
||
| collect_ids(visible_blocks) | ||
|
|
||
| def mark_gated(block): | ||
| block['is_gated'] = block['id'] not in visible_ids | ||
| for child in block.get('children', []): | ||
| mark_gated(child) | ||
|
|
||
| mark_gated(all_blocks) | ||
| course_blocks = all_blocks | ||
|
|
||
| if not navigation_sidebar_caching_is_disabled: | ||
| cache.set(cache_key, course_blocks, self.COURSE_BLOCKS_CACHE_TIMEOUT) | ||
|
|
||
| course_blocks = self.filter_inaccessible_blocks(course_blocks, course_key) | ||
| course_blocks = self.mark_complete_recursive(course_blocks) | ||
|
|
||
| context = self.get_serializer_context() | ||
|
|
@@ -491,7 +504,6 @@ def get(self, request, *args, **kwargs): | |
| }) | ||
|
|
||
| serializer = self.get_serializer_class()(course_blocks, context=context) | ||
|
|
||
| return Response(serializer.data) | ||
|
|
||
| def filter_inaccessible_blocks(self, course_blocks, course_key): | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: I would rethink the name
is_gatedas it doesn't have as much intrinsic meaning / it differs from the other teminology we use across the platform. Perhaps something likeis_restrictedoraccess_restrictedwhich is more explicit.