Skip to content

fix: load user preference for notes visibility in courseware API and toggle_notes.html template #33096

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

Merged
merged 3 commits into from
Sep 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lms/djangoapps/courseware/views/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions lms/templates/courseware/courseware-chromeless.html
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@
<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
Expand All @@ -111,7 +111,7 @@
% 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

Expand Down
2 changes: 1 addition & 1 deletion lms/templates/courseware/courseware.html
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@
<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
Expand Down
4 changes: 2 additions & 2 deletions lms/templates/edxnotes/toggle_notes.html
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -7,7 +7,7 @@
<%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
Expand Down
18 changes: 18 additions & 0 deletions openedx/core/djangoapps/content/course_overviews/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
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
Expand Down Expand Up @@ -844,6 +845,23 @@ def _original_course(self):
"""
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):
"""
Expand Down
1 change: 1 addition & 0 deletions openedx/core/djangoapps/courseware_api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ def __init__(self, course_key, request, username=''):
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'])

Expand Down