Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: check course start date for courseware search #35740

Merged
merged 2 commits into from
Oct 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we set enabled to False without the inclusion_date value?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If there's no inclusion date, we should just rely on the default behavior in this view, which is why this is separated into a separate conditional.

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
Loading