AA-234: Switch link in dates widget if Course Home MFE is active
This commit is contained in:
@@ -33,6 +33,7 @@ from lms.djangoapps.courseware.models import (
|
|||||||
OrgDynamicUpgradeDeadlineConfiguration
|
OrgDynamicUpgradeDeadlineConfiguration
|
||||||
)
|
)
|
||||||
from lms.djangoapps.commerce.models import CommerceConfiguration
|
from lms.djangoapps.commerce.models import CommerceConfiguration
|
||||||
|
from lms.djangoapps.course_home_api.toggles import COURSE_HOME_MICROFRONTEND, COURSE_HOME_MICROFRONTEND_DATES_TAB
|
||||||
from lms.djangoapps.verify_student.models import VerificationDeadline
|
from lms.djangoapps.verify_student.models import VerificationDeadline
|
||||||
from lms.djangoapps.verify_student.tests.factories import SoftwareSecurePhotoVerificationFactory
|
from lms.djangoapps.verify_student.tests.factories import SoftwareSecurePhotoVerificationFactory
|
||||||
from openedx.core.djangoapps.content.course_overviews.models import CourseOverview
|
from openedx.core.djangoapps.content.course_overviews.models import CourseOverview
|
||||||
@@ -60,6 +61,7 @@ class CourseDateSummaryTest(SharedModuleStoreTestCase):
|
|||||||
SelfPacedConfiguration.objects.create(enable_course_home_improvements=True)
|
SelfPacedConfiguration.objects.create(enable_course_home_improvements=True)
|
||||||
|
|
||||||
def make_request(self, user):
|
def make_request(self, user):
|
||||||
|
""" Creates a request """
|
||||||
request = RequestFactory().request()
|
request = RequestFactory().request()
|
||||||
request.user = user
|
request.user = user
|
||||||
self.addCleanup(crum.set_current_request, None)
|
self.addCleanup(crum.set_current_request, None)
|
||||||
@@ -658,22 +660,36 @@ class CourseDateSummaryTest(SharedModuleStoreTestCase):
|
|||||||
self.assertEqual(block.relative_datestring, expected_date_string)
|
self.assertEqual(block.relative_datestring, expected_date_string)
|
||||||
|
|
||||||
@ddt.data(
|
@ddt.data(
|
||||||
'info',
|
('info', True),
|
||||||
'openedx.course_experience.course_home',
|
('info', False),
|
||||||
|
('openedx.course_experience.course_home', True),
|
||||||
|
('openedx.course_experience.course_home', False),
|
||||||
)
|
)
|
||||||
|
@ddt.unpack
|
||||||
@override_waffle_flag(UNIFIED_COURSE_TAB_FLAG, active=True)
|
@override_waffle_flag(UNIFIED_COURSE_TAB_FLAG, active=True)
|
||||||
def test_dates_tab_link_render(self, url_name):
|
@RELATIVE_DATES_FLAG.override(active=True)
|
||||||
|
def test_dates_tab_link_render(self, url_name, mfe_active):
|
||||||
""" The dates tab link should only show for enrolled or staff users """
|
""" The dates tab link should only show for enrolled or staff users """
|
||||||
course = create_course_run()
|
course = create_course_run()
|
||||||
html_elements = [
|
html_elements = [
|
||||||
'class="dates-tab-link"',
|
'class="dates-tab-link"',
|
||||||
'View all course dates</a>',
|
'View all course dates</a>',
|
||||||
]
|
]
|
||||||
|
# The url should change based on the mfe being active.
|
||||||
|
if mfe_active:
|
||||||
|
html_elements.append('/course/' + str(course.id) + '/dates')
|
||||||
|
else:
|
||||||
|
html_elements.append('/courses/' + str(course.id) + '/dates')
|
||||||
url = reverse(url_name, args=(course.id,))
|
url = reverse(url_name, args=(course.id,))
|
||||||
|
|
||||||
def assert_html_elements(assert_function, user):
|
def assert_html_elements(assert_function, user):
|
||||||
self.client.login(username=user.username, password=TEST_PASSWORD)
|
self.client.login(username=user.username, password=TEST_PASSWORD)
|
||||||
response = self.client.get(url, follow=True)
|
if mfe_active:
|
||||||
|
with COURSE_HOME_MICROFRONTEND.override(active=True), \
|
||||||
|
COURSE_HOME_MICROFRONTEND_DATES_TAB.override(active=True):
|
||||||
|
response = self.client.get(url, follow=True)
|
||||||
|
else:
|
||||||
|
response = self.client.get(url, follow=True)
|
||||||
for html in html_elements:
|
for html in html_elements:
|
||||||
assert_function(response, html)
|
assert_function(response, html)
|
||||||
self.client.logout()
|
self.client.logout()
|
||||||
@@ -809,6 +825,7 @@ class TestDateAlerts(SharedModuleStoreTestCase):
|
|||||||
|
|
||||||
@ddt.ddt
|
@ddt.ddt
|
||||||
class TestScheduleOverrides(SharedModuleStoreTestCase):
|
class TestScheduleOverrides(SharedModuleStoreTestCase):
|
||||||
|
""" Tests for Schedule Overrides """
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(TestScheduleOverrides, self).setUp()
|
super(TestScheduleOverrides, self).setUp()
|
||||||
@@ -833,6 +850,7 @@ class TestScheduleOverrides(SharedModuleStoreTestCase):
|
|||||||
self._check_text(block)
|
self._check_text(block)
|
||||||
|
|
||||||
def _check_text(self, upgrade_date_summary):
|
def _check_text(self, upgrade_date_summary):
|
||||||
|
""" Validates the text on an upgrade_date_summary """
|
||||||
self.assertEqual(upgrade_date_summary.title, 'Upgrade to Verified Certificate')
|
self.assertEqual(upgrade_date_summary.title, 'Upgrade to Verified Certificate')
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
upgrade_date_summary.description,
|
upgrade_date_summary.description,
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ from django.utils.translation import ugettext as _
|
|||||||
% for course_date_block in course_date_blocks:
|
% for course_date_block in course_date_blocks:
|
||||||
<%include file="dates-summary.html" args="course_date=course_date_block" />
|
<%include file="dates-summary.html" args="course_date=course_date_block" />
|
||||||
% endfor
|
% endfor
|
||||||
% if user_enrolled:
|
% if dates_tab_enabled:
|
||||||
<div class="dates-tab-link">
|
<div class="dates-tab-link">
|
||||||
<a href="${dates_tab_link}">View all course dates</a>
|
<a href="${dates_tab_link}">View all course dates</a>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -12,6 +12,9 @@ from web_fragments.fragment import Fragment
|
|||||||
|
|
||||||
from lms.djangoapps.courseware.access import has_access
|
from lms.djangoapps.courseware.access import has_access
|
||||||
from lms.djangoapps.courseware.courses import get_course_date_blocks, get_course_with_access
|
from lms.djangoapps.courseware.courses import get_course_date_blocks, get_course_with_access
|
||||||
|
from lms.djangoapps.courseware.tabs import DatesTab
|
||||||
|
from lms.djangoapps.course_home_api.toggles import course_home_mfe_dates_tab_is_active
|
||||||
|
from lms.djangoapps.course_home_api.utils import get_microfrontend_url
|
||||||
from openedx.core.djangoapps.plugin_api.views import EdxFragmentView
|
from openedx.core.djangoapps.plugin_api.views import EdxFragmentView
|
||||||
from student.models import CourseEnrollment
|
from student.models import CourseEnrollment
|
||||||
|
|
||||||
@@ -29,16 +32,17 @@ class CourseDatesFragmentView(EdxFragmentView):
|
|||||||
course_key = CourseKey.from_string(course_id)
|
course_key = CourseKey.from_string(course_id)
|
||||||
course = get_course_with_access(request.user, 'load', course_key, check_if_enrolled=False)
|
course = get_course_with_access(request.user, 'load', course_key, check_if_enrolled=False)
|
||||||
course_date_blocks = get_course_date_blocks(course, request.user, request, num_assignments=1)
|
course_date_blocks = get_course_date_blocks(course, request.user, request, num_assignments=1)
|
||||||
# We will use this boolean to gate if we show a link to the dates tab. This same logic
|
|
||||||
# dictates if we show the tab at all.
|
dates_tab_enabled = DatesTab.is_enabled(course, request.user)
|
||||||
user_enrolled = (request.user and request.user.is_authenticated and
|
if course_home_mfe_dates_tab_is_active(course_key):
|
||||||
(bool(CourseEnrollment.is_enrolled(request.user, course.id) or
|
dates_tab_link = get_microfrontend_url(course_key=course.id, view_name='dates')
|
||||||
has_access(request.user, 'staff', course, course.id))))
|
else:
|
||||||
|
dates_tab_link = reverse('dates', args=[course.id])
|
||||||
|
|
||||||
context = {
|
context = {
|
||||||
'course_date_blocks': [block for block in course_date_blocks if block.title != 'current_datetime'],
|
'course_date_blocks': [block for block in course_date_blocks if block.title != 'current_datetime'],
|
||||||
'dates_tab_link': reverse('dates', args=[course.id]),
|
'dates_tab_link': dates_tab_link,
|
||||||
'user_enrolled': user_enrolled,
|
'dates_tab_enabled': dates_tab_enabled,
|
||||||
}
|
}
|
||||||
html = render_to_string(self.template_name, context)
|
html = render_to_string(self.template_name, context)
|
||||||
dates_fragment = Fragment(html)
|
dates_fragment = Fragment(html)
|
||||||
|
|||||||
Reference in New Issue
Block a user