Skip to content

Commit

Permalink
feat: add course optimizer waffle flag (#35884)
Browse files Browse the repository at this point in the history
Description
Add a waffle flag to toggle on or off the new Course Optimizer feature per course.

Impact
Course Author

Context
Course Optimizer is a much-requested feature that has been aligned with the OpenEdx community. The only component for now is a broken link checker that will return a list of all broken links in a course to the frontend. There will be a new page for this that is a bit similar to the export page.

This PR only deals with adding a waffle flag.

Supporting information
Internal Ticket (2U):
https://2u-internal.atlassian.net/browse/TNL-11808
  • Loading branch information
jesperhodge authored Nov 20, 2024
1 parent 8f13bdd commit 38e5745
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class CourseWaffleFlagsSerializer(serializers.Serializer):
use_new_certificates_page = serializers.SerializerMethodField()
use_new_textbooks_page = serializers.SerializerMethodField()
use_new_group_configurations_page = serializers.SerializerMethodField()
enable_course_optimizer = serializers.SerializerMethodField()

def get_course_key(self):
"""
Expand Down Expand Up @@ -144,3 +145,10 @@ def get_use_new_group_configurations_page(self, obj):
"""
course_key = self.get_course_key()
return toggles.use_new_group_configurations_page(course_key)

def get_enable_course_optimizer(self, obj):
"""
Method to get the enable_course_optimizer waffle flag
"""
course_key = self.get_course_key()
return toggles.enable_course_optimizer(course_key)
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ class CourseWaffleFlagsViewTest(CourseTestCase):
"use_new_group_configurations_page",
]

other_expected_waffle_flags = ["enable_course_optimizer"]

def setUp(self):
"""
Set up test data and state before each test method.
Expand All @@ -46,6 +48,18 @@ def setUp(self):
super().setUp()
self.url = reverse("cms.djangoapps.contentstore:v1:course_waffle_flags")
self.create_waffle_flags(self.course_waffle_flags)
self.create_custom_waffle_flags()

def create_custom_waffle_flags(self, enabled=True):
"""
Helper method to create waffle flags that are not part of `course_waffle_flags` and have
a different format.
"""
WaffleFlagCourseOverrideModel.objects.create(
waffle_flag="contentstore.enable_course_optimizer",
course_id=self.course.id,
enabled=enabled,
)

def create_waffle_flags(self, flags, enabled=True):
"""
Expand All @@ -72,7 +86,10 @@ def expected_response(self, enabled=False):
Returns:
dict: A dictionary with each flag set to the value of `enabled`.
"""
return {flag: enabled for flag in self.course_waffle_flags}
res = {flag: enabled for flag in self.course_waffle_flags}
for flag in self.other_expected_waffle_flags:
res[flag] = enabled
return res

def test_get_course_waffle_flags_with_course_id(self):
"""
Expand Down
20 changes: 20 additions & 0 deletions cms/djangoapps/contentstore/toggles.py
Original file line number Diff line number Diff line change
Expand Up @@ -667,3 +667,23 @@ def libraries_v2_enabled():
search_api.is_meilisearch_enabled() and
not DISABLE_NEW_LIBRARIES.is_enabled()
)


# .. toggle_name: contentstore.enable_course_optimizer
# .. toggle_implementation: CourseWaffleFlag
# .. toggle_default: False
# .. toggle_description: This flag enables the use of unique anonymous_user_id during studio preview
# .. toggle_use_cases: temporary
# .. toggle_creation_date: 2022-05-04
# .. toggle_target_removal_date: 2022-05-30
# .. toggle_tickets: MST-1455
ENABLE_COURSE_OPTIMIZER = CourseWaffleFlag(
f'{CONTENTSTORE_NAMESPACE}.enable_course_optimizer', __name__
)


def enable_course_optimizer(course_id):
"""
Returns a boolean if individualized anonymous_user_id is enabled on the course
"""
return ENABLE_COURSE_OPTIMIZER.is_enabled(course_id)

0 comments on commit 38e5745

Please sign in to comment.