Expose access denial reasons inside verticals to the front-end on the course outline

This commit is contained in:
Calen Pennington
2019-10-18 16:09:35 -04:00
parent 1b1d428630
commit 4e6e283495
2 changed files with 18 additions and 1 deletions

View File

@@ -5,6 +5,7 @@
<%namespace name='static' file='../static_content.html'/>
<%!
import json
from datetime import date
from django.utils.translation import ugettext as _
@@ -164,8 +165,9 @@ self_paced = context.get('self_paced', False)
if vertical_is_access_denied:
continue
scored = 'scored' if vertical.get('scored', False) else ''
access_restricted = list(vertical.get('all_denial_reasons', []))
%>
<li class="vertical outline-item focusable ${scored}">
<li class="vertical outline-item focusable ${scored}" data-access-denied="${json.dumps(access_restricted)}">
<a class="outline-item focusable"
% if enable_links:
href="${ vertical['lms_web_url'] }"

View File

@@ -146,6 +146,20 @@ def get_course_outline_block_tree(request, course_id, user=None):
block['scored'] = False
return False
def recurse_mark_auth_denial(block):
"""
Mark this block as 'scored' if any of its descendents are 'scored' (that is, 'has_score' and 'weight' > 0).
"""
own_denial_reason = {block['authorization_denial_reason']} if 'authorization_denial_reason' in block else set()
# Use a list comprehension to force the recursion over all children, rather than just stopping
# at the first child that is scored.
child_denial_reasons = own_denial_reason.union(
*(recurse_mark_auth_denial(child) for child in block.get('children', []))
)
if child_denial_reasons:
block['all_denial_reasons'] = child_denial_reasons
return child_denial_reasons
course_key = CourseKey.from_string(course_id)
course_usage_key = modulestore().make_course_usage_key(course_key)
@@ -188,6 +202,7 @@ def get_course_outline_block_tree(request, course_id, user=None):
if course_outline_root_block:
populate_children(course_outline_root_block, all_blocks['blocks'])
recurse_mark_scored(course_outline_root_block)
recurse_mark_auth_denial(course_outline_root_block)
if user:
set_last_accessed_default(course_outline_root_block)
mark_blocks_completed(