Files
edx-platform/lms/djangoapps/courseware/toggles.py
Vladas Tamoshaitis ec98847c74 feat: Add Waffle flag to enable/disable special exams on MFE learning (#27545)
* feat: Use forked RG version of edx_proctoring in devstack

* Add waffle flag for special exams for mfe (#2371)

* feat: add waffle flag for special exams for mfe

* fix: waffle flag name, add coma to imports

Co-authored-by: Vladas Tamoshaitis <vladas.tamoshaitis@raccoongang.com>

* fix: revert requirements for master branch

* fix: revert dev requirements

* fix: trailing comma after imported item

* feat: add special exams waffle flag test

* fix: use ENABLE_SPECIAL_EXAMS global settings flag

* fix: toggle description

* fix: naming of waffle flag helpers to reflect relation with mfe

* fix(tests): assertion operators order

Co-authored-by: Sagirov Eugeniy <sagirov19@gmail.com>
Co-authored-by: Sagirov Evgeniy <34642612+UvgenGen@users.noreply.github.com>
Co-authored-by: Vladas Tamoshaitis <vladas.tamoshaitis@raccoongang.com>
2021-05-07 08:52:53 -04:00

253 lines
10 KiB
Python

"""
Toggles for courseware in-course experience.
"""
from edx_toggles.toggles import LegacyWaffleFlagNamespace, SettingToggle
from opaque_keys.edx.keys import CourseKey
from openedx.core.djangoapps.waffle_utils import CourseWaffleFlag
# Namespace for courseware waffle flags.
WAFFLE_FLAG_NAMESPACE = LegacyWaffleFlagNamespace(name='courseware')
# .. toggle_name: courseware.courseware_mfe
# .. toggle_implementation: CourseWaffleFlag
# .. toggle_default: False
# .. toggle_description: Waffle flag to redirect to another learner profile experience. 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-01-29
# .. toggle_target_removal_date: 2020-12-31
# .. toggle_warnings: Also set settings.LEARNING_MICROFRONTEND_URL.
# .. toggle_tickets: DEPR-109
REDIRECT_TO_COURSEWARE_MICROFRONTEND = CourseWaffleFlag(
WAFFLE_FLAG_NAMESPACE, 'courseware_mfe', __name__
)
# .. toggle_name: courseware.microfrontend_course_team_preview
# .. toggle_implementation: CourseWaffleFlag
# .. toggle_default: False
# .. toggle_description: Waffle flag to display a link for the new learner experience to course teams without
# redirecting students. Supports staged rollout to course teams of a new micro-frontend-based implementation of the
# courseware page.
# .. toggle_use_cases: temporary, open_edx
# .. toggle_creation_date: 2020-03-09
# .. toggle_target_removal_date: 2020-12-31
# .. toggle_warnings: Also set settings.LEARNING_MICROFRONTEND_URL.
# .. toggle_tickets: DEPR-109
COURSEWARE_MICROFRONTEND_COURSE_TEAM_PREVIEW = CourseWaffleFlag(
WAFFLE_FLAG_NAMESPACE, 'microfrontend_course_team_preview', __name__
)
# 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_warnings: Also set settings.LEARNING_MICROFRONTEND_URL.
# .. toggle_tickets: AA-188
COURSEWARE_MICROFRONTEND_COURSE_EXIT_PAGE = CourseWaffleFlag(
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_warnings: Also set settings.LEARNING_MICROFRONTEND_URL.
# .. toggle_tickets: AA-371
COURSEWARE_MICROFRONTEND_PROGRESS_MILESTONES = CourseWaffleFlag(
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_warnings: Also set settings.LEARNING_MICROFRONTEND_URL and
# COURSEWARE_MICROFRONTEND_PROGRESS_MILESTONES.
# .. toggle_tickets: AA-304
COURSEWARE_MICROFRONTEND_PROGRESS_MILESTONES_STREAK_CELEBRATION = CourseWaffleFlag(
WAFFLE_FLAG_NAMESPACE, 'mfe_progress_milestones_streak_celebration', __name__
)
# .. toggle_name: courseware.proctoring_improvements
# .. toggle_implementation: CourseWaffleFlag
# .. toggle_default: False
# .. toggle_description: Waffle flag to toggle various enhancements to the proctoring experience, including but
# not limited to the display of learner facing proctoring information on the course outline, changes to the
# Proctortrack onboarding flow, changes to IDV (identity verification) requirements, etc.
# .. toggle_use_cases: temporary
# .. toggle_creation_date: 2020-10-07
# .. toggle_target_removal_date: None
# .. toggle_tickets: MST-432
COURSEWARE_PROCTORING_IMPROVEMENTS = CourseWaffleFlag(
WAFFLE_FLAG_NAMESPACE, 'proctoring_improvements', __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(
WAFFLE_FLAG_NAMESPACE, 'optimized_render_xblock', __name__
)
# .. toggle_name: courseware.mfe_special_exams
# .. toggle_implementation: CourseWaffleFlag
# .. toggle_default: False
# .. toggle_description: Waffle flag to enable special exams experience without
# redirecting students to LMS.
# .. toggle_use_cases: temporary
# .. toggle_creation_date: 2021-4-29
# .. toggle_target_removal_date: 2021-6-30
# .. toggle_warnings: None
COURSEWARE_MICROFRONTEND_SPECIAL_EXAMS = CourseWaffleFlag(
WAFFLE_FLAG_NAMESPACE, 'mfe_special_exams', __name__
)
def mfe_special_exams_is_active(course_key: CourseKey) -> bool:
"""
Can we see a course special exams in the Learning MFE?
"""
# DENY: Old Mongo courses don't work in the MFE.
if course_key.deprecated:
return False
# OTHERWISE: Defer to value of waffle flag for this course run and user.
return COURSEWARE_MICROFRONTEND_SPECIAL_EXAMS.is_enabled(course_key)
def courseware_mfe_is_active(course_key: CourseKey) -> bool:
"""
Should we serve the Learning MFE as the canonical courseware experience?
"""
# NO: Old Mongo courses are always served in the Legacy frontend,
# regardless of configuration.
if course_key.deprecated:
return False
# OTHERWISE: Defer to value of waffle flag for this course run and user.
return REDIRECT_TO_COURSEWARE_MICROFRONTEND.is_enabled(course_key)
def courseware_mfe_is_visible(
course_key: CourseKey,
is_global_staff=False,
is_course_staff=False,
) -> bool:
"""
Can we see a course run's content in the Learning MFE?
"""
# DENY: Old Mongo courses don't work in the MFE.
if course_key.deprecated:
return False
# ALLOW: Where techincally possible, global staff may always see the MFE.
if is_global_staff:
return True
# ALLOW: If course team preview is enabled, then course staff may see their
# course in the MFE.
if is_course_staff and COURSEWARE_MICROFRONTEND_COURSE_TEAM_PREVIEW.is_enabled(course_key):
return True
# OTHERWISE: The MFE is only visible if it's the active (ie canonical) experience.
return courseware_mfe_is_active(course_key)
def courseware_mfe_is_advertised(
course_key: CourseKey,
is_global_staff=False,
is_course_staff=False,
) -> bool:
"""
Should we invite the user to view a course run's content in the Learning MFE?
This check is slightly different than `courseware_mfe_is_visible`, in that
we always *permit* global staff to view MFE content (assuming it's deployed),
but we do not shove the New Experience in their face if the preview isn't
enabled.
"""
# DENY: Old Mongo courses don't work in the MFE.
if course_key.deprecated:
return False
# ALLOW: Both global and course staff can see the MFE link if the course team
# preview is enabled.
is_staff = is_global_staff or is_course_staff
if is_staff and COURSEWARE_MICROFRONTEND_COURSE_TEAM_PREVIEW.is_enabled(course_key):
return True
# OTHERWISE: The MFE is only advertised if it's the active (ie canonical) experience.
return courseware_mfe_is_active(course_key)
def courseware_legacy_is_visible(
course_key: CourseKey,
is_global_staff=False,
) -> bool:
"""
Can we see a course run's content in the Legacy frontend?
Note: This function will always return True for Old Mongo courses,
since `courseware_mfe_is_active` will always return False for them.
"""
# ALLOW: Global staff may always see the Legacy experience.
if is_global_staff:
return True
# OTHERWISE: Legacy is only visible if it's the active (ie canonical) experience.
# Note that Old Mongo courses are never the active experience,
# so we effectively always ALLOW them to be viewed in Legacy.
return not courseware_mfe_is_active(course_key)
def course_exit_page_is_active(course_key):
return (
courseware_mfe_is_active(course_key) and
COURSEWARE_MICROFRONTEND_COURSE_EXIT_PAGE.is_enabled(course_key)
)
def courseware_mfe_progress_milestones_are_active(course_key):
return (
courseware_mfe_is_active(course_key) 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)
)
# .. 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
def is_courses_default_invite_only_enabled():
return SettingToggle("COURSES_INVITE_ONLY", default=False).is_enabled()