Skip to content

Commit 7da9984

Browse files
authored
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.
1 parent 6e2c43e commit 7da9984

File tree

6 files changed

+25
-5
lines changed

6 files changed

+25
-5
lines changed

lms/djangoapps/courseware/views/views.py

+1
Original file line numberDiff line numberDiff line change
@@ -1636,6 +1636,7 @@ def render_xblock(request, usage_key_string, check_if_enrolled=True, disable_sta
16361636
context = {
16371637
'fragment': fragment,
16381638
'course': course,
1639+
'block': block,
16391640
'disable_accordion': True,
16401641
'allow_iframing': True,
16411642
'disable_header': True,

lms/templates/courseware/courseware-chromeless.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@
100100
<nav class="nav-utilities ${"has-utility-calculator" if course.show_calculator else ""}" aria-label="${_('Course Utilities')}">
101101
## Utility: Notes
102102
% if edx_notes_enabled:
103-
<%include file="/edxnotes/toggle_notes.html" args="course=course"/>
103+
<%include file="/edxnotes/toggle_notes.html" args="course=course, block=block"/>
104104
% endif
105105

106106
## Utility: Calc
@@ -111,7 +111,7 @@
111111
% endif
112112
% else:
113113
% if edx_notes_enabled:
114-
<%include file="/edxnotes/toggle_notes.html" args="course=course"/>
114+
<%include file="/edxnotes/toggle_notes.html" args="course=course, block=block"/>
115115
% endif
116116
% endif
117117

lms/templates/courseware/courseware.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@
308308
<nav class="nav-utilities ${"has-utility-calculator" if course.show_calculator else ""}" aria-label="${_('Course Utilities')}">
309309
## Utility: Notes
310310
% if is_edxnotes_enabled(course, request.user):
311-
<%include file="/edxnotes/toggle_notes.html" args="course=course"/>
311+
<%include file="/edxnotes/toggle_notes.html" args="course=course, block=course"/>
312312
% endif
313313

314314
## Utility: Calc

lms/templates/edxnotes/toggle_notes.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<%page args="course" expression_filter="h"/>
1+
<%page args="course, block" expression_filter="h"/>
22
<%!
33
from django.utils.translation import gettext as _
44
from django.urls import reverse
@@ -7,7 +7,7 @@
77
<%namespace name='static' file='/static_content.html'/>
88

99
<%
10-
edxnotes_visibility = course.edxnotes_visibility
10+
edxnotes_visibility = getattr(block, 'edxnotes_visibility', course.edxnotes_visibility)
1111
edxnotes_visibility_url = reverse("edxnotes_visibility", kwargs={"course_id": course.id})
1212
if is_learning_mfe is UNDEFINED:
1313
hide_ui = False

openedx/core/djangoapps/content/course_overviews/models.py

+18
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
from opaque_keys.edx.django.models import CourseKeyField, UsageKeyField
2424
from simple_history.models import HistoricalRecords
2525

26+
from lms.djangoapps.courseware.model_data import FieldDataCache
2627
from lms.djangoapps.discussion import django_comment_client
2728
from openedx.core.djangoapps.catalog.models import CatalogIntegration
2829
from openedx.core.djangoapps.lang_pref.api import get_closest_released_language
@@ -844,6 +845,23 @@ def _original_course(self):
844845
"""
845846
return modulestore().get_course(self.id)
846847

848+
def bind_course_for_student(self, request):
849+
"""
850+
Bind user-specific field data to the Course XBlock.
851+
852+
By default, the retrieved course XBlock is "unbound" - it means that any field from the `user_info` scope
853+
(like `edxnotes_visibility`) returns its default value.
854+
"""
855+
# Delay import until here to avoid circular dependency.
856+
from lms.djangoapps.courseware.block_render import get_block_for_descriptor
857+
get_block_for_descriptor(
858+
request.user,
859+
request,
860+
self._original_course,
861+
FieldDataCache([self._original_course], self._original_course.id, request.user),
862+
self._original_course.id,
863+
)
864+
847865
@property
848866
def allow_public_wiki_access(self):
849867
"""

openedx/core/djangoapps/courseware_api/views.py

+1
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ def __init__(self, course_key, request, username=''):
8989
staff_access=original_user_is_staff,
9090
)
9191
self.request.user = self.effective_user
92+
self.overview.bind_course_for_student(self.request)
9293
self.enrollment_object = CourseEnrollment.get_enrollment(self.effective_user, self.course_key,
9394
select_related=['celebration', 'user__celebration'])
9495

0 commit comments

Comments
 (0)