refactor!: switch from LegacyWaffle* to modern waffles (#30330)

This is a first stage for removing the LegacyWaffle* classes.

LegacyWaffleFlag usage replaced with WaffleFlag;
LegacyWaffleSwitche usage replaced with WaffleSwitch;
New CourseWaffleFlag added to the temporary module __future__ as FutureCourseWaffleFlag;
Updated all the imports to use CourseWaffleFlag from the __future__ module;

BREAKING CHANGE: A number of toggle related constants (e.g. ENABLE_ACCESSIBILITY_POLICY_PAGE)
changed types. They were strings, and are now toggle instances (e.g. WaffleSwitch). Although the entire
refactor should be self-contained in edx-platform, if any plugins or dependencies were directly
using these constants, they will break. If this is the case, try to find a better publicized way of
exposing those toggles.
This commit is contained in:
Eugene Dyudyunov
2022-05-05 19:03:10 +03:00
committed by GitHub
parent f1bd793cc5
commit 8bd43207ca
60 changed files with 471 additions and 644 deletions

View File

@@ -16,7 +16,7 @@ from django.utils.translation import gettext as _
from django.views.decorators.csrf import ensure_csrf_cookie
from edx_django_utils import monitoring as monitoring_utils
from edx_django_utils.plugins import get_plugins_view_context
from edx_toggles.toggles import LegacyWaffleFlag, LegacyWaffleFlagNamespace
from edx_toggles.toggles import WaffleFlag
from opaque_keys.edx.keys import CourseKey
from pytz import UTC
@@ -61,7 +61,7 @@ from xmodule.modulestore.django import modulestore # lint-amnesty, pylint: disa
log = logging.getLogger("edx.student")
experiments_namespace = LegacyWaffleFlagNamespace(name='student.experiments')
EXPERIMENTS_NAMESPACE = 'student.experiments'
def get_org_black_and_whitelist_for_site():
@@ -652,7 +652,7 @@ def student_dashboard(request): # lint-amnesty, pylint: disable=too-many-statem
inverted_programs = meter.invert_programs()
urls, programs_data = {}, {}
bundles_on_dashboard_flag = LegacyWaffleFlag(experiments_namespace, 'bundles_on_dashboard', __name__) # lint-amnesty, pylint: disable=toggle-missing-annotation
bundles_on_dashboard_flag = WaffleFlag(f'{EXPERIMENTS_NAMESPACE}.bundles_on_dashboard', __name__) # lint-amnesty, pylint: disable=toggle-missing-annotation
# TODO: Delete this code and the relevant HTML code after testing LEARNER-3072 is complete
if bundles_on_dashboard_flag.is_enabled() and inverted_programs and list(inverted_programs.items()):

View File

@@ -22,7 +22,7 @@ from xblock.core import XBlock
from xblock.exceptions import NoSuchServiceError
from xblock.fields import Boolean, Integer, List, Scope, String
from edx_toggles.toggles import LegacyWaffleFlag, SettingDictToggle
from edx_toggles.toggles import WaffleFlag, SettingDictToggle
from xmodule.util.xmodule_django import add_webpack_to_fragment
from xmodule.x_module import (
HTMLSnippet,
@@ -58,10 +58,8 @@ class_priority = ['video', 'problem']
# `django.utils.translation.ugettext_noop` because Django cannot be imported in this file
_ = lambda text: text
TIMED_EXAM_GATING_WAFFLE_FLAG = LegacyWaffleFlag( # lint-amnesty, pylint: disable=toggle-missing-annotation
waffle_namespace="xmodule",
flag_name='rev_1377_rollout',
module_name=__name__,
TIMED_EXAM_GATING_WAFFLE_FLAG = WaffleFlag( # lint-amnesty, pylint: disable=toggle-missing-annotation
'xmodule.rev_1377_rollout', __name__
)
# .. toggle_name: FEATURES['SHOW_PROGRESS_BAR']

View File

@@ -31,7 +31,7 @@ from xblock.runtime import KvsFieldData
from common.djangoapps.xblock_django.constants import ATTR_KEY_REQUEST_COUNTRY_CODE
from openedx.core.djangoapps.video_config.models import HLSPlaybackEnabledFlag, CourseYoutubeBlockedFlag
from openedx.core.djangoapps.video_pipeline.config.waffle import DEPRECATE_YOUTUBE, waffle_flags
from openedx.core.djangoapps.video_pipeline.config.waffle import DEPRECATE_YOUTUBE
from openedx.core.lib.cache_utils import request_cached
from openedx.core.lib.license import LicenseMixin
from xmodule.contentstore.content import StaticContent
@@ -198,7 +198,7 @@ class VideoBlock(
# check if youtube has been deprecated and hls as primary playback
# is enabled for this course
return waffle_flags()[DEPRECATE_YOUTUBE].is_enabled(self.location.course_key)
return DEPRECATE_YOUTUBE.is_enabled(self.location.course_key)
def youtube_disabled_for_course(self): # lint-amnesty, pylint: disable=missing-function-docstring
if not self.location.context_key.is_course: