Account: Toggle for Microfrontend Redirect
ARCH-636
This commit is contained in:
@@ -5,6 +5,7 @@ import logging
|
||||
from django.conf import settings
|
||||
from django.contrib import messages
|
||||
from django.contrib.auth.decorators import login_required
|
||||
from django.shortcuts import redirect
|
||||
from django.utils.translation import ugettext as _
|
||||
from django.urls import reverse
|
||||
from django.views.decorators.http import require_http_methods
|
||||
@@ -19,7 +20,10 @@ from openedx.core.djangoapps.dark_lang.models import DarkLangConfig
|
||||
from openedx.core.djangoapps.lang_pref.api import all_languages, released_languages
|
||||
from openedx.core.djangoapps.programs.models import ProgramsApiConfig
|
||||
from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers
|
||||
from openedx.core.djangoapps.user_api.accounts.toggles import should_redirect_to_order_history_microfrontend
|
||||
from openedx.core.djangoapps.user_api.accounts.toggles import (
|
||||
should_redirect_to_order_history_microfrontend,
|
||||
should_redirect_to_account_microfrontend,
|
||||
)
|
||||
from openedx.core.djangoapps.user_api.preferences.api import get_user_preferences
|
||||
from openedx.core.lib.edx_api_utils import get_edx_api_data
|
||||
from openedx.core.lib.time_zone_utils import TIME_ZONE_CHOICES
|
||||
@@ -52,6 +56,9 @@ def account_settings(request):
|
||||
GET /account/settings
|
||||
|
||||
"""
|
||||
if should_redirect_to_account_microfrontend():
|
||||
return redirect(settings.ACCOUNT_MICROFRONTEND_URL)
|
||||
|
||||
context = account_settings_context(request)
|
||||
return render_to_response('student_account/account_settings.html', context)
|
||||
|
||||
|
||||
@@ -13,19 +13,22 @@ from edx_rest_api_client import exceptions
|
||||
from lms.djangoapps.commerce.models import CommerceConfiguration
|
||||
from lms.djangoapps.commerce.tests import factories
|
||||
from lms.djangoapps.commerce.tests.mocks import mock_get_orders
|
||||
from openedx.core.djangoapps.user_api.accounts.toggles import REDIRECT_TO_ACCOUNT_MICROFRONTEND
|
||||
from openedx.core.djangoapps.dark_lang.models import DarkLangConfig
|
||||
from openedx.core.djangoapps.lang_pref.tests.test_api import EN, LT_LT
|
||||
from openedx.core.djangoapps.programs.tests.mixins import ProgramsApiConfigMixin
|
||||
from openedx.core.djangoapps.site_configuration.tests.factories import SiteFactory
|
||||
from openedx.core.djangoapps.site_configuration.tests.mixins import SiteMixin
|
||||
from openedx.core.djangoapps.user_api.tests.factories import UserPreferenceFactory
|
||||
from openedx.core.djangolib.testing.utils import skip_unless_lms
|
||||
from openedx.core.djangoapps.user_api.accounts.settings_views import account_settings_context, get_user_orders
|
||||
from openedx.core.djangoapps.waffle_utils.testutils import override_waffle_flag
|
||||
from student.tests.factories import UserFactory
|
||||
from third_party_auth.tests.testutil import ThirdPartyAuthTestMixin
|
||||
|
||||
|
||||
@skip_unless_lms
|
||||
class AccountSettingsViewTest(ThirdPartyAuthTestMixin, TestCase, ProgramsApiConfigMixin):
|
||||
class AccountSettingsViewTest(ThirdPartyAuthTestMixin, SiteMixin, ProgramsApiConfigMixin, TestCase):
|
||||
""" Tests for the account settings view. """
|
||||
|
||||
USERNAME = 'student'
|
||||
@@ -152,7 +155,7 @@ class AccountSettingsViewTest(ThirdPartyAuthTestMixin, TestCase, ProgramsApiConf
|
||||
|
||||
def test_view(self):
|
||||
"""
|
||||
Test that all fields are visible
|
||||
Test that all fields are visible
|
||||
"""
|
||||
view_path = reverse('account_settings')
|
||||
response = self.client.get(path=view_path)
|
||||
@@ -243,3 +246,22 @@ class AccountSettingsViewTest(ThirdPartyAuthTestMixin, TestCase, ProgramsApiConf
|
||||
order_detail = get_user_orders(self.user)
|
||||
|
||||
self.assertEqual(len(order_detail), 1)
|
||||
|
||||
def test_redirect_view(self):
|
||||
with override_waffle_flag(REDIRECT_TO_ACCOUNT_MICROFRONTEND, active=True):
|
||||
old_url_path = reverse('account_settings')
|
||||
|
||||
# Test with waffle flag active and site setting disabled, does not redirect
|
||||
response = self.client.get(path=old_url_path)
|
||||
for attribute in self.FIELDS:
|
||||
self.assertIn(attribute, response.content)
|
||||
|
||||
# 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_ACCOUNT_MICROFRONTEND': True
|
||||
})
|
||||
self.client.login(username=self.USERNAME, password=self.PASSWORD)
|
||||
response = self.client.get(path=old_url_path)
|
||||
self.assertRedirects(response, settings.ACCOUNT_MICROFRONTEND_URL, fetch_redirect_response=False)
|
||||
|
||||
@@ -13,12 +13,35 @@ from openedx.core.djangoapps.waffle_utils import WaffleFlag
|
||||
# .. toggle_use_cases: incremental_release, open_edx
|
||||
# .. toggle_creation_date: 2019-04-11
|
||||
# .. toggle_expiration_date: 2020-12-31
|
||||
# .. toggle_warnings: Remember to also set ORDER_HISTORY_MICROFRONTEND_URL before this toggle is enabled.
|
||||
# .. toggle_warnings: Also set settings.ORDER_HISTORY_MICROFRONTEND_URL and site's ENABLE_ORDER_HISTORY_MICROFRONTEND.
|
||||
# .. toggle_tickets: DEPR-17
|
||||
# .. toggle_status: supported
|
||||
REDIRECT_TO_ORDER_HISTORY_MICROFRONTEND = WaffleFlag('order_history', 'redirect_to_microfrontend')
|
||||
|
||||
|
||||
def should_redirect_to_order_history_microfrontend():
|
||||
should_redirect_for_current_site = configuration_helpers.get_value('ENABLE_ORDER_HISTORY_MICROFRONTEND')
|
||||
return REDIRECT_TO_ORDER_HISTORY_MICROFRONTEND.is_enabled() and should_redirect_for_current_site
|
||||
return (
|
||||
configuration_helpers.get_value('ENABLE_ORDER_HISTORY_MICROFRONTEND') and
|
||||
REDIRECT_TO_ORDER_HISTORY_MICROFRONTEND.is_enabled()
|
||||
)
|
||||
|
||||
|
||||
# .. toggle_name: REDIRECT_TO_ACCOUNT_MICROFRONTEND
|
||||
# .. toggle_type: waffle_flag
|
||||
# .. toggle_default: False
|
||||
# .. toggle_description: Supports staged rollout of a new micro-frontend-based implementation of the account page.
|
||||
# .. toggle_category: micro-frontend
|
||||
# .. toggle_use_cases: incremental_release, open_edx
|
||||
# .. toggle_creation_date: 2019-04-30
|
||||
# .. toggle_expiration_date: 2020-12-31
|
||||
# .. toggle_warnings: Also set settings.ACCOUNT_MICROFRONTEND_URL and site's ENABLE_ACCOUNT_MICROFRONTEND.
|
||||
# .. toggle_tickets: DEPR-17
|
||||
# .. toggle_status: supported
|
||||
REDIRECT_TO_ACCOUNT_MICROFRONTEND = WaffleFlag('account', 'redirect_to_microfrontend')
|
||||
|
||||
|
||||
def should_redirect_to_account_microfrontend():
|
||||
return (
|
||||
configuration_helpers.get_value('ENABLE_ACCOUNT_MICROFRONTEND') and
|
||||
REDIRECT_TO_ACCOUNT_MICROFRONTEND.is_enabled()
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user