diff --git a/lms/envs/common.py b/lms/envs/common.py index 3bfd56693504a18766dc9c3212549cfb50a68e00..92247b6f71ad49aa37dc52995da58af03efec941 100644 --- a/lms/envs/common.py +++ b/lms/envs/common.py @@ -601,8 +601,8 @@ FEATURES = { # .. toggle_creation_date: 2020-09-08 # .. toggle_target_removal_date: None # .. toggle_tickets: 'https://github.com/edx/edx-platform/pull/24908' - # .. toggle_warnings: Also set settings.ACCOUNT_MICROFRONTEND_URL and set REDIRECT_TO_ACCOUNT_MICROFRONTEND for - # rollout. This temporary feature toggle does not have a target removal date. + # .. toggle_warnings: Also set settings.LOGISTRATION_MICROFRONTEND_URL for rollout. This temporary feature + # toggle does not have a target removal date. 'ENABLE_LOGISTRATION_MICROFRONTEND': False, ### ORA Feature Flags ### @@ -4000,6 +4000,7 @@ WRITABLE_GRADEBOOK_URL = None PROFILE_MICROFRONTEND_URL = None ORDER_HISTORY_MICROFRONTEND_URL = None ACCOUNT_MICROFRONTEND_URL = None +LOGISTRATION_MICROFRONTEND_URL = None PROGRAM_CONSOLE_MICROFRONTEND_URL = None LEARNING_MICROFRONTEND_URL = None diff --git a/lms/envs/devstack.py b/lms/envs/devstack.py index 93aa3159e3a5969778e712face01b247bc234a95..06a8e59631ec6d91e32e051ff8b0849bbafbe61f 100644 --- a/lms/envs/devstack.py +++ b/lms/envs/devstack.py @@ -331,6 +331,7 @@ EDXNOTES_CLIENT_NAME = 'edx_notes_api-backend-service' ############## Settings for Microfrontends ######################### LEARNING_MICROFRONTEND_URL = 'http://localhost:2000' ACCOUNT_MICROFRONTEND_URL = 'http://localhost:1997' +LOGISTRATION_MICROFRONTEND_URL = 'http://localhost:1999' ############## Docker based devstack settings ####################### diff --git a/lms/envs/devstack_decentralized.py b/lms/envs/devstack_decentralized.py index 1790e0eee924807f07227fd14faf6c9a50e31ab9..f08323b7523bc846a529ad9ad9d5398f225b87c8 100644 --- a/lms/envs/devstack_decentralized.py +++ b/lms/envs/devstack_decentralized.py @@ -270,6 +270,7 @@ EDXNOTES_CLIENT_NAME = 'edx_notes_api-backend-service' ############## Settings for Microfrontends ######################### LEARNING_MICROFRONTEND_URL = 'http://localhost:2000' ACCOUNT_MICROFRONTEND_URL = 'http://localhost:1997' +LOGISTRATION_MICROFRONTEND_URL = 'http://localhost:1999' ############## Docker based devstack settings ####################### diff --git a/lms/envs/test.py b/lms/envs/test.py index 6a2055ceded2844689df9e2fee12d05c866ecccc..f0a5163a952ddf984876d225afb3aaf38c0eb65e 100644 --- a/lms/envs/test.py +++ b/lms/envs/test.py @@ -571,6 +571,7 @@ PDF_RECEIPT_TAX_ID_LABEL = 'Tax ID' PROFILE_MICROFRONTEND_URL = "http://profile-mfe/abc/" ORDER_HISTORY_MICROFRONTEND_URL = "http://order-history-mfe/" ACCOUNT_MICROFRONTEND_URL = "http://account-mfe/" +LOGISTRATION_MICROFRONTEND_URL = "http://logistation-mfe" LEARNING_MICROFRONTEND_URL = "http://learning-mfe" ########################## limiting dashboard courses ###################### diff --git a/lms/templates/header/navbar-not-authenticated.html b/lms/templates/header/navbar-not-authenticated.html index c998d8cc874b21d3d42f135c2066f246c4c5a322..84bcafb348e2b4352e6fc907b955b2904e3f387c 100644 --- a/lms/templates/header/navbar-not-authenticated.html +++ b/lms/templates/header/navbar-not-authenticated.html @@ -11,7 +11,7 @@ from django.urls import reverse from django.utils.translation import ugettext as _ from six import text_type -from openedx.core.djangoapps.user_api.accounts.toggles import should_redirect_to_logistration_mircrofrontend +from openedx.core.djangoapps.user_authn.utils import should_redirect_to_logistration_mircrofrontend %> <% @@ -51,7 +51,7 @@ from openedx.core.djangoapps.user_api.accounts.toggles import should_redirect_to % if allow_public_account_creation: % if should_redirect_to_logistration_mfe: <div class="mobile-nav-item hidden-mobile nav-item"> - <a class="register-btn btn" href="${settings.ACCOUNT_MICROFRONTEND_URL}/register${login_query()}">${_("Register")}</a> + <a class="register-btn btn" href="${settings.LOGISTRATION_MICROFRONTEND_URL}/register${login_query()}">${_("Register")}</a> </div> % else: <div class="mobile-nav-item hidden-mobile nav-item"> @@ -61,7 +61,7 @@ from openedx.core.djangoapps.user_api.accounts.toggles import should_redirect_to % endif % if should_redirect_to_logistration_mfe: <div class="mobile-nav-item hidden-mobile nav-item"> - <a class="sign-in-btn btn" href="${settings.ACCOUNT_MICROFRONTEND_URL}/login${login_query()}">${_("Sign in")}</a> + <a class="sign-in-btn btn" href="${settings.LOGISTRATION_MICROFRONTEND_URL}/login${login_query()}">${_("Sign in")}</a> </div> % else: <div class="mobile-nav-item hidden-mobile nav-item"> diff --git a/openedx/core/djangoapps/user_api/accounts/toggles.py b/openedx/core/djangoapps/user_api/accounts/toggles.py index 5bb2f019b5238ce6831557bdbf294f4d118e1e97..621d13048d809e08dc21ec4317c1fb31f5187567 100644 --- a/openedx/core/djangoapps/user_api/accounts/toggles.py +++ b/openedx/core/djangoapps/user_api/accounts/toggles.py @@ -2,8 +2,6 @@ Toggles for accounts related code. """ -from django.conf import settings - from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers from openedx.core.djangoapps.waffle_utils import WaffleFlag @@ -44,10 +42,3 @@ def should_redirect_to_account_microfrontend(): configuration_helpers.get_value('ENABLE_ACCOUNT_MICROFRONTEND') and REDIRECT_TO_ACCOUNT_MICROFRONTEND.is_enabled() ) - - -def should_redirect_to_logistration_mircrofrontend(): - return ( - should_redirect_to_account_microfrontend() and - settings.FEATURES.get('ENABLE_LOGISTRATION_MICROFRONTEND') - ) diff --git a/openedx/core/djangoapps/user_authn/utils.py b/openedx/core/djangoapps/user_authn/utils.py index 2ed90062f136e62ed550dbebf6ee410cb1b8b9c1..fb40374a85e1b3b270d697f8f55d832cbcb77d91 100644 --- a/openedx/core/djangoapps/user_authn/utils.py +++ b/openedx/core/djangoapps/user_authn/utils.py @@ -11,6 +11,8 @@ from django.utils import http from oauth2_provider.models import Application from six.moves.urllib.parse import urlparse # pylint: disable=import-error +from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers + def is_safe_login_or_logout_redirect(redirect_to, request_host, dot_client_id, require_https): """ @@ -67,3 +69,12 @@ def is_registration_api_v1(request): :return: Bool """ return 'v1' in request.get_full_path() and 'register' not in request.get_full_path() + + +def should_redirect_to_logistration_mircrofrontend(): + """ + Checks if login/registration should be done via MFE. + """ + return configuration_helpers.get_value( + 'ENABLE_LOGISTRATION_MICROFRONTEND', settings.FEATURES.get('ENABLE_LOGISTRATION_MICROFRONTEND') + ) diff --git a/openedx/core/djangoapps/user_authn/views/login.py b/openedx/core/djangoapps/user_authn/views/login.py index 638ca779d798f7e789d6f726b7780d9b9433271c..384f33e8e6f6ea96f6e74a5e435aadb184ab43c9 100644 --- a/openedx/core/djangoapps/user_authn/views/login.py +++ b/openedx/core/djangoapps/user_authn/views/login.py @@ -31,10 +31,10 @@ from rest_framework.views import APIView from edxmako.shortcuts import render_to_response from openedx.core.djangoapps.password_policy import compliance as password_policy_compliance from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers -from openedx.core.djangoapps.user_api.accounts.toggles import should_redirect_to_logistration_mircrofrontend from openedx.core.djangoapps.user_authn.views.login_form import get_login_session_form from openedx.core.djangoapps.user_authn.cookies import refresh_jwt_cookies, set_logged_in_cookies from openedx.core.djangoapps.user_authn.exceptions import AuthFailedError +from openedx.core.djangoapps.user_authn.utils import should_redirect_to_logistration_mircrofrontend from openedx.core.djangoapps.util.user_messages import PageLevelMessages from openedx.core.djangoapps.user_authn.views.password_reset import send_password_reset_email_for_user from openedx.core.djangoapps.user_authn.config.waffle import ENABLE_LOGIN_USING_THIRDPARTY_AUTH_ONLY diff --git a/openedx/core/djangoapps/user_authn/views/login_form.py b/openedx/core/djangoapps/user_authn/views/login_form.py index 67f0f6e1524e047c9b4aedf30b77fd32d0943671..c5ec46d83576938cd03c953ed61dd1141e50e3e1 100644 --- a/openedx/core/djangoapps/user_authn/views/login_form.py +++ b/openedx/core/djangoapps/user_authn/views/login_form.py @@ -18,13 +18,13 @@ import third_party_auth from edxmako.shortcuts import render_to_response from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers from openedx.core.djangoapps.user_api import accounts -from openedx.core.djangoapps.user_api.accounts.toggles import should_redirect_to_logistration_mircrofrontend from openedx.core.djangoapps.user_api.accounts.utils import ( is_multiple_user_enterprises_feature_enabled, is_secondary_email_feature_enabled ) from openedx.core.djangoapps.user_api.helpers import FormDescription from openedx.core.djangoapps.user_authn.cookies import are_logged_in_cookies_set +from openedx.core.djangoapps.user_authn.utils import should_redirect_to_logistration_mircrofrontend from openedx.core.djangoapps.user_authn.views.password_reset import get_password_reset_form from openedx.core.djangoapps.user_authn.views.registration_form import RegistrationFormFactory from openedx.features.enterprise_support.api import enterprise_customer_for_request @@ -189,7 +189,7 @@ def login_and_registration_form(request, initial_mode="login"): initial_mode, '?' + query_params if query_params else '' ) - return redirect(settings.ACCOUNT_MICROFRONTEND_URL + url_path) + return redirect(settings.LOGISTRATION_MICROFRONTEND_URL + url_path) # Account activation message account_activation_messages = [ diff --git a/openedx/core/djangoapps/user_authn/views/tests/test_login.py b/openedx/core/djangoapps/user_authn/views/tests/test_login.py index 718d213363805164933e53eb6affa4b6e74cc1ee..df89781a19fdcb35ec4c0b341db745d94c233d2f 100644 --- a/openedx/core/djangoapps/user_authn/views/tests/test_login.py +++ b/openedx/core/djangoapps/user_authn/views/tests/test_login.py @@ -25,7 +25,6 @@ from openedx.core.djangoapps.password_policy.compliance import ( NonCompliantPasswordWarning ) from openedx.core.djangoapps.user_api.accounts import EMAIL_MIN_LENGTH, EMAIL_MAX_LENGTH -from openedx.core.djangoapps.user_api.accounts.toggles import REDIRECT_TO_ACCOUNT_MICROFRONTEND from openedx.core.djangoapps.user_authn.cookies import jwt_cookies from openedx.core.djangoapps.user_authn.views.login import ( AllowedAuthUser, @@ -35,7 +34,6 @@ from openedx.core.djangoapps.user_authn.views.login import ( from openedx.core.djangoapps.user_authn.tests.utils import setup_login_oauth_client from openedx.core.djangolib.testing.utils import CacheIsolationTestCase, skip_unless_lms from openedx.core.djangoapps.site_configuration.tests.mixins import SiteMixin -from openedx.core.djangoapps.waffle_utils.testutils import override_waffle_flag from openedx.core.lib.api.test_utils import ApiTestCase from student.tests.factories import RegistrationFactory, UserFactory, UserProfileFactory from util.password_policy_validators import DEFAULT_MAX_PASSWORD_LENGTH @@ -142,8 +140,6 @@ class LoginTest(SiteMixin, CacheIsolationTestCase): @override_settings(FEATURES=FEATURES_WITH_LOGIN_MFE_ENABLED) @skip_unless_lms def test_login_success_with_redirect(self, next_url, course_id, expected_redirect): - site_domain = 'example.org' - self.set_up_site(site_domain, {'ENABLE_ACCOUNT_MICROFRONTEND': True}) post_params = {} if next_url: @@ -151,13 +147,12 @@ class LoginTest(SiteMixin, CacheIsolationTestCase): if course_id: post_params['course_id'] = course_id - with override_waffle_flag(REDIRECT_TO_ACCOUNT_MICROFRONTEND, active=True): - response, _ = self._login_response( - self.user_email, - self.password, - extra_post_params=post_params, - HTTP_ACCEPT='*/*', - ) + response, _ = self._login_response( + self.user_email, + self.password, + extra_post_params=post_params, + HTTP_ACCEPT='*/*', + ) self._assert_response(response, success=True) self._assert_redirect_url(response, expected_redirect) diff --git a/openedx/core/djangoapps/user_authn/views/tests/test_logistration.py b/openedx/core/djangoapps/user_authn/views/tests/test_logistration.py index 35787b8105eb6c50d10022b1198db6f1982fa89e..04ac77b0a23c956f127c39ca4fd1e289f261d758 100644 --- a/openedx/core/djangoapps/user_authn/views/tests/test_logistration.py +++ b/openedx/core/djangoapps/user_authn/views/tests/test_logistration.py @@ -27,9 +27,7 @@ from lms.djangoapps.branding.api import get_privacy_url from openedx.core.djangoapps.site_configuration.tests.factories import SiteConfigurationFactory, SiteFactory from openedx.core.djangoapps.site_configuration.tests.mixins import SiteMixin from openedx.core.djangoapps.theming.tests.test_util import with_comprehensive_theme_context -from openedx.core.djangoapps.user_api.accounts.toggles import REDIRECT_TO_ACCOUNT_MICROFRONTEND from openedx.core.djangoapps.user_authn.views.login_form import login_and_registration_form -from openedx.core.djangoapps.waffle_utils.testutils import override_waffle_flag from openedx.core.djangolib.js_utils import dump_js_escaped_json from openedx.core.djangolib.markup import HTML, Text from openedx.core.djangolib.testing.utils import skip_unless_lms @@ -40,7 +38,7 @@ from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase @skip_unless_lms @ddt.ddt -class LoginAndRegistrationTest(ThirdPartyAuthTestMixin, UrlResetMixin, ModuleStoreTestCase, SiteMixin): +class LoginAndRegistrationTest(ThirdPartyAuthTestMixin, UrlResetMixin, ModuleStoreTestCase): """ Tests for Login and Registration. """ USERNAME = "bob" EMAIL = "bob@example.com" @@ -82,13 +80,9 @@ class LoginAndRegistrationTest(ThirdPartyAuthTestMixin, UrlResetMixin, ModuleSto Test that if Logistration MFE is enabled, then we redirect to the correct URL. """ - site_domain = 'example.org' - self.set_up_site(site_domain, {'ENABLE_ACCOUNT_MICROFRONTEND': True}) - - with override_waffle_flag(REDIRECT_TO_ACCOUNT_MICROFRONTEND, active=True): - response = self.client.get(reverse(url_name)) + response = self.client.get(reverse(url_name)) - self.assertEqual(response.url, settings.ACCOUNT_MICROFRONTEND_URL + path) + self.assertEqual(response.url, settings.LOGISTRATION_MICROFRONTEND_URL + path) self.assertEqual(response.status_code, 302) @ddt.data( @@ -110,15 +104,10 @@ class LoginAndRegistrationTest(ThirdPartyAuthTestMixin, UrlResetMixin, ModuleSto Test that if request is redirected to logistration MFE, query params are passed to the redirect url. """ - site_domain = 'example.org' - expected_url = settings.ACCOUNT_MICROFRONTEND_URL + path + '?' + urlencode(query_params) - - self.set_up_site(site_domain, {'ENABLE_ACCOUNT_MICROFRONTEND': True}) - - with override_waffle_flag(REDIRECT_TO_ACCOUNT_MICROFRONTEND, active=True): - response = self.client.get(reverse(url_name), query_params) + expected_url = settings.LOGISTRATION_MICROFRONTEND_URL + path + '?' + urlencode(query_params) + response = self.client.get(reverse(url_name), query_params) - self.assertRedirects(response, expected_url) + self.assertRedirects(response, expected_url, target_status_code=302) @ddt.data( ("signin_user", "login"), diff --git a/themes/edx.org/lms/templates/header/navbar-not-authenticated.html b/themes/edx.org/lms/templates/header/navbar-not-authenticated.html index f4630e5b96422a56305baeabe73cd48082af0493..ae8b0ff27eb17f6f9cf1c81a168e703dd2de62bf 100644 --- a/themes/edx.org/lms/templates/header/navbar-not-authenticated.html +++ b/themes/edx.org/lms/templates/header/navbar-not-authenticated.html @@ -23,7 +23,7 @@ from six import text_type % if allow_public_account_creation: % if should_redirect_to_logistration_mfe: <div class="mobile-nav-item hidden-mobile nav-item"> - <a class="register-btn btn" href="${settings.ACCOUNT_MICROFRONTEND_URL}/register${login_query()}">${_("Register")}</a> + <a class="register-btn btn" href="${settings.LOGISTRATION_MICROFRONTEND_URL}/register${login_query()}">${_("Register")}</a> </div> % else: <div class="mobile-nav-item hidden-mobile nav-item"> @@ -33,7 +33,7 @@ from six import text_type % endif % if should_redirect_to_logistration_mfe: <div class="mobile-nav-item hidden-mobile nav-item"> - <a class="sign-in-btn btn" href="${settings.ACCOUNT_MICROFRONTEND_URL}/login${login_query()}">${_("Sign in")}</a> + <a class="sign-in-btn btn" href="${settings.LOGISTRATION_MICROFRONTEND_URL}/login${login_query()}">${_("Sign in")}</a> </div> % else: <div class="mobile-nav-item hidden-mobile nav-item">