From ae41ac446e64981dab547636d4476bdda26b33a0 Mon Sep 17 00:00:00 2001 From: Calen Pennington <cale@edx.org> Date: Tue, 2 Oct 2018 13:47:30 -0400 Subject: [PATCH] Allow AccessResponse messages to appear on the student dashboard --- common/djangoapps/student/tests/test_views.py | 8 +++++--- common/djangoapps/student/views/dashboard.py | 8 ++++---- lms/templates/dashboard.html | 2 +- .../dashboard/_dashboard_course_listing.html | 12 ++++++++++-- themes/edx.org/lms/templates/dashboard.html | 2 +- 5 files changed, 21 insertions(+), 11 deletions(-) diff --git a/common/djangoapps/student/tests/test_views.py b/common/djangoapps/student/tests/test_views.py index ffa5c6b0890..20b00120ee0 100644 --- a/common/djangoapps/student/tests/test_views.py +++ b/common/djangoapps/student/tests/test_views.py @@ -24,6 +24,7 @@ from edx_oauth2_provider.tests.factories import (ClientFactory, TrustedClientFactory) from entitlements.tests.factories import CourseEntitlementFactory from milestones.tests.utils import MilestonesTestCaseMixin +from opaque_keys.edx.keys import CourseKey from openedx.core.djangoapps.catalog.tests.factories import ProgramFactory from openedx.core.djangoapps.content.course_overviews.models import CourseOverview from openedx.core.djangoapps.content.course_overviews.tests.factories import CourseOverviewFactory @@ -377,10 +378,11 @@ class StudentDashboardTests(SharedModuleStoreTestCase, MilestonesTestCaseMixin, program = ProgramFactory() CourseEntitlementFactory.create(user=self.user, course_uuid=program['courses'][0]['uuid']) mock_get_programs.return_value = [program] - mock_course_overview.return_value = CourseOverviewFactory.create(start=self.TOMORROW) + course_key = CourseKey.from_string('course-v1:FAKE+FA1-MA1.X+3T2017') + mock_course_overview.return_value = CourseOverviewFactory.create(start=self.TOMORROW, id=course_key) mock_course_runs.return_value = [ { - 'key': 'course-v1:FAKE+FA1-MA1.X+3T2017', + 'key': unicode(course_key), 'enrollment_end': str(self.TOMORROW), 'pacing_type': 'instructor_paced', 'type': 'verified', @@ -388,7 +390,7 @@ class StudentDashboardTests(SharedModuleStoreTestCase, MilestonesTestCaseMixin, } ] mock_pseudo_session.return_value = { - 'key': 'course-v1:FAKE+FA1-MA1.X+3T2017', + 'key': unicode(course_key), 'type': 'verified' } response = self.client.get(self.path) diff --git a/common/djangoapps/student/views/dashboard.py b/common/djangoapps/student/views/dashboard.py index 44141780402..ab0d3aca4bd 100644 --- a/common/djangoapps/student/views/dashboard.py +++ b/common/djangoapps/student/views/dashboard.py @@ -647,10 +647,10 @@ def student_dashboard(request): staff_access = True errored_courses = modulestore().get_errored_courses() - show_courseware_links_for = frozenset( - enrollment.course_id for enrollment in course_enrollments - if has_access(request.user, 'load', enrollment.course_overview) - ) + show_courseware_links_for = { + enrollment.course_id: has_access(request.user, 'load', enrollment.course_overview) + for enrollment in course_enrollments + } # Find programs associated with course runs being displayed. This information # is passed in the template context to allow rendering of program-related diff --git a/lms/templates/dashboard.html b/lms/templates/dashboard.html index 1fc45e6c1ec..22f5e529d8d 100644 --- a/lms/templates/dashboard.html +++ b/lms/templates/dashboard.html @@ -175,7 +175,7 @@ from student.models import CourseEnrollment show_email_settings = (enrollment.course_id in show_email_settings_for) session_id = enrollment.course_id - show_courseware_link = (session_id in show_courseware_links_for) + show_courseware_link = show_courseware_links_for.get(session_id, False) cert_status = cert_statuses.get(session_id) can_refund_entitlement = entitlement and entitlement.is_entitlement_refundable() can_unenroll = (not cert_status) or cert_status.get('can_unenroll') if not unfulfilled_entitlement else False diff --git a/lms/templates/dashboard/_dashboard_course_listing.html b/lms/templates/dashboard/_dashboard_course_listing.html index 680bd640c93..1b16d0ba339 100644 --- a/lms/templates/dashboard/_dashboard_course_listing.html +++ b/lms/templates/dashboard/_dashboard_course_listing.html @@ -184,8 +184,8 @@ from util.course import get_link_for_about_page, get_encoded_course_sharing_utm_ </span> </a> % elif not is_course_blocked: - <a href="${course_target}" - class="enter-course ${'hidden' if is_unfulfilled_entitlement else ''}" + <a href="${course_target}" + class="enter-course ${'hidden' if is_unfulfilled_entitlement else ''}" data-course-key="${enrollment.course_id}"> ${_('View Course')} <span class="sr"> @@ -202,6 +202,14 @@ from util.course import get_link_for_about_page, get_encoded_course_sharing_utm_ </a> % endif % endif + % elif hasattr(show_courseware_link, 'user_message'): + <span class="enter-course-blocked" + data-course-key="${enrollment.course_id}"> + ${show_courseware_link.user_message} + <span class="sr"> + ${_('for {course_display_name}').format(course_display_name=course_overview.display_name_with_default)} + </span> + </span> % endif % if show_courseware_link or course_overview.has_social_sharing_url() or course_overview.has_marketing_url(): diff --git a/themes/edx.org/lms/templates/dashboard.html b/themes/edx.org/lms/templates/dashboard.html index e05515c7f59..63a54c5a803 100644 --- a/themes/edx.org/lms/templates/dashboard.html +++ b/themes/edx.org/lms/templates/dashboard.html @@ -190,7 +190,7 @@ from student.models import CourseEnrollment show_email_settings = (enrollment.course_id in show_email_settings_for) session_id = enrollment.course_id - show_courseware_link = (session_id in show_courseware_links_for) + show_courseware_link = show_courseware_links_for.get(session_id, False) cert_status = cert_statuses.get(session_id) can_refund_entitlement = entitlement and entitlement.is_entitlement_refundable() can_unenroll = (not cert_status) or cert_status.get('can_unenroll') if not unfulfilled_entitlement else False -- GitLab