Skip to content

Commit

Permalink
feat: check course start date for courseware search (#35740)
Browse files Browse the repository at this point in the history
  • Loading branch information
alangsto authored Oct 30, 2024
1 parent d5a7689 commit 338a0a1
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
20 changes: 20 additions & 0 deletions lms/djangoapps/courseware/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand Down
7 changes: 7 additions & 0 deletions lms/djangoapps/courseware/views/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit 338a0a1

Please sign in to comment.