From 15ee684989fbb9609a7682d5e7ad0f20f192924c Mon Sep 17 00:00:00 2001 From: Navin Karkera Date: Mon, 15 Jan 2024 20:26:38 +0530 Subject: [PATCH] feat: include custom relative dates flag info in outline api --- .../contentstore/rest_api/v1/serializers/course_index.py | 1 + .../contentstore/rest_api/v1/views/course_index.py | 2 ++ .../rest_api/v1/views/tests/test_course_index.py | 7 +++++++ 3 files changed, 10 insertions(+) diff --git a/cms/djangoapps/contentstore/rest_api/v1/serializers/course_index.py b/cms/djangoapps/contentstore/rest_api/v1/serializers/course_index.py index d423f7e9dab4..45fb976b73e5 100644 --- a/cms/djangoapps/contentstore/rest_api/v1/serializers/course_index.py +++ b/cms/djangoapps/contentstore/rest_api/v1/serializers/course_index.py @@ -29,3 +29,4 @@ class CourseIndexSerializer(serializers.Serializer): proctoring_errors = ProctoringErrorListSerializer(many=True) reindex_link = serializers.CharField() rerun_notification_id = serializers.IntegerField() + is_custom_relative_dates_active = serializers.BooleanField() diff --git a/cms/djangoapps/contentstore/rest_api/v1/views/course_index.py b/cms/djangoapps/contentstore/rest_api/v1/views/course_index.py index 1ffac5ba6900..2a6fb0f4bcc4 100644 --- a/cms/djangoapps/contentstore/rest_api/v1/views/course_index.py +++ b/cms/djangoapps/contentstore/rest_api/v1/views/course_index.py @@ -7,6 +7,7 @@ from rest_framework.response import Response from rest_framework.views import APIView +from cms.djangoapps.contentstore.config.waffle import CUSTOM_RELATIVE_DATES from cms.djangoapps.contentstore.rest_api.v1.serializers import CourseIndexSerializer from cms.djangoapps.contentstore.utils import get_course_index_context from common.djangoapps.student.auth import has_studio_read_access @@ -92,6 +93,7 @@ def get(self, request: Request, course_id: str): course_index_context.update({ "discussions_incontext_learnmore_url": settings.DISCUSSIONS_INCONTEXT_LEARNMORE_URL, "discussions_incontext_feedback_url": settings.DISCUSSIONS_INCONTEXT_FEEDBACK_URL, + "is_custom_relative_dates_active": CUSTOM_RELATIVE_DATES.is_enabled(course_key), }) serializer = CourseIndexSerializer(course_index_context) diff --git a/cms/djangoapps/contentstore/rest_api/v1/views/tests/test_course_index.py b/cms/djangoapps/contentstore/rest_api/v1/views/tests/test_course_index.py index e65ae8429567..29c61a167675 100644 --- a/cms/djangoapps/contentstore/rest_api/v1/views/tests/test_course_index.py +++ b/cms/djangoapps/contentstore/rest_api/v1/views/tests/test_course_index.py @@ -5,6 +5,9 @@ from django.urls import reverse from rest_framework import status +from edx_toggles.toggles.testutils import override_waffle_flag + +from cms.djangoapps.contentstore.config.waffle import CUSTOM_RELATIVE_DATES from cms.djangoapps.contentstore.rest_api.v1.mixins import PermissionAccessMixin from cms.djangoapps.contentstore.tests.utils import CourseTestCase from cms.djangoapps.contentstore.utils import get_lms_link_for_item @@ -46,6 +49,7 @@ def setUp(self): kwargs={"course_id": self.course.id}, ) + @override_waffle_flag(CUSTOM_RELATIVE_DATES, active=True) def test_course_index_response(self): """Check successful response content""" response = self.client.get(self.url) @@ -59,6 +63,7 @@ def test_course_index_response(self): }, "discussions_incontext_feedback_url": "", "discussions_incontext_learnmore_url": "", + "is_custom_relative_dates_active": True, "initial_state": None, "initial_user_clipboard": { "content": None, @@ -78,6 +83,7 @@ def test_course_index_response(self): self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertDictEqual(expected_response, response.data) + @override_waffle_flag(CUSTOM_RELATIVE_DATES, active=False) def test_course_index_response_with_show_locators(self): """Check successful response content with show query param""" response = self.client.get(self.url, {"show": str(self.unit.location)}) @@ -91,6 +97,7 @@ def test_course_index_response_with_show_locators(self): }, "discussions_incontext_feedback_url": "", "discussions_incontext_learnmore_url": "", + "is_custom_relative_dates_active": False, "initial_state": { "expanded_locators": [ str(self.unit.location),