feat: check course start date for courseware search (#35740)
This commit is contained in:
@@ -3814,6 +3814,26 @@ class TestCoursewareMFESearchAPI(SharedModuleStoreTestCase):
|
||||
self.assertEqual(response.status_code, 200)
|
||||
self.assertEqual(body, {'enabled': False})
|
||||
|
||||
@patch.dict('django.conf.settings.FEATURES', {'COURSEWARE_SEARCH_INCLUSION_DATE': '2020'})
|
||||
@ddt.data(
|
||||
(datetime(2013, 9, 18, 11, 30, 00), False),
|
||||
(None, False),
|
||||
(datetime(2024, 9, 18, 11, 30, 00), True),
|
||||
)
|
||||
@ddt.unpack
|
||||
def test_inclusion_date_greater_than_course_start(self, start_date, expected_enabled):
|
||||
course_with_start = CourseFactory.create(start=start_date)
|
||||
api_url = reverse('courseware_search_enabled_view', kwargs={'course_id': str(course_with_start.id)})
|
||||
|
||||
user_staff = UserFactory(is_staff=True)
|
||||
|
||||
self.client.login(username=user_staff.username, password=TEST_PASSWORD)
|
||||
response = self.client.get(api_url, content_type='application/json')
|
||||
body = json.loads(response.content.decode('utf-8'))
|
||||
|
||||
self.assertEqual(response.status_code, 200)
|
||||
self.assertEqual(body, {'enabled': expected_enabled})
|
||||
|
||||
|
||||
class TestCoursewareMFENavigationSidebarTogglesAPI(SharedModuleStoreTestCase):
|
||||
"""
|
||||
|
||||
@@ -2317,6 +2317,13 @@ def courseware_mfe_search_enabled(request, course_id=None):
|
||||
else:
|
||||
enabled = True
|
||||
|
||||
inclusion_date = settings.FEATURES.get('COURSEWARE_SEARCH_INCLUSION_DATE')
|
||||
start_date = CourseOverview.get_from_id(course_key).start
|
||||
|
||||
# only include courses that have a start date later than the setting-defined inclusion date
|
||||
if inclusion_date:
|
||||
enabled = enabled and (start_date and start_date.strftime('%Y-%m-%d') > inclusion_date)
|
||||
|
||||
payload = {"enabled": courseware_mfe_search_is_enabled(course_key) if enabled else False}
|
||||
return JsonResponse(payload)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user