From d61936fdb61ff69b19a4cf44a24ca9837dce8038 Mon Sep 17 00:00:00 2001 From: Adeel Khan Date: Thu, 29 Oct 2020 15:03:24 +0500 Subject: [PATCH] Adds Logistration MFE url for forgot password email. This patch would enable routing learner to logistration MFE via forgot password url than on platform when ENABLE_LOGISTRATION_MICROFRONTEND feature flag is set. VAN-98 --- common/djangoapps/student/forms.py | 5 ++++- lms/envs/common.py | 1 + lms/envs/devstack.py | 1 + lms/envs/test.py | 1 + openedx/core/djangoapps/user_authn/views/password_reset.py | 5 ++++- .../user_authn/views/tests/test_reset_password.py | 7 ++++++- 6 files changed, 17 insertions(+), 3 deletions(-) diff --git a/common/djangoapps/student/forms.py b/common/djangoapps/student/forms.py index dffe1a2a28f6..6375e30c51c6 100644 --- a/common/djangoapps/student/forms.py +++ b/common/djangoapps/student/forms.py @@ -22,6 +22,7 @@ from openedx.core.djangoapps.theming.helpers import get_current_site from openedx.core.djangoapps.user_api import accounts as accounts_settings from openedx.core.djangoapps.user_api.accounts.utils import is_secondary_email_feature_enabled +from openedx.core.djangoapps.user_authn.utils import should_redirect_to_logistration_mircrofrontend from openedx.core.djangoapps.user_api.preferences.api import get_user_preference from student.message_types import AccountRecovery as AccountRecoveryMessage from student.models import CourseEnrollmentAllowed, email_exists_or_retired @@ -38,13 +39,15 @@ def send_account_recovery_email_for_user(user, request, email=None): """ site = get_current_site() message_context = get_base_template_context(site) + site_name = settings.LOGISTRATION_MICROFRONTEND_DOMAIN if should_redirect_to_logistration_mircrofrontend() \ + else configuration_helpers.get_value('SITE_NAME', settings.SITE_NAME) message_context.update({ 'request': request, # Used by google_analytics_tracking_pixel 'email': email, 'platform_name': configuration_helpers.get_value('PLATFORM_NAME', settings.PLATFORM_NAME), 'reset_link': '{protocol}://{site}{link}?is_account_recovery=true'.format( protocol='https' if request.is_secure() else 'http', - site=configuration_helpers.get_value('SITE_NAME', settings.SITE_NAME), + site=site_name, link=reverse('password_reset_confirm', kwargs={ 'uidb36': int_to_base36(user.id), 'token': default_token_generator.make_token(user), diff --git a/lms/envs/common.py b/lms/envs/common.py index cf147b1876c7..1d7f333438bd 100644 --- a/lms/envs/common.py +++ b/lms/envs/common.py @@ -4009,6 +4009,7 @@ def _make_locale_paths(settings): # pylint: disable=missing-function-docstring ORDER_HISTORY_MICROFRONTEND_URL = None ACCOUNT_MICROFRONTEND_URL = None LOGISTRATION_MICROFRONTEND_URL = None +LOGISTRATION_MICROFRONTEND_DOMAIN = None PROGRAM_CONSOLE_MICROFRONTEND_URL = None LEARNING_MICROFRONTEND_URL = None diff --git a/lms/envs/devstack.py b/lms/envs/devstack.py index 06a8e59631ec..769228ef17cb 100644 --- a/lms/envs/devstack.py +++ b/lms/envs/devstack.py @@ -332,6 +332,7 @@ def should_show_debug_toolbar(request): LEARNING_MICROFRONTEND_URL = 'http://localhost:2000' ACCOUNT_MICROFRONTEND_URL = 'http://localhost:1997' LOGISTRATION_MICROFRONTEND_URL = 'http://localhost:1999' +LOGISTRATION_MICROFRONTEND_DOMAIN = 'localhost:1999' ############## Docker based devstack settings ####################### diff --git a/lms/envs/test.py b/lms/envs/test.py index f0a5163a952d..5379b0b2840c 100644 --- a/lms/envs/test.py +++ b/lms/envs/test.py @@ -572,6 +572,7 @@ ORDER_HISTORY_MICROFRONTEND_URL = "http://order-history-mfe/" ACCOUNT_MICROFRONTEND_URL = "http://account-mfe/" LOGISTRATION_MICROFRONTEND_URL = "http://logistation-mfe" +LOGISTRATION_MICROFRONTEND_DOMAIN = "logistation-mfe" LEARNING_MICROFRONTEND_URL = "http://learning-mfe" ########################## limiting dashboard courses ###################### diff --git a/openedx/core/djangoapps/user_authn/views/password_reset.py b/openedx/core/djangoapps/user_authn/views/password_reset.py index 3031c5cd32cd..76990c3b8d03 100644 --- a/openedx/core/djangoapps/user_authn/views/password_reset.py +++ b/openedx/core/djangoapps/user_authn/views/password_reset.py @@ -34,6 +34,7 @@ from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers from openedx.core.djangoapps.theming.helpers import get_current_request, get_current_site from openedx.core.djangoapps.user_api import accounts, errors, helpers +from openedx.core.djangoapps.user_authn.utils import should_redirect_to_logistration_mircrofrontend from openedx.core.djangoapps.user_api.accounts.utils import is_secondary_email_feature_enabled from openedx.core.djangoapps.user_api.helpers import FormDescription from openedx.core.djangoapps.user_api.models import UserRetirementRequest @@ -145,13 +146,15 @@ def send_password_reset_email_for_user(user, request, preferred_email=None): preferred_email (str): Send email to this address if present, otherwise fallback to user's email address. """ message_context, user_language_preference = get_user_default_email_params(user) + site_name = settings.LOGISTRATION_MICROFRONTEND_DOMAIN if should_redirect_to_logistration_mircrofrontend() \ + else configuration_helpers.get_value('SITE_NAME', settings.SITE_NAME) message_context.update({ 'request': request, # Used by google_analytics_tracking_pixel # TODO: This overrides `platform_name` from `get_base_template_context` to make the tests passes 'platform_name': configuration_helpers.get_value('PLATFORM_NAME', settings.PLATFORM_NAME), 'reset_link': '{protocol}://{site}{link}?track=pwreset'.format( protocol='https' if request.is_secure() else 'http', - site=configuration_helpers.get_value('SITE_NAME', settings.SITE_NAME), + site=site_name, link=reverse('password_reset_confirm', kwargs={ 'uidb36': int_to_base36(user.id), 'token': default_token_generator.make_token(user), diff --git a/openedx/core/djangoapps/user_authn/views/tests/test_reset_password.py b/openedx/core/djangoapps/user_authn/views/tests/test_reset_password.py index 94aa2a0662b5..494a6045681d 100644 --- a/openedx/core/djangoapps/user_authn/views/tests/test_reset_password.py +++ b/openedx/core/djangoapps/user_authn/views/tests/test_reset_password.py @@ -26,7 +26,6 @@ from mock import Mock, patch from oauth2_provider import models as dot_models from pytz import UTC -from six.moves import range from openedx.core.djangoapps.oauth_dispatch.tests import factories as dot_factories from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers @@ -47,6 +46,10 @@ from util.testing import EventTestMixin +ENABLE_LOGISTRATION_MICROFRONTEND = settings.FEATURES.copy() +ENABLE_LOGISTRATION_MICROFRONTEND['ENABLE_LOGISTRATION_MICROFRONTEND'] = True + + def process_request(request): middleware = SessionMiddleware() middleware.process_request(request) @@ -327,6 +330,7 @@ def test_reset_password_email_https(self, is_secure, protocol): SETTING_CHANGE_INITIATED, user_id=self.user.id, setting=u'password', old=None, new=None ) + @override_settings(FEATURES=ENABLE_LOGISTRATION_MICROFRONTEND) @unittest.skipUnless(settings.ROOT_URLCONF == 'lms.urls', "Test only valid in LMS") @ddt.data(('Crazy Awesome Site', 'Crazy Awesome Site'), ('edX', 'edX')) @ddt.unpack @@ -350,6 +354,7 @@ def test_reset_password_email_site(self, site_name, platform_name): reset_msg = reset_msg.format(site_name) self.assertIn(reset_msg, msg) + self.assertIn(settings.LOGISTRATION_MICROFRONTEND_URL, msg) sign_off = u"The {} Team".format(platform_name) self.assertIn(sign_off, msg)