diff --git a/lms/djangoapps/courseware/tests/test_views.py b/lms/djangoapps/courseware/tests/test_views.py index cde0e8a34ec2..7a5e36e54904 100644 --- a/lms/djangoapps/courseware/tests/test_views.py +++ b/lms/djangoapps/courseware/tests/test_views.py @@ -3814,6 +3814,26 @@ def test_is_mfe_search_waffle_disabled(self): 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): """ diff --git a/lms/djangoapps/courseware/views/views.py b/lms/djangoapps/courseware/views/views.py index 1c57b23d9b11..b182202eddaf 100644 --- a/lms/djangoapps/courseware/views/views.py +++ b/lms/djangoapps/courseware/views/views.py @@ -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)