fix: hide sequences & sections when access is restricted in units through cohorts (#33191)

This does two major things:

* Removes subsections from a student's course outline if the
  subsection's units are all restricted to a cohort that the student
  is not a part of (see CohortPartitionGroupsOutlineProcessor).
* Removes sections from the course outline if the user is not allowed
  to see any of its child subsections.
This commit is contained in:
ABBOUD Moncef
2023-09-19 16:05:02 +02:00
committed by GitHub
parent 2d7f8afc2b
commit 9b44065ab0
6 changed files with 310 additions and 3 deletions

View File

@@ -303,9 +303,20 @@ class OutlineTabView(RetrieveAPIView):
)
available_seq_ids = {str(usage_key) for usage_key in user_course_outline.sequences}
available_section_ids = {str(section.usage_key) for section in user_course_outline.sections}
# course_blocks is a reference to the root of the course,
# so we go through the chapters (sections) and keep only those
# which are part of the outline.
course_blocks['children'] = [
chapter_data
for chapter_data in course_blocks.get('children', [])
if chapter_data['id'] in available_section_ids
]
# course_blocks is a reference to the root of the course, so we go
# through the chapters (sections) to look for sequences to remove.
for chapter_data in course_blocks.get('children', []):
for chapter_data in course_blocks['children']:
chapter_data['children'] = [
seq_data
for seq_data in chapter_data['children']