-
Notifications
You must be signed in to change notification settings - Fork 3.9k
/
toggles.py
221 lines (188 loc) · 9.06 KB
/
toggles.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
"""
Toggles for courseware in-course experience.
"""
from edx_toggles.toggles import SettingToggle, WaffleSwitch
from openedx.core.djangoapps.waffle_utils import CourseWaffleFlag
# Namespace for courseware waffle flags.
WAFFLE_FLAG_NAMESPACE = 'courseware'
# Waffle flag to enable the course exit page in the learning MFE.
#
# .. toggle_name: courseware.microfrontend_course_exit_page
# .. toggle_implementation: CourseWaffleFlag
# .. toggle_default: False
# .. toggle_description: Supports staged rollout of the new micro-frontend-based implementation of the course exit page.
# .. toggle_use_cases: open_edx, temporary
# .. toggle_creation_date: 2020-10-02
# .. toggle_target_removal_date: None
# .. toggle_warning: Also set settings.LEARNING_MICROFRONTEND_URL.
# .. toggle_tickets: AA-188
COURSEWARE_MICROFRONTEND_COURSE_EXIT_PAGE = CourseWaffleFlag(
f'{WAFFLE_FLAG_NAMESPACE}.microfrontend_course_exit_page', __name__
)
# .. toggle_name: courseware.mfe_progress_milestones
# .. toggle_implementation: CourseWaffleFlag
# .. toggle_default: False
# .. toggle_description: Waffle flag to display learner progress milestones in a course. Supports staged
# rollout to students for a new micro-frontend-based implementation of the courseware page.
# .. toggle_use_cases: temporary, open_edx
# .. toggle_creation_date: 2020-10-07
# .. toggle_target_removal_date: none
# .. toggle_warning: Also set settings.LEARNING_MICROFRONTEND_URL.
# .. toggle_tickets: AA-371
COURSEWARE_MICROFRONTEND_PROGRESS_MILESTONES = CourseWaffleFlag(
f'{WAFFLE_FLAG_NAMESPACE}.mfe_progress_milestones', __name__
)
# .. toggle_name: courseware.mfe_progress_milestones_streak_celebration
# .. toggle_implementation: CourseWaffleFlag
# .. toggle_default: False
# .. toggle_description: Waffle flag to display a celebration modal when learner completes a configurable streak
# Supports staged rollout to students for a new micro-frontend-based implementation of the
# courseware page.
# .. toggle_use_cases: temporary, open_edx
# .. toggle_creation_date: 2021-02-16
# .. toggle_target_removal_date: None
# .. toggle_warning: Also set settings.LEARNING_MICROFRONTEND_URL and
# COURSEWARE_MICROFRONTEND_PROGRESS_MILESTONES.
# .. toggle_tickets: AA-304
COURSEWARE_MICROFRONTEND_PROGRESS_MILESTONES_STREAK_CELEBRATION = CourseWaffleFlag(
f'{WAFFLE_FLAG_NAMESPACE}.mfe_progress_milestones_streak_celebration', __name__
)
# .. toggle_name: courseware.mfe_courseware_search
# .. toggle_implementation: WaffleFlag
# .. toggle_default: False
# .. toggle_description: Enables Courseware Search on Learning MFE
# .. toggle_use_cases: temporary
# .. toggle_creation_date: 2023-09-28
# .. toggle_target_removal_date: None
# .. toggle_tickets: KBK-20
# .. toggle_warning: None.
COURSEWARE_MICROFRONTEND_SEARCH_ENABLED = CourseWaffleFlag(
f'{WAFFLE_FLAG_NAMESPACE}.mfe_courseware_search', __name__
)
# .. toggle_name: courseware.disable_navigation_sidebar_blocks_caching
# .. toggle_implementation: WaffleFlag
# .. toggle_default: False
# .. toggle_description: Disable caching of navigation sidebar blocks on Learning MFE.
# It can be used when caching the structure of large courses for a large number of users
# at the same time can overload the cache storage (memcache or redis).
# .. toggle_use_cases: opt_out, open_edx
# .. toggle_creation_date: 2024-03-21
# .. toggle_target_removal_date: None
# .. toggle_tickets: FC-0056
# .. toggle_warning: None.
COURSEWARE_MICROFRONTEND_NAVIGATION_SIDEBAR_BLOCKS_DISABLE_CACHING = CourseWaffleFlag(
f'{WAFFLE_FLAG_NAMESPACE}.disable_navigation_sidebar_blocks_caching', __name__
)
# .. toggle_name: courseware.enable_navigation_sidebar
# .. toggle_implementation: WaffleFlag
# .. toggle_default: False
# .. toggle_description: Enable navigation sidebar on Learning MFE
# .. toggle_use_cases: opt_out, open_edx
# .. toggle_creation_date: 2024-03-07
# .. toggle_target_removal_date: None
# .. toggle_tickets: FC-0056
COURSEWARE_MICROFRONTEND_ENABLE_NAVIGATION_SIDEBAR = CourseWaffleFlag(
f'{WAFFLE_FLAG_NAMESPACE}.enable_navigation_sidebar', __name__
)
# .. toggle_name: courseware.always_open_auxiliary_sidebar
# .. toggle_implementation: WaffleFlag
# .. toggle_default: True
# .. toggle_description: Waffle flag that determines whether the auxiliary sidebar,
# such as discussion or notification, should automatically expand
# on each course unit page within the Learning MFE, without preserving
# the previous state of the sidebar.
# .. toggle_use_cases: temporary
# .. toggle_creation_date: 2024-04-28
# .. toggle_target_removal_date: 2024-07-28
# .. toggle_tickets: FC-0056
COURSEWARE_MICROFRONTEND_ALWAYS_OPEN_AUXILIARY_SIDEBAR = CourseWaffleFlag(
f'{WAFFLE_FLAG_NAMESPACE}.always_open_auxiliary_sidebar', __name__
)
# .. toggle_name: courseware.mfe_progress_milestones_streak_discount_enabled
# .. toggle_implementation: CourseWaffleFlag
# .. toggle_default: False
# .. toggle_description: This flag enables an engagement discount incentive message.
# .. toggle_warning: This flag depends on the streak celebration feature being enabled
# .. toggle_use_cases: opt_out, open_edx
# .. toggle_creation_date: 2021-08-26
# .. toggle_target_removal_date: None
# .. toggle_tickets: https://openedx.atlassian.net/browse/AA-950
COURSEWARE_MFE_MILESTONES_STREAK_DISCOUNT = CourseWaffleFlag(
f'{WAFFLE_FLAG_NAMESPACE}.streak_discount_enabled', __name__
)
# .. toggle_name: courseware.optimized_render_xblock
# .. toggle_implementation: CourseWaffleFlag
# .. toggle_default: False
# .. toggle_description: Waffle flag that determines whether we speed up the render_xblock for browsers by
# removing unnecessary JavaScript and CSS. It is possible that this could introduce edge cases with content
# that relies on these assets, so being a CourseWaffleFlag will give us the flexibility to exempt courses
# from these optimizations.
# .. toggle_use_cases: temporary
# .. toggle_creation_date: 2021-02-09
# .. toggle_target_removal_date: 2021-05-01
COURSEWARE_OPTIMIZED_RENDER_XBLOCK = CourseWaffleFlag(
f'{WAFFLE_FLAG_NAMESPACE}.optimized_render_xblock', __name__
)
# .. toggle_name: COURSES_INVITE_ONLY
# .. toggle_implementation: SettingToggle
# .. toggle_type: feature_flag
# .. toggle_default: False
# .. toggle_description: Setting this sets the default value of INVITE_ONLY across all courses in a given deployment
# .. toggle_category: admin
# .. toggle_use_cases: open_edx
# .. toggle_creation_date: 2019-05-16
# .. toggle_expiration_date: None
# .. toggle_tickets: https://github.com/mitodl/edx-platform/issues/123
# .. toggle_status: unsupported
COURSES_INVITE_ONLY = SettingToggle('COURSES_INVITE_ONLY', default=False)
ENABLE_OPTIMIZELY_IN_COURSEWARE = WaffleSwitch( # lint-amnesty, pylint: disable=toggle-missing-annotation
'RET.enable_optimizely_in_courseware', __name__
)
# .. toggle_name: courseware.discovery_default_language_filter
# .. toggle_implementation: WaffleSwitch
# .. toggle_default: False
# .. toggle_description: Enable courses to be filtered by user language by default.
# .. toggle_use_cases: open_edx
# .. toggle_creation_date: 2023-11-02
# .. toggle_target_removal_date: None
# .. toggle_warning: The ENABLE_COURSE_DISCOVERY feature flag should be enabled.
# .. toggle_tickets: https://github.com/openedx/edx-platform/pull/33647
ENABLE_COURSE_DISCOVERY_DEFAULT_LANGUAGE_FILTER = WaffleSwitch(
f'{WAFFLE_FLAG_NAMESPACE}.discovery_default_language_filter', __name__
)
def courseware_mfe_is_active() -> bool:
"""
Should we serve the Learning MFE as the canonical courseware experience?
"""
from lms.djangoapps.courseware.access_utils import in_preview_mode # avoid a circular import
# We only use legacy views for the Studio "preview mode" feature these days, while everyone else gets the MFE
return not in_preview_mode()
def course_exit_page_is_active(course_key):
return (
courseware_mfe_is_active() and
COURSEWARE_MICROFRONTEND_COURSE_EXIT_PAGE.is_enabled(course_key)
)
def courseware_mfe_progress_milestones_are_active(course_key):
return (
courseware_mfe_is_active() and
COURSEWARE_MICROFRONTEND_PROGRESS_MILESTONES.is_enabled(course_key)
)
def streak_celebration_is_active(course_key):
return (
courseware_mfe_progress_milestones_are_active(course_key) and
COURSEWARE_MICROFRONTEND_PROGRESS_MILESTONES_STREAK_CELEBRATION.is_enabled(course_key)
)
def course_is_invitation_only(courselike) -> bool:
"""Returns whether the course is invitation only or not."""
# We also mark Old Mongo courses (deprecated keys) as invitation only to cut off enrollment
return COURSES_INVITE_ONLY.is_enabled() or courselike.invitation_only or courselike.id.deprecated
def courseware_mfe_search_is_enabled(course_key=None):
"""
Return whether the courseware.mfe_courseware_search flag is on.
"""
return COURSEWARE_MICROFRONTEND_SEARCH_ENABLED.is_enabled(course_key)
def courseware_disable_navigation_sidebar_blocks_caching(course_key=None):
"""
Return whether the courseware.disable_navigation_sidebar_blocks_caching flag is on.
"""
return COURSEWARE_MICROFRONTEND_NAVIGATION_SIDEBAR_BLOCKS_DISABLE_CACHING.is_enabled(course_key)