Redirect Profile view to Profile Microfrontend

This commit is contained in:
Nimisha Asthagiri
2019-02-12 23:57:50 -05:00
parent b22c1ed0d6
commit 7848dd737f
5 changed files with 29 additions and 2 deletions

View File

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

View File

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

View File

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

View File

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

View File

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