-
Notifications
You must be signed in to change notification settings - Fork 196
/
Copy pathconfig_mixin.py
198 lines (174 loc) · 7.77 KB
/
config_mixin.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
"""
Mixin for determining configuration and feature-toggle state relevant to an ORA block.
"""
from django.conf import settings
from django.utils.functional import cached_property
from edx_toggles.toggles import WaffleSwitch
from openassessment.runtime_imports.classes import import_course_waffle_flag, import_waffle_flag
WAFFLE_NAMESPACE = 'openresponseassessment'
ALL_FILES_URLS = 'all_files_urls'
TEAM_SUBMISSIONS = 'team_submissions'
USER_STATE_UPLOAD_DATA = 'user_state_upload_data'
RUBRIC_REUSE = 'rubric_reuse'
ENHANCED_STAFF_GRADER = 'enhanced_staff_grader'
MFE_VIEWS = 'mfe_views'
SELECTABLE_LEARNER_WAITING_REVIEW = 'selectable_learner_waiting_review'
ENABLE_PEER_CONFIGURABLE_GRADING = 'peer_configurable_grading'
FEATURE_TOGGLES_BY_FLAG_NAME = {
ALL_FILES_URLS: 'ENABLE_ORA_ALL_FILE_URLS',
MFE_VIEWS: 'ENABLE_ORA_MFE_VIEWS',
TEAM_SUBMISSIONS: 'ENABLE_ORA_TEAM_SUBMISSIONS',
USER_STATE_UPLOAD_DATA: 'ENABLE_ORA_USER_STATE_UPLOAD_DATA',
RUBRIC_REUSE: 'ENABLE_ORA_RUBRIC_REUSE',
ENHANCED_STAFF_GRADER: 'ENABLE_ENHANCED_STAFF_GRADER',
SELECTABLE_LEARNER_WAITING_REVIEW: 'ENABLE_ORA_SELECTABLE_LEARNER_WAITING_REVIEW',
ENABLE_PEER_CONFIGURABLE_GRADING: 'ENABLE_ORA_PEER_CONFIGURABLE_GRADING',
}
class ConfigMixin:
"""
Mixin class for determining configuration and feature-toggle state relevant to an ORA block.
"""
@staticmethod
def _waffle_switch(switch_name):
"""
Returns a ``WaffleSwitch`` object in WAFFLE_NAMESPACE
with the given ``switch_name``.
"""
# pylint: disable=toggle-missing-annotation
return WaffleSwitch(f"{WAFFLE_NAMESPACE}.{switch_name}", module_name=__name__)
@staticmethod
def _course_waffle_flag(flag_name):
"""
Returns a ``CourseWaffleFlag`` object in WAFFLE_NAMESPACE
with the given ``flag_name``.
"""
CourseWaffleFlag = import_course_waffle_flag() # pylint: disable=invalid-name
# pylint: disable=toggle-missing-annotation
return CourseWaffleFlag(f"{WAFFLE_NAMESPACE}.{flag_name}", module_name=__name__)
@staticmethod
def _waffle_flag(flag_name):
"""
Return a ``WaffleFlag`` object in WAFFLE_NAMESPACE
with the given ``flag_name``.
"""
WaffleFlag = import_waffle_flag() # pylint: disable=invalid-name
# pylint: disable=toggle-missing-annotation
return WaffleFlag(f"{WAFFLE_NAMESPACE}.{flag_name}", module_name=__name__)
@staticmethod
def _settings_toggle_enabled(toggle_name):
"""
Returns True iff ``toggle_name`` is defined and set to ``True``
in Django settings ``FEATURES`` dict.
"""
if not toggle_name:
return False
toggle_state = settings.FEATURES.get(toggle_name)
# If the feature toggle is not defined in settings, this will return False
return toggle_state is True
def is_feature_enabled(self, flag):
"""
Returns True if a CourseWaffleFlag, WaffleSwitch, or Django settings ``FEATURE``
is enabled for this block, False otherwise.
"""
if hasattr(self, 'location') and self._course_waffle_flag(flag).is_enabled(self.location.course_key):
return True
if self._waffle_switch(flag).is_enabled():
return True
if self._waffle_flag(flag).is_enabled():
return True
if self._settings_toggle_enabled(FEATURE_TOGGLES_BY_FLAG_NAME.get(flag)):
return True
return False
@cached_property
def mfe_views_enabled(self):
"""
Returns a boolean specifying if mfe views are enabled.
"""
return self.is_feature_enabled(MFE_VIEWS)
@cached_property
def team_submissions_enabled(self):
"""
Returns a boolean specifying if the team submission is enabled.
"""
return self.is_feature_enabled(TEAM_SUBMISSIONS)
@cached_property
def user_state_upload_data_enabled(self):
"""
Returns a boolean indicating the user state upload data flag is enabled or not.
"""
return self.is_feature_enabled(USER_STATE_UPLOAD_DATA)
@cached_property
def is_fetch_all_urls_waffle_enabled(self):
"""
Returns a boolean indicating the all files urls feature flag is enabled or not.
"""
return self.is_feature_enabled(ALL_FILES_URLS)
@cached_property
def is_mobile_support_enabled(self):
"""
Returns a boolean indicating if the mobile support feature flag is enabled or not.
"""
# .. toggle_name: FEATURES['ENABLE_ORA_MOBILE_SUPPORT']
# .. toggle_implementation: SettingToggle
# .. toggle_default: False
# .. toggle_description: Set to True to enable the ORA2 Xblock to be rendered
# in mobile apps.
# .. toggle_use_cases: open_edx
# .. toggle_creation_date: 2020-10-14
# .. toggle_tickets: https://github.com/openedx/edx-ora2/pull/1445
return settings.FEATURES.get('ENABLE_ORA_MOBILE_SUPPORT', False)
@cached_property
def is_rubric_reuse_enabled(self):
"""
Return a boolean indicating the reuse of rubric feature is enabled or not.
"""
# pylint: disable=toggle-missing-target-removal-date
# .. toggle_name: FEATURES['ENABLE_ORA_RUBRIC_REUSE']
# .. toggle_implementation: WaffleFlag
# .. toggle_default: False
# .. toggle_description: Set to True to enable the reuse of rubric feature
# .. toggle_use_cases: temporary
# .. toggle_creation_date: 2021-05-18
# .. toggle_tickets: https://openedx.atlassian.net/browse/EDUCATOR-5751
return self.is_feature_enabled(RUBRIC_REUSE)
@cached_property
def is_enhanced_staff_grader_enabled(self):
"""
Return a boolean indicating the enhanced staff grader feature is enabled or not.
"""
# .. toggle_name: FEATURES['ENABLE_ENHANCED_STAFF_GRADER']
# .. toggle_implementation: WaffleFlag
# .. toggle_default: False
# .. toggle_description: Set to True to enable the enhanced staff grader feature
# .. toggle_use_cases: circuit_breaker
# .. toggle_creation_date: 2021-08-29
# .. toggle_tickets: https://openedx.atlassian.net/browse/AU-50
return self.is_feature_enabled(ENHANCED_STAFF_GRADER)
@cached_property
def is_selectable_learner_waiting_review_enabled(self):
"""
Return a boolean indicating the selectable learner waiting review is enabled or not.
"""
# .. toggle_name: FEATURES['ENABLE_ORA_SELECTABLE_LEARNER_WAITING_REVIEW']
# .. toggle_implementation: SettingToggle
# .. toggle_default: False
# .. toggle_description: Enable selectable learner in the waiting step list ORA2.
# When enabled, it shows a checkbox to select a learner, and when a learner is chosen,
# it shows a review button to see the details of a submission.
# .. toggle_use_cases: open_edx
# .. toggle_creation_date: 2024-02-09
# .. toggle_tickets: https://github.com/openedx/edx-ora2/pull/2025
return self.is_feature_enabled(SELECTABLE_LEARNER_WAITING_REVIEW)
@cached_property
def enable_peer_configurable_grading(self):
"""
Return a boolean indicating the peer configurable grading feature is enabled or not.
"""
# .. toggle_name: FEATURES['ENABLE_ORA_PEER_CONFIGURABLE_GRADING']
# .. toggle_implementation: SettingToggle
# .. toggle_default: False
# .. toggle_description: Enable configurable grading for peer review.
# .. toggle_use_cases: open_edx
# .. toggle_creation_date: 2024-03-25
# .. toggle_tickets: https://github.com/openedx/edx-ora2/pull/2196
return self.is_feature_enabled(ENABLE_PEER_CONFIGURABLE_GRADING)