diff --git a/lms/envs/common.py b/lms/envs/common.py index 334aafa23a55532b35026abea26355256268a5f5..69e129ea56e7849030e503d281c38b609fabe0de 100644 --- a/lms/envs/common.py +++ b/lms/envs/common.py @@ -3452,11 +3452,17 @@ RETIREMENT_STATES = [ 'COMPLETE', ] -############## Settings for Writable Gradebook ######################### +############## Settings for Microfrontends ######################### # If running a Gradebook container locally, # modify lms/envs/private.py to give it a non-null value WRITABLE_GRADEBOOK_URL = None +# TODO (DEPR-17) +# This URL value is needed to redirect the old profile page to a new +# micro-frontend based implementation. Once the old implementation is +# completely removed and this redirect is no longer needed, we can remove this. +PROFILE_MICROFRONTEND_URL = "http://some.profile.spa/u/" + ############### Settings for django-fernet-fields ################## FERNET_KEYS = [ 'DUMMY KEY CHANGE BEFORE GOING TO PRODUCTION', diff --git a/lms/envs/production.py b/lms/envs/production.py index 1bdb8c6a51f8029f838583687d0633c80e47daa6..cc128c0f14e9517af84f95081b71b4e59b010e63 100644 --- a/lms/envs/production.py +++ b/lms/envs/production.py @@ -1102,8 +1102,9 @@ RETIREMENT_STATES = ENV_TOKENS.get('RETIREMENT_STATES', RETIREMENT_STATES) ############## Settings for Course Enrollment Modes ###################### COURSE_ENROLLMENT_MODES = ENV_TOKENS.get('COURSE_ENROLLMENT_MODES', COURSE_ENROLLMENT_MODES) -############## Settings for Writable Gradebook ######################### +############## Settings for Microfrontend URLS ######################### WRITABLE_GRADEBOOK_URL = ENV_TOKENS.get('WRITABLE_GRADEBOOK_URL', WRITABLE_GRADEBOOK_URL) +PROFILE_MICROFRONTEND_URL = ENV_TOKENS.get('PROFILE_MICROFRONTEND_URL', PROFILE_MICROFRONTEND_URL) ############################### Plugin Settings ############################### diff --git a/openedx/features/learner_profile/__init__.py b/openedx/features/learner_profile/__init__.py index 80875eefd0e859ba898acc16262d50b4d8da9941..ea54674b5147eb589ea0d4f1b996ec38dde92f93 100644 --- a/openedx/features/learner_profile/__init__.py +++ b/openedx/features/learner_profile/__init__.py @@ -14,3 +14,6 @@ SHOW_PROFILE_MESSAGE = WaffleFlag(WAFFLE_FLAG_NAMESPACE, 'show_message') # Waffle flag to show achievements on the learner profile. SHOW_ACHIEVEMENTS_FLAG = WaffleFlag(WAFFLE_FLAG_NAMESPACE, 'show_achievements', flag_undefined_default=True) + +# Waffle flag to redirect to another learner profile experience. +REDIRECT_TO_PROFILE_MICROFRONTEND = WaffleFlag(WAFFLE_FLAG_NAMESPACE, 'redirect_to_microfrontend') diff --git a/openedx/features/learner_profile/tests/views/test_learner_profile.py b/openedx/features/learner_profile/tests/views/test_learner_profile.py index 628d55d62cff7dd338cfeb47f9f867db95d80556..faa3dba732c3bd93a3a1c7ca9964924fea9a4f57 100644 --- a/openedx/features/learner_profile/tests/views/test_learner_profile.py +++ b/openedx/features/learner_profile/tests/views/test_learner_profile.py @@ -5,6 +5,8 @@ import datetime import ddt import mock +from django.test import override_settings + from lms.djangoapps.certificates.tests.factories import GeneratedCertificateFactory from lms.djangoapps.certificates.api import is_passing_status from lms.envs.test import CREDENTIALS_PUBLIC_SERVICE_URL @@ -13,7 +15,9 @@ from django.conf import settings from django.urls import reverse from django.test.client import RequestFactory from opaque_keys.edx.locator import CourseLocator +from openedx.features.learner_profile import REDIRECT_TO_PROFILE_MICROFRONTEND from openedx.features.learner_profile.views.learner_profile import learner_profile_context +from openedx.core.djangoapps.waffle_utils.testutils import override_waffle_flag from student.tests.factories import CourseEnrollmentFactory, UserFactory from util.testing import UrlResetMixin from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase @@ -111,6 +115,14 @@ class LearnerProfileViewTest(UrlResetMixin, ModuleStoreTestCase): for attribute in self.CONTEXT_DATA: self.assertIn(attribute, response.content) + def test_redirect_view(self): + profile_url = "http://profile-spa/abc/" + with override_settings(PROFILE_MICROFRONTEND_URL=profile_url): + with override_waffle_flag(REDIRECT_TO_PROFILE_MICROFRONTEND, active=True): + profile_path = reverse('learner_profile', kwargs={'username': self.USERNAME}) + response = self.client.get(path=profile_path) + self.assertRedirects(response, profile_url + self.USERNAME, target_status_code=404) + def test_records_link(self): profile_path = reverse('learner_profile', kwargs={'username': self.USERNAME}) response = self.client.get(path=profile_path) diff --git a/openedx/features/learner_profile/views/learner_profile.py b/openedx/features/learner_profile/views/learner_profile.py index c727d57aa27442b84f6e945ff7660e059f9b4b7b..6f9e289d84d144afd39bc4d9e164290a1567e734 100644 --- a/openedx/features/learner_profile/views/learner_profile.py +++ b/openedx/features/learner_profile/views/learner_profile.py @@ -7,7 +7,7 @@ from django.contrib.staticfiles.storage import staticfiles_storage from django.core.exceptions import ObjectDoesNotExist from django.urls import reverse from django.http import Http404 -from django.shortcuts import render_to_response +from django.shortcuts import render_to_response, redirect from django.utils.translation import ugettext as _ from django.views.decorators.http import require_http_methods from django_countries import countries @@ -23,7 +23,7 @@ from openedx.core.djangolib.markup import HTML, Text from openedx.features.journals.api import journals_enabled from student.models import User -from .. import SHOW_PROFILE_MESSAGE +from .. import SHOW_PROFILE_MESSAGE, REDIRECT_TO_PROFILE_MICROFRONTEND from learner_achievements import LearnerAchievementsFragmentView @@ -47,6 +47,10 @@ def learner_profile(request, username): Example usage: GET /account/profile """ + if REDIRECT_TO_PROFILE_MICROFRONTEND.is_enabled(): + profile_microfrontend_url = "{}{}".format(settings.PROFILE_MICROFRONTEND_URL, username) + return redirect(profile_microfrontend_url) + try: context = learner_profile_context(request, username, request.user.is_staff) # TODO: LEARNER-2554: 09/2017: Remove message and cookie logic when we no longer want this message