Exemplo n.º 1
0
 def render_to_fragment(self, request, course=None, tab=None, **kwargs):
     course_id = six.text_type(course.id)
     if course_home_mfe_outline_tab_is_active(course.id) and not request.user.is_staff:
         microfrontend_url = get_microfrontend_url(course_key=course_id, view_name="home")
         raise Redirect(microfrontend_url)
     home_fragment_view = CourseHomeFragmentView()
     return home_fragment_view.render_to_fragment(request, course_id=course_id, **kwargs)
Exemplo n.º 2
0
 def _redirect_to_learning_mfe(self):
     """
     Can the user access this sequence in the courseware MFE? If so, redirect to MFE.
     """
     # If the MFE is active, prefer that
     if courseware_mfe_is_active():
         raise Redirect(self.microfrontend_url)
Exemplo n.º 3
0
 def render_to_fragment(self, request, course=None, tab=None, **kwargs):  # lint-amnesty, pylint: disable=arguments-differ, unused-argument
     course_id = str(course.id)
     if course_home_mfe_is_active(course.id) and not request.user.is_staff:
         microfrontend_url = get_learning_mfe_home_url(course_key=course_id,
                                                       view_name="home")
         raise Redirect(microfrontend_url)
     home_fragment_view = CourseHomeFragmentView()
     return home_fragment_view.render_to_fragment(request,
                                                  course_id=course_id,
                                                  **kwargs)
 def test_redirect_exceptions(self):
     """
     Unit tests for handling of Redirect exceptions.
     """
     request = RequestFactory().get("dummy_url")
     test_url = '/test_url'
     exception = Redirect(test_url)
     response = RedirectMiddleware().process_exception(request, exception)
     self.assertEqual(response.status_code, 302)
     target_url = response._headers['location'][1]
     self.assertTrue(target_url.endswith(test_url))
Exemplo n.º 5
0
 def render_to_fragment(self, request, course=None, tab=None, **kwargs):  # lint-amnesty, pylint: disable=arguments-differ, unused-argument
     course_id = str(course.id)
     if course_home_legacy_is_active(course.id) or request.user.is_staff:
         home_fragment_view = CourseHomeFragmentView()
         return home_fragment_view.render_to_fragment(request,
                                                      course_id=course_id,
                                                      **kwargs)
     microfrontend_url = get_learning_mfe_home_url(course_key=course_id,
                                                   url_fragment='home',
                                                   params=request.GET)
     raise Redirect(microfrontend_url)
Exemplo n.º 6
0
 def test_redirect_exceptions(self):
     """
     Unit tests for handling of Redirect exceptions.
     """
     request = RequestFactory().get("dummy_url")
     test_url = '/test_url'
     exception = Redirect(test_url)
     response = RedirectMiddleware().process_exception(request, exception)
     assert response.status_code == 302
     target_url = response._headers['location'][1]  # lint-amnesty, pylint: disable=protected-access
     assert target_url.endswith(test_url)
Exemplo n.º 7
0
 def test_redirect_exceptions(self):
     """
     Unit tests for handling of Redirect exceptions.
     """
     request = RequestFactory().get("dummy_url")
     test_url = '/test_url'
     exception = Redirect(test_url)
     response = RedirectMiddleware().process_exception(request, exception)
     assert response.status_code == 302
     headers = self.get_headers(response)
     target_url = headers['location'][1]
     assert target_url.endswith(test_url)
Exemplo n.º 8
0
    def _redirect_to_learning_mfe(self):
        """
        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

            raise Redirect(self.microfrontend_url)
Exemplo n.º 9
0
    def _redirect_to_learning_mfe(self):
        """
        Can the user access this sequence in Legacy courseware? If not, redirect to MFE.

        We specifically allow users to stay in the Legacy frontend for special
        (ie timed/proctored) exams since they're not yet supported by the MFE.
        """
        # STAY: if the course run as a whole is visible in the Legacy experience.
        if courseware_legacy_is_visible(
                course_key=self.course_key,
                is_global_staff=self.request.user.is_staff,
        ):
            return
        # STAY: if we are in a special (ie proctored/timed) exam, which isn't yet
        #       supported on the MFE.
        if getattr(self.section, 'is_time_limited', False):
            return
        # REDIRECT otherwise.
        raise Redirect(self.microfrontend_url)
Exemplo n.º 10
0
 def _redirect_to_learning_mfe(self):
     """
     Redirect to the new courseware micro frontend,
     unless this is a time limited exam.
     """
     # 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)