Skip to content

Commit

Permalink
Adds Logistration MFE url for forgot password email.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
adeelkhan committed Oct 29, 2020
1 parent 7afee25 commit d61936f
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 3 deletions.
5 changes: 4 additions & 1 deletion common/djangoapps/student/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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),
Expand Down
1 change: 1 addition & 0 deletions lms/envs/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions lms/envs/devstack.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 #######################

Expand Down
1 change: 1 addition & 0 deletions lms/envs/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 ######################
Expand Down
5 changes: 4 additions & 1 deletion openedx/core/djangoapps/user_authn/views/password_reset.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down

0 comments on commit d61936f

Please sign in to comment.