feat: add & expose courseware.use_learning_sequences_api flag (#27993)

Add a Waffle Flag. When enabled, the courseware pages of the
Learning MFE should use the Learning Sequences HTTP API instead
of the Course Blocks HTTP API in order to load course structure
data. We expect that this switchover will lead to performance
improvements and a more comprehensible system.

(We are putting the switchover behind a temporary flag in order to
enable debugging, incremental rollout, and comparison testing.)

The flag is exposed to the MFE via the Course API.
As of this commit, the new flag is not enabled in any environment,
and the MFE does not have any code to act on the flag's value.
So, this commit on its own should have no production impact.

TNL-8330
This commit is contained in:
Kyle McCormick
2021-06-25 11:19:28 -04:00
committed by GitHub
parent e286e1ce28
commit 78f1e2b3bd
4 changed files with 48 additions and 0 deletions

View File

@@ -116,6 +116,7 @@ class CourseInfoSerializer(serializers.Serializer): # pylint: disable=abstract-
verify_identity_url = AbsoluteURLField()
verification_status = serializers.CharField()
linkedin_add_to_profile_url = serializers.URLField()
is_learning_sequences_api_enabled = serializers.BooleanField()
is_mfe_special_exams_enabled = serializers.BooleanField()
is_mfe_proctored_exams_enabled = serializers.BooleanField()
user_needs_integrity_signature = serializers.BooleanField()

View File

@@ -28,6 +28,7 @@ from lms.djangoapps.courseware.toggles import (
COURSEWARE_MICROFRONTEND_PROGRESS_MILESTONES_STREAK_CELEBRATION,
COURSEWARE_MICROFRONTEND_SPECIAL_EXAMS,
COURSEWARE_MICROFRONTEND_PROCTORED_EXAMS,
COURSEWARE_USE_LEARNING_SEQUENCES_API,
)
from lms.djangoapps.experiments.testutils import override_experiment_waffle_flag
from lms.djangoapps.experiments.utils import STREAK_DISCOUNT_EXPERIMENT_FLAG
@@ -294,6 +295,17 @@ class CourseApiTestViews(BaseCoursewareTests, MasqueradeMixin):
else:
assert not response.data['can_load_courseware']['has_access']
@ddt.data(True, False)
def test_is_learning_sequences_api_enabled(self, enable_new_api):
"""
Test that the Courseware API exposes the Learning Sequences API flag.
"""
with override_waffle_flag(COURSEWARE_USE_LEARNING_SEQUENCES_API, active=enable_new_api):
response = self.client.get(self.url)
assert response.status_code == 200
courseware_data = response.json()
assert courseware_data['is_learning_sequences_api_enabled'] is enable_new_api
def test_streak_data_in_response(self):
""" Test that metadata endpoint returns data for the streak celebration """
CourseEnrollment.enroll(self.user, self.course.id, 'audit')

View File

@@ -40,6 +40,7 @@ from lms.djangoapps.courseware.toggles import (
course_exit_page_is_active,
mfe_special_exams_is_active,
mfe_proctored_exams_is_active,
COURSEWARE_USE_LEARNING_SEQUENCES_API,
)
from lms.djangoapps.courseware.views.views import get_cert_data
from lms.djangoapps.grades.api import CourseGradeFactory
@@ -121,6 +122,23 @@ class CoursewareMeta:
is_course_staff=self.original_user_is_staff
)
@property
def is_learning_sequences_api_enabled(self):
"""
Should the Learning Sequences API be used to load course structure data?
Courseware views in frontend-app-learning need to load course structure data
from the backend to display feaures like breadcrumbs, the smart "Next"
button, etc. This has been done so far using the Course Blocks API.
Over the next few weeks (starting 2021-06-25), we will be incrementally
transitioning said views to instead use the Learning Sequences API,
which we expect to be significantly faster. Once the transition is in
progress, this function will surface to frontend-app-learning whether
the old Course Blocks API or Learning Sequences API should be used.
"""
return COURSEWARE_USE_LEARNING_SEQUENCES_API.is_enabled(self.course_key)
@property
def is_mfe_special_exams_enabled(self):
return settings.FEATURES.get('ENABLE_SPECIAL_EXAMS', False) and mfe_special_exams_is_active(self.course_key)