fix: edxnotes visibility in courseware and courseware API (#33096)
This retrieves user preferences for edxnotes visibility by: 1. Adding a `bind_course_for_student` method to course overview model. 2. Using a bound XBlock in the `toggle_notes.html` template. The previously used unbound course instance was returning a default value.
This commit is contained in:
@@ -1636,6 +1636,7 @@ def render_xblock(request, usage_key_string, check_if_enrolled=True, disable_sta
|
||||
context = {
|
||||
'fragment': fragment,
|
||||
'course': course,
|
||||
'block': block,
|
||||
'disable_accordion': True,
|
||||
'allow_iframing': True,
|
||||
'disable_header': True,
|
||||
|
||||
@@ -100,7 +100,7 @@ ${HTML(fragment.foot_html())}
|
||||
<nav class="nav-utilities ${"has-utility-calculator" if course.show_calculator else ""}" aria-label="${_('Course Utilities')}">
|
||||
## Utility: Notes
|
||||
% if edx_notes_enabled:
|
||||
<%include file="/edxnotes/toggle_notes.html" args="course=course"/>
|
||||
<%include file="/edxnotes/toggle_notes.html" args="course=course, block=block"/>
|
||||
% endif
|
||||
|
||||
## Utility: Calc
|
||||
@@ -111,7 +111,7 @@ ${HTML(fragment.foot_html())}
|
||||
% endif
|
||||
% else:
|
||||
% if edx_notes_enabled:
|
||||
<%include file="/edxnotes/toggle_notes.html" args="course=course"/>
|
||||
<%include file="/edxnotes/toggle_notes.html" args="course=course, block=block"/>
|
||||
% endif
|
||||
% endif
|
||||
|
||||
|
||||
@@ -308,7 +308,7 @@ ${HTML(fragment.foot_html())}
|
||||
<nav class="nav-utilities ${"has-utility-calculator" if course.show_calculator else ""}" aria-label="${_('Course Utilities')}">
|
||||
## Utility: Notes
|
||||
% if is_edxnotes_enabled(course, request.user):
|
||||
<%include file="/edxnotes/toggle_notes.html" args="course=course"/>
|
||||
<%include file="/edxnotes/toggle_notes.html" args="course=course, block=course"/>
|
||||
% endif
|
||||
|
||||
## Utility: Calc
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<%page args="course" expression_filter="h"/>
|
||||
<%page args="course, block" expression_filter="h"/>
|
||||
<%!
|
||||
from django.utils.translation import gettext as _
|
||||
from django.urls import reverse
|
||||
@@ -7,7 +7,7 @@ from openedx.core.djangolib.js_utils import dump_js_escaped_json, js_escaped_str
|
||||
<%namespace name='static' file='/static_content.html'/>
|
||||
|
||||
<%
|
||||
edxnotes_visibility = course.edxnotes_visibility
|
||||
edxnotes_visibility = getattr(block, 'edxnotes_visibility', course.edxnotes_visibility)
|
||||
edxnotes_visibility_url = reverse("edxnotes_visibility", kwargs={"course_id": course.id})
|
||||
if is_learning_mfe is UNDEFINED:
|
||||
hide_ui = False
|
||||
|
||||
@@ -23,6 +23,7 @@ from model_utils.models import TimeStampedModel
|
||||
from opaque_keys.edx.django.models import CourseKeyField, UsageKeyField
|
||||
from simple_history.models import HistoricalRecords
|
||||
|
||||
from lms.djangoapps.courseware.model_data import FieldDataCache
|
||||
from lms.djangoapps.discussion import django_comment_client
|
||||
from openedx.core.djangoapps.catalog.models import CatalogIntegration
|
||||
from openedx.core.djangoapps.lang_pref.api import get_closest_released_language
|
||||
@@ -844,6 +845,23 @@ class CourseOverview(TimeStampedModel):
|
||||
"""
|
||||
return modulestore().get_course(self.id)
|
||||
|
||||
def bind_course_for_student(self, request):
|
||||
"""
|
||||
Bind user-specific field data to the Course XBlock.
|
||||
|
||||
By default, the retrieved course XBlock is "unbound" - it means that any field from the `user_info` scope
|
||||
(like `edxnotes_visibility`) returns its default value.
|
||||
"""
|
||||
# Delay import until here to avoid circular dependency.
|
||||
from lms.djangoapps.courseware.block_render import get_block_for_descriptor
|
||||
get_block_for_descriptor(
|
||||
request.user,
|
||||
request,
|
||||
self._original_course,
|
||||
FieldDataCache([self._original_course], self._original_course.id, request.user),
|
||||
self._original_course.id,
|
||||
)
|
||||
|
||||
@property
|
||||
def allow_public_wiki_access(self):
|
||||
"""
|
||||
|
||||
@@ -89,6 +89,7 @@ class CoursewareMeta:
|
||||
staff_access=original_user_is_staff,
|
||||
)
|
||||
self.request.user = self.effective_user
|
||||
self.overview.bind_course_for_student(self.request)
|
||||
self.enrollment_object = CourseEnrollment.get_enrollment(self.effective_user, self.course_key,
|
||||
select_related=['celebration', 'user__celebration'])
|
||||
|
||||
|
||||
Reference in New Issue
Block a user