Merge pull request #20368 from edx/arch/account-settings-toggle
Account Settings: Toggle for Micro-frontend Redirect
This commit is contained in:
@@ -1,23 +0,0 @@
|
||||
"""
|
||||
Learner profile settings and helper methods.
|
||||
"""
|
||||
|
||||
from openedx.core.djangoapps.waffle_utils import WaffleFlag, WaffleFlagNamespace
|
||||
|
||||
|
||||
# Namespace for learner profile waffle flags.
|
||||
WAFFLE_FLAG_NAMESPACE = WaffleFlagNamespace(name='learner_profile')
|
||||
|
||||
# Waffle flag to redirect to another learner profile experience.
|
||||
# .. toggle_name: REDIRECT_TO_PROFILE_MICROFRONTEND
|
||||
# .. toggle_type: waffle_flag
|
||||
# .. toggle_default: False
|
||||
# .. toggle_description: Supports staged rollout of a new micro-frontend-based implementation of the profile page.
|
||||
# .. toggle_category: micro-frontend
|
||||
# .. toggle_use_cases: incremental_release, open_edx
|
||||
# .. toggle_creation_date: 2019-02-19
|
||||
# .. toggle_expiration_date: 2020-12-31
|
||||
# .. toggle_warnings: Remember to also set PROFILE_MICROFRONTEND_URL before this toggle is enabled.
|
||||
# .. toggle_tickets: DEPR-17
|
||||
# .. toggle_status: supported
|
||||
REDIRECT_TO_PROFILE_MICROFRONTEND = WaffleFlag(WAFFLE_FLAG_NAMESPACE, 'redirect_to_microfrontend')
|
||||
|
||||
@@ -15,7 +15,7 @@ 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.toggles import REDIRECT_TO_PROFILE_MICROFRONTEND
|
||||
from openedx.features.learner_profile.views.learner_profile import learner_profile_context
|
||||
from openedx.core.djangoapps.site_configuration.tests.mixins import SiteMixin
|
||||
from openedx.core.djangoapps.waffle_utils.testutils import override_waffle_flag
|
||||
@@ -117,25 +117,24 @@ class LearnerProfileViewTest(SiteMixin, UrlResetMixin, ModuleStoreTestCase):
|
||||
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})
|
||||
with override_waffle_flag(REDIRECT_TO_PROFILE_MICROFRONTEND, active=True):
|
||||
profile_path = reverse('learner_profile', kwargs={'username': self.USERNAME})
|
||||
|
||||
# Test with waffle flag active, site setting disabled
|
||||
response = self.client.get(path=profile_path)
|
||||
for attribute in self.CONTEXT_DATA:
|
||||
self.assertIn(attribute, response.content)
|
||||
# Test with waffle flag active and site setting disabled, does not redirect
|
||||
response = self.client.get(path=profile_path)
|
||||
for attribute in self.CONTEXT_DATA:
|
||||
self.assertIn(attribute, response.content)
|
||||
|
||||
# Test with waffle flag active, site setting enabled
|
||||
site_domain = 'othersite.example.com'
|
||||
self.set_up_site(site_domain, {
|
||||
'SITE_NAME': site_domain,
|
||||
'ENABLE_PROFILE_MICROFRONTEND': True
|
||||
})
|
||||
self.client.login(username=self.USERNAME, password=self.PASSWORD)
|
||||
response = self.client.get(path=profile_path)
|
||||
self.assertRedirects(response, profile_url + self.USERNAME, target_status_code=404)
|
||||
# Test with waffle flag active and site setting enabled, redirects to microfrontend
|
||||
site_domain = 'othersite.example.com'
|
||||
self.set_up_site(site_domain, {
|
||||
'SITE_NAME': site_domain,
|
||||
'ENABLE_PROFILE_MICROFRONTEND': True
|
||||
})
|
||||
self.client.login(username=self.USERNAME, password=self.PASSWORD)
|
||||
response = self.client.get(path=profile_path)
|
||||
profile_url = settings.PROFILE_MICROFRONTEND_URL
|
||||
self.assertRedirects(response, profile_url + self.USERNAME, fetch_redirect_response=False)
|
||||
|
||||
def test_records_link(self):
|
||||
profile_path = reverse('learner_profile', kwargs={'username': self.USERNAME})
|
||||
|
||||
31
openedx/features/learner_profile/toggles.py
Normal file
31
openedx/features/learner_profile/toggles.py
Normal file
@@ -0,0 +1,31 @@
|
||||
"""
|
||||
Toggles for Learner Profile page.
|
||||
"""
|
||||
|
||||
from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers
|
||||
from openedx.core.djangoapps.waffle_utils import WaffleFlag, WaffleFlagNamespace
|
||||
|
||||
|
||||
# Namespace for learner profile waffle flags.
|
||||
WAFFLE_FLAG_NAMESPACE = WaffleFlagNamespace(name='learner_profile')
|
||||
|
||||
# Waffle flag to redirect to another learner profile experience.
|
||||
# .. toggle_name: REDIRECT_TO_PROFILE_MICROFRONTEND
|
||||
# .. toggle_type: waffle_flag
|
||||
# .. toggle_default: False
|
||||
# .. toggle_description: Supports staged rollout of a new micro-frontend-based implementation of the profile page.
|
||||
# .. toggle_category: micro-frontend
|
||||
# .. toggle_use_cases: incremental_release, open_edx
|
||||
# .. toggle_creation_date: 2019-02-19
|
||||
# .. toggle_expiration_date: 2020-12-31
|
||||
# .. toggle_warnings: Also set settings.PROFILE_MICROFRONTEND_URL and site's ENABLE_PROFILE_MICROFRONTEND.
|
||||
# .. toggle_tickets: DEPR-17
|
||||
# .. toggle_status: supported
|
||||
REDIRECT_TO_PROFILE_MICROFRONTEND = WaffleFlag(WAFFLE_FLAG_NAMESPACE, 'redirect_to_microfrontend')
|
||||
|
||||
|
||||
def should_redirect_to_profile_microfrontend():
|
||||
return (
|
||||
configuration_helpers.get_value('ENABLE_PROFILE_MICROFRONTEND') and
|
||||
REDIRECT_TO_PROFILE_MICROFRONTEND.is_enabled()
|
||||
)
|
||||
@@ -19,13 +19,11 @@ from openedx.core.djangoapps.user_api.accounts.api import get_account_settings
|
||||
from openedx.core.djangoapps.user_api.errors import UserNotAuthorized, UserNotFound
|
||||
from openedx.core.djangoapps.user_api.preferences.api import get_user_preferences
|
||||
from openedx.core.djangolib.markup import HTML, Text
|
||||
from openedx.features.learner_profile.toggles import should_redirect_to_profile_microfrontend
|
||||
from openedx.features.learner_profile.views.learner_achievements import LearnerAchievementsFragmentView
|
||||
from openedx.features.journals.api import journals_enabled
|
||||
from student.models import User
|
||||
|
||||
from .. import REDIRECT_TO_PROFILE_MICROFRONTEND
|
||||
|
||||
from learner_achievements import LearnerAchievementsFragmentView
|
||||
|
||||
|
||||
@login_required
|
||||
@require_http_methods(['GET'])
|
||||
@@ -46,8 +44,7 @@ def learner_profile(request, username):
|
||||
Example usage:
|
||||
GET /account/profile
|
||||
"""
|
||||
is_profile_mfe_enabled_for_site = configuration_helpers.get_value('ENABLE_PROFILE_MICROFRONTEND')
|
||||
if is_profile_mfe_enabled_for_site and REDIRECT_TO_PROFILE_MICROFRONTEND.is_enabled():
|
||||
if should_redirect_to_profile_microfrontend():
|
||||
profile_microfrontend_url = "{}{}".format(settings.PROFILE_MICROFRONTEND_URL, username)
|
||||
return redirect(profile_microfrontend_url)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user