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.
This commit is contained in:
stvn
2020-07-16 15:02:12 -07:00
parent 7f22041fc1
commit 9e31d65afe
2 changed files with 14 additions and 19 deletions

View File

@@ -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)
)

View File

@@ -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