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: add & expose courseware.use_learning_sequences_api flag #27993

Merged
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
17 changes: 17 additions & 0 deletions lms/djangoapps/courseware/toggles.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,23 @@
WAFFLE_FLAG_NAMESPACE, 'use_legacy_frontend', __name__
)

# .. toggle_name: courseware.use_learning_sequences_api
# .. toggle_implementation: CourseWaffleFlag
# .. toggle_default: False
# .. toggle_description: When enbled, frontend-app-learning's courseware pages should use the
# new Learning Sequences API (from ``openedx.core.djangoapps.content.learning_sequences``)
# instead of the Course Blocks API (from ``lms.djangoapps.course_api.blocks``)
# in order to load course structure data.
# .. toggle_warnings: As of 2021-06-25, the frontend-app-learning changes necessary to honor this
# flag's value have not yet been implemented. We expect that they will be implemented in
# the coming weeks.
# .. toggle_use_cases: temporary
# .. toggle_creation_date: 2021-06-25
# .. toggle_target_removal_date: 2021-09-01
COURSEWARE_USE_LEARNING_SEQUENCES_API = CourseWaffleFlag(
WAFFLE_FLAG_NAMESPACE, 'use_learning_sequences_api', __name__
)

# .. toggle_name: courseware.microfrontend_course_team_preview
# .. toggle_implementation: CourseWaffleFlag
# .. toggle_default: False
Expand Down
1 change: 1 addition & 0 deletions openedx/core/djangoapps/courseware_api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
12 changes: 12 additions & 0 deletions openedx/core/djangoapps/courseware_api/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
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
Expand Down Expand Up @@ -294,6 +295,17 @@ def test_can_load_courseware(
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')
Expand Down
18 changes: 18 additions & 0 deletions openedx/core/djangoapps/courseware_api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
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
Expand Down Expand Up @@ -121,6 +122,23 @@ def is_microfrontend_enabled_for_user(self):
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)
Expand Down