From 7848dd737f964757fd1de2ceb508ddf77b7d5f31 Mon Sep 17 00:00:00 2001 From: Nimisha Asthagiri Date: Tue, 12 Feb 2019 23:57:50 -0500 Subject: [PATCH 1/2] Redirect Profile view to Profile Microfrontend --- lms/envs/common.py | 5 +++++ lms/envs/production.py | 3 +++ openedx/features/learner_profile/__init__.py | 3 +++ .../tests/views/test_learner_profile.py | 12 ++++++++++++ .../learner_profile/views/learner_profile.py | 8 ++++++-- 5 files changed, 29 insertions(+), 2 deletions(-) diff --git a/lms/envs/common.py b/lms/envs/common.py index 7629aebd98..c4436cb09b 100644 --- a/lms/envs/common.py +++ b/lms/envs/common.py @@ -2452,6 +2452,11 @@ MOBILE_STORE_URLS = { 'google': '#' } +################# Learner Profile ################## + +# TODO (DEPR-TODO) +PROFILE_MICROFRONTEND_URL_BASE = "http://localhost:18000/profile-spa/" + ################# Student Verification ################# VERIFY_STUDENT = { "DAYS_GOOD_FOR": 365, # How many days is a verficiation good for? diff --git a/lms/envs/production.py b/lms/envs/production.py index 240c57a703..5c4f42dd20 100644 --- a/lms/envs/production.py +++ b/lms/envs/production.py @@ -307,6 +307,9 @@ ACTIVATION_EMAIL_SUPPORT_LINK = ENV_TOKENS.get( # Mobile store URL overrides MOBILE_STORE_URLS = ENV_TOKENS.get('MOBILE_STORE_URLS', MOBILE_STORE_URLS) +# Learner Profile URL overrides +PROFILE_MICROFRONTEND_URL_BASE = ENV_TOKENS.get('PROFILE_MICROFRONTEND_URL_BASE', PROFILE_MICROFRONTEND_URL_BASE) + # Timezone overrides TIME_ZONE = ENV_TOKENS.get('CELERY_TIMEZONE', CELERY_TIMEZONE) diff --git a/openedx/features/learner_profile/__init__.py b/openedx/features/learner_profile/__init__.py index 80875eefd0..ea54674b51 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 c2c459d91c..a5f545523f 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_base = "http://profile-spa/" + with override_settings(PROFILE_MICROFRONTEND_URL_BASE=profile_url_base): + 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_base + 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 a8d8d24b4f..a11555a769 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_BASE, 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 From 551f07c1306d96c10a7b6fb0e15bf750d9f94606 Mon Sep 17 00:00:00 2001 From: Nimisha Asthagiri Date: Thu, 14 Feb 2019 09:17:31 -0500 Subject: [PATCH 2/2] fixup! updated URL config name and value; added DEPR ticket --- lms/envs/common.py | 13 +++++++------ lms/envs/production.py | 6 ++---- .../tests/views/test_learner_profile.py | 6 +++--- .../learner_profile/views/learner_profile.py | 2 +- 4 files changed, 13 insertions(+), 14 deletions(-) diff --git a/lms/envs/common.py b/lms/envs/common.py index c4436cb09b..317d839b3f 100644 --- a/lms/envs/common.py +++ b/lms/envs/common.py @@ -2452,11 +2452,6 @@ MOBILE_STORE_URLS = { 'google': '#' } -################# Learner Profile ################## - -# TODO (DEPR-TODO) -PROFILE_MICROFRONTEND_URL_BASE = "http://localhost:18000/profile-spa/" - ################# Student Verification ################# VERIFY_STUDENT = { "DAYS_GOOD_FOR": 365, # How many days is a verficiation good for? @@ -3460,11 +3455,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 5c4f42dd20..2c4a219ece 100644 --- a/lms/envs/production.py +++ b/lms/envs/production.py @@ -307,9 +307,6 @@ ACTIVATION_EMAIL_SUPPORT_LINK = ENV_TOKENS.get( # Mobile store URL overrides MOBILE_STORE_URLS = ENV_TOKENS.get('MOBILE_STORE_URLS', MOBILE_STORE_URLS) -# Learner Profile URL overrides -PROFILE_MICROFRONTEND_URL_BASE = ENV_TOKENS.get('PROFILE_MICROFRONTEND_URL_BASE', PROFILE_MICROFRONTEND_URL_BASE) - # Timezone overrides TIME_ZONE = ENV_TOKENS.get('CELERY_TIMEZONE', CELERY_TIMEZONE) @@ -1101,8 +1098,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/tests/views/test_learner_profile.py b/openedx/features/learner_profile/tests/views/test_learner_profile.py index a5f545523f..9630b6e94a 100644 --- a/openedx/features/learner_profile/tests/views/test_learner_profile.py +++ b/openedx/features/learner_profile/tests/views/test_learner_profile.py @@ -116,12 +116,12 @@ class LearnerProfileViewTest(UrlResetMixin, ModuleStoreTestCase): self.assertIn(attribute, response.content) def test_redirect_view(self): - profile_url_base = "http://profile-spa/" - with override_settings(PROFILE_MICROFRONTEND_URL_BASE=profile_url_base): + 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_base + self.USERNAME, target_status_code=404) + 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}) diff --git a/openedx/features/learner_profile/views/learner_profile.py b/openedx/features/learner_profile/views/learner_profile.py index a11555a769..d9be85508b 100644 --- a/openedx/features/learner_profile/views/learner_profile.py +++ b/openedx/features/learner_profile/views/learner_profile.py @@ -48,7 +48,7 @@ def learner_profile(request, username): GET /account/profile """ if REDIRECT_TO_PROFILE_MICROFRONTEND.is_enabled(): - profile_microfrontend_url = "{}{}".format(settings.PROFILE_MICROFRONTEND_URL_BASE, username) + profile_microfrontend_url = "{}{}".format(settings.PROFILE_MICROFRONTEND_URL, username) return redirect(profile_microfrontend_url) try: