From 9e31d65afe2c2b96b0eece427986076d22876982 Mon Sep 17 00:00:00 2001 From: stvn Date: Thu, 16 Jul 2020 15:02:12 -0700 Subject: [PATCH] Consolidate MFE redirect logic Its ripe for confusion to have this logic split between two separate methods. This consolidation should make things easier to understand and hopefully, less issue prone. We don't really benefit from having two methods here anyway, as one is _only_ ever called by the other. It's also misleading that the second helper, in `toggles.py`, _also_ checks the FEATURE flag, as well as the waffle flag. --- lms/djangoapps/courseware/toggles.py | 8 -------- lms/djangoapps/courseware/views/index.py | 25 +++++++++++++----------- 2 files changed, 14 insertions(+), 19 deletions(-) diff --git a/lms/djangoapps/courseware/toggles.py b/lms/djangoapps/courseware/toggles.py index 8055b60cfb..c1039ca5dc 100644 --- a/lms/djangoapps/courseware/toggles.py +++ b/lms/djangoapps/courseware/toggles.py @@ -37,11 +37,3 @@ REDIRECT_TO_COURSEWARE_MICROFRONTEND = ExperimentWaffleFlag(WAFFLE_FLAG_NAMESPAC # .. toggle_tickets: TNL-6982 # .. toggle_status: supported COURSEWARE_MICROFRONTEND_COURSE_TEAM_PREVIEW = CourseWaffleFlag(WAFFLE_FLAG_NAMESPACE, 'microfrontend_course_team_preview') - - -def should_redirect_to_courseware_microfrontend(course_key): - return ( - settings.FEATURES.get('ENABLE_COURSEWARE_MICROFRONTEND') and - (not course_key.deprecated) and # Old Mongo courses not supported - REDIRECT_TO_COURSEWARE_MICROFRONTEND.is_enabled(course_key) - ) diff --git a/lms/djangoapps/courseware/views/index.py b/lms/djangoapps/courseware/views/index.py index d13fdd3c9d..5dc879adf0 100644 --- a/lms/djangoapps/courseware/views/index.py +++ b/lms/djangoapps/courseware/views/index.py @@ -74,7 +74,6 @@ from ..permissions import MASQUERADE_AS_STUDENT from ..toggles import ( COURSEWARE_MICROFRONTEND_COURSE_TEAM_PREVIEW, REDIRECT_TO_COURSEWARE_MICROFRONTEND, - should_redirect_to_courseware_microfrontend, ) from ..url_helpers import get_microfrontend_url @@ -186,16 +185,20 @@ class CoursewareIndex(View): Redirect to the new courseware micro frontend, unless this is a time limited exam. """ - # learners should redirect, if the waffle flag is set - if should_redirect_to_courseware_microfrontend(self.course_key): - # but exams should not redirect to the mfe until they're supported - if getattr(self.section, 'is_time_limited', False): - return - - # and staff will not redirect, either - if self.is_staff: - return - + # DENY: feature disabled globally + if not settings.FEATURES.get('ENABLE_COURSEWARE_MICROFRONTEND'): + return + # DENY: staff access + if self.is_staff: + return + # DENY: Old Mongo courses, until removed from platform + if self.course_key.deprecated: + return + # DENY: Timed Exams, until supported + if getattr(self.section, 'is_time_limited', False): + return + # ALLOW: when flag set for course + if REDIRECT_TO_COURSEWARE_MICROFRONTEND.is_enabled(self.course_key): raise Redirect(self.microfrontend_url) @property