Add query param to account activation redirect (#26107)
This commit is contained in:
@@ -15,6 +15,10 @@ from common.djangoapps.student.models import Registration
|
||||
from common.djangoapps.student.tests.factories import UserFactory
|
||||
|
||||
|
||||
FEATURES_WITH_LOGIN_MFE_ENABLED = settings.FEATURES.copy()
|
||||
FEATURES_WITH_LOGIN_MFE_ENABLED['ENABLE_LOGISTRATION_MICROFRONTEND'] = True
|
||||
|
||||
|
||||
@unittest.skipUnless(settings.ROOT_URLCONF == 'lms.urls', 'Test only valid in lms')
|
||||
class TestActivateAccount(TestCase):
|
||||
"""Tests for account creation"""
|
||||
@@ -146,3 +150,27 @@ class TestActivateAccount(TestCase):
|
||||
response = self.client.get(reverse('activate', args=[uuid4().hex]), follow=True)
|
||||
self.assertRedirects(response, login_page_url)
|
||||
self.assertContains(response, 'Your account could not be activated')
|
||||
|
||||
@override_settings(FEATURES=FEATURES_WITH_LOGIN_MFE_ENABLED)
|
||||
def test_unauthenticated_user_redirects_to_mfe(self):
|
||||
"""
|
||||
Verify that if Authn MFE is enabled then authenticated user redirects to
|
||||
login page with correct query param.
|
||||
"""
|
||||
login_page_url = "{authn_mfe}/login?account_activation_status=".format(
|
||||
authn_mfe=settings.LOGISTRATION_MICROFRONTEND_URL
|
||||
)
|
||||
|
||||
self._assert_user_active_state(expected_active_state=False)
|
||||
|
||||
# Access activation link, the user is redirected to login page with success query param
|
||||
response = self.client.get(reverse('activate', args=[self.registration.activation_key]))
|
||||
self.assertEqual(response.url, login_page_url + 'success')
|
||||
|
||||
# Access activation link again, the user is redirected to login page with info query param
|
||||
response = self.client.get(reverse('activate', args=[self.registration.activation_key]))
|
||||
self.assertEqual(response.url, login_page_url + 'info')
|
||||
|
||||
# Open account activation page with an invalid activation link, the query param should contain error
|
||||
response = self.client.get(reverse('activate', args=[uuid4().hex]))
|
||||
self.assertEqual(response.url, login_page_url + 'error')
|
||||
|
||||
@@ -50,6 +50,7 @@ from openedx.core.djangoapps.programs.models import ProgramsApiConfig
|
||||
from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers
|
||||
from openedx.core.djangoapps.theming import helpers as theming_helpers
|
||||
from openedx.core.djangoapps.user_api.preferences import api as preferences_api
|
||||
from openedx.core.djangoapps.user_authn.utils import should_redirect_to_logistration_mircrofrontend
|
||||
from openedx.core.djangolib.markup import HTML, Text
|
||||
from common.djangoapps.student.helpers import DISABLE_UNENROLL_CERT_STATES, cert_info, generate_activation_email_context
|
||||
from common.djangoapps.student.message_types import AccountActivation, EmailChange, EmailChangeConfirmation, RecoveryEmailCreate
|
||||
@@ -492,9 +493,11 @@ def activate_account(request, key):
|
||||
# TODO: Use custom attribute to determine if there are any `activate_account` calls for cms in Production.
|
||||
# If not, the templates wouldn't be needed for cms, but we still need a way to activate for cms tests.
|
||||
monitoring_utils.set_custom_attribute('student_activate_account', 'lms')
|
||||
activation_message_type = None
|
||||
try:
|
||||
registration = Registration.objects.get(activation_key=key)
|
||||
except (Registration.DoesNotExist, Registration.MultipleObjectsReturned):
|
||||
activation_message_type = 'error'
|
||||
messages.error(
|
||||
request,
|
||||
HTML(_(
|
||||
@@ -511,6 +514,7 @@ def activate_account(request, key):
|
||||
)
|
||||
else:
|
||||
if registration.user.is_active:
|
||||
activation_message_type = 'info'
|
||||
messages.info(
|
||||
request,
|
||||
HTML(_('{html_start}This account has already been activated.{html_end}')).format(
|
||||
@@ -533,6 +537,7 @@ def activate_account(request, key):
|
||||
)
|
||||
|
||||
# Add message for later use.
|
||||
activation_message_type = 'success'
|
||||
messages.success(
|
||||
request,
|
||||
HTML(message).format(
|
||||
@@ -542,6 +547,10 @@ def activate_account(request, key):
|
||||
extra_tags='account-activation aa-icon',
|
||||
)
|
||||
|
||||
if should_redirect_to_logistration_mircrofrontend() and not request.user.is_authenticated:
|
||||
url_path = '/login?account_activation_status={}'.format(activation_message_type)
|
||||
return redirect(settings.LOGISTRATION_MICROFRONTEND_URL + url_path)
|
||||
|
||||
return redirect('dashboard')
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user