From 353153666de3c7f4f97246adaa921c9e28bd3ed5 Mon Sep 17 00:00:00 2001 From: Eric Herrera Date: Wed, 12 May 2021 16:02:47 -0500 Subject: [PATCH] refactor!: Enable Account MFE globally. This commit refactors the way the Account MFE is activated in the platform. The main objective is to control the global activation/deactivation of the MFE through the account.redirect_to_microfrontend waffle flag and use the Site Configurations to control MFE activation/deactivation with per-site granularity. Notice that the Site Configuration object will have precedence over the waffle flag value. Since the classic Account Django view will be most likely supported during Lilac, the expiration of this temporary waffle flag was extended till the end of 2021 With this commit: - There's no need to create a Site Configuration object to get the MFE activated. Setting the waffle flag to True is enough. - It helps multisite installations to better handling granular per-site activation/deactivation. BREAKING CHANGE: For operators of multisite installations, the activation of the waffle flag will now activate the MFE for all sites, unless explicitly disabled on a per-site basis. Otherwise, this is a backwards-compatible change, since the MFE will remain activated for installations where this is already enabled. --- .../accounts/tests/test_settings_views.py | 39 ++++++++++++------- .../djangoapps/user_api/accounts/toggles.py | 11 +++--- 2 files changed, 30 insertions(+), 20 deletions(-) diff --git a/openedx/core/djangoapps/user_api/accounts/tests/test_settings_views.py b/openedx/core/djangoapps/user_api/accounts/tests/test_settings_views.py index 3930a777bf..f5a112c601 100644 --- a/openedx/core/djangoapps/user_api/accounts/tests/test_settings_views.py +++ b/openedx/core/djangoapps/user_api/accounts/tests/test_settings_views.py @@ -241,20 +241,31 @@ class AccountSettingsViewTest(ThirdPartyAuthTestMixin, SiteMixin, ProgramsApiCon assert len(order_detail) == 1 def test_redirect_view(self): + old_url_path = reverse('account_settings') 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.assertContains(response, attribute) - - # 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) + # Test with waffle flag active and none site setting, redirects to microfrontend response = self.client.get(path=old_url_path) self.assertRedirects(response, settings.ACCOUNT_MICROFRONTEND_URL, fetch_redirect_response=False) + + # Test with waffle flag disabled and site setting disabled, does not redirect + response = self.client.get(path=old_url_path) + for attribute in self.FIELDS: + self.assertContains(response, attribute) + + # Test with site setting disabled, does not redirect + site_domain = 'othersite.example.com' + site = self.set_up_site(site_domain, { + 'SITE_NAME': site_domain, + 'ENABLE_ACCOUNT_MICROFRONTEND': False + }) + self.client.login(username=self.USERNAME, password=self.PASSWORD) + response = self.client.get(path=old_url_path) + for attribute in self.FIELDS: + self.assertContains(response, attribute) + + # Test with site setting enabled, redirects to microfrontend + site.configuration.site_values['ENABLE_ACCOUNT_MICROFRONTEND'] = True + site.configuration.save() + site.__class__.objects.clear_cache() + response = self.client.get(path=old_url_path) + self.assertRedirects(response, settings.ACCOUNT_MICROFRONTEND_URL, fetch_redirect_response=False) diff --git a/openedx/core/djangoapps/user_api/accounts/toggles.py b/openedx/core/djangoapps/user_api/accounts/toggles.py index 25f49faab3..f8221a02ab 100644 --- a/openedx/core/djangoapps/user_api/accounts/toggles.py +++ b/openedx/core/djangoapps/user_api/accounts/toggles.py @@ -29,16 +29,15 @@ def should_redirect_to_order_history_microfrontend(): # .. toggle_implementation: WaffleFlag # .. toggle_default: False # .. toggle_description: Supports staged rollout of a new micro-frontend-based implementation of the account page. +# Its action can be overridden using site's ENABLE_ACCOUNT_MICROFRONTEND setting. # .. toggle_use_cases: temporary, open_edx # .. toggle_creation_date: 2019-04-30 -# .. toggle_target_removal_date: 2020-12-31 -# .. toggle_warnings: Also set settings.ACCOUNT_MICROFRONTEND_URL and site's ENABLE_ACCOUNT_MICROFRONTEND. +# .. toggle_target_removal_date: 2021-12-31 +# .. toggle_warnings: Also set settings.ACCOUNT_MICROFRONTEND_URL. # .. toggle_tickets: DEPR-17 REDIRECT_TO_ACCOUNT_MICROFRONTEND = LegacyWaffleFlag('account', 'redirect_to_microfrontend', __name__) def should_redirect_to_account_microfrontend(): - return ( - configuration_helpers.get_value('ENABLE_ACCOUNT_MICROFRONTEND') and - REDIRECT_TO_ACCOUNT_MICROFRONTEND.is_enabled() - ) + return configuration_helpers.get_value('ENABLE_ACCOUNT_MICROFRONTEND', + REDIRECT_TO_ACCOUNT_MICROFRONTEND.is_enabled())