From daa52f3ba924cd98ef724ad4689db4d234b9eae5 Mon Sep 17 00:00:00 2001 From: Mubbshar Anwar <78487564+mubbsharanwar@users.noreply.github.com> Date: Tue, 25 Jul 2023 11:56:33 +0500 Subject: [PATCH] feat: embedded form redirection experience (#32814) Redirection for embedded registration experience VAN-1535 --- openedx/core/djangoapps/user_authn/api/tests/data_mock.py | 4 ++++ .../core/djangoapps/user_authn/api/tests/test_views.py | 8 ++++++-- openedx/core/djangoapps/user_authn/api/views.py | 8 +++++++- openedx/core/djangoapps/user_authn/serializers.py | 1 + 4 files changed, 18 insertions(+), 3 deletions(-) diff --git a/openedx/core/djangoapps/user_authn/api/tests/data_mock.py b/openedx/core/djangoapps/user_authn/api/tests/data_mock.py index c5c1c317e1..ffb9ad11b2 100644 --- a/openedx/core/djangoapps/user_authn/api/tests/data_mock.py +++ b/openedx/core/djangoapps/user_authn/api/tests/data_mock.py @@ -37,6 +37,7 @@ MFE_CONTEXT_WITH_TPA_DATA = { 'autoSubmitRegForm': False, 'syncLearnerProfileData': False, 'countryCode': '', + 'welcomePageRedirectUrl': '', 'pipeline_user_details': { 'username': 'test123', 'email': 'test123@edx.com', @@ -59,6 +60,7 @@ SERIALIZED_MFE_CONTEXT_WITH_TPA_DATA = { 'autoSubmitRegForm': False, 'syncLearnerProfileData': False, 'countryCode': '', + 'welcomePageRedirectUrl': '', 'pipelineUserDetails': { 'username': 'test123', 'email': 'test123@edx.com', @@ -85,6 +87,7 @@ MFE_CONTEXT_WITHOUT_TPA_DATA = { 'autoSubmitRegForm': False, 'syncLearnerProfileData': False, 'countryCode': '', + 'welcomePageRedirectUrl': '', 'pipeline_user_details': {} } } @@ -101,6 +104,7 @@ SERIALIZED_MFE_CONTEXT_WITHOUT_TPA_DATA = { 'autoSubmitRegForm': False, 'syncLearnerProfileData': False, 'countryCode': '', + 'welcomePageRedirectUrl': '', 'pipelineUserDetails': {} }, 'registrationFields': {}, diff --git a/openedx/core/djangoapps/user_authn/api/tests/test_views.py b/openedx/core/djangoapps/user_authn/api/tests/test_views.py index c1947e2939..bd3ab92fc3 100644 --- a/openedx/core/djangoapps/user_authn/api/tests/test_views.py +++ b/openedx/core/djangoapps/user_authn/api/tests/test_views.py @@ -117,6 +117,7 @@ class MFEContextViewTest(ThirdPartyAuthTestMixin, APITestCase): 'autoSubmitRegForm': False, 'syncLearnerProfileData': False, 'countryCode': self.country_code, + 'welcomePageRedirectUrl': None, 'pipelineUserDetails': self.pipeline_user_details, }, 'registrationFields': {}, @@ -391,16 +392,19 @@ class MFEContextViewTest(ThirdPartyAuthTestMixin, APITestCase): @override_settings( ENABLE_DYNAMIC_REGISTRATION_FIELDS=True, REGISTRATION_EXTRA_FIELDS={'specialty': 'optional', 'goals': 'optional'}, + LOGIN_REDIRECT_WHITELIST=['openedx.service'], ) def test_welcome_page_context(self): """ Test MFE Context API response for welcome page """ - self.query_params.update({'is_welcome_page': True}) - response = self.client.get(self.url, self.query_params) + redirect_url = 'https://openedx.service/coolpage' + self.query_params.update({'is_welcome_page': True, 'next': redirect_url}) + response = self.client.get(self.url, self.query_params, HTTP_ACCEPT='*/*') assert response.status_code == status.HTTP_200_OK assert list(response.data['optionalFields']['fields'].keys()) == ['specialty', 'goals'] assert list(response.data['optionalFields']['extended_profile']) == ['specialty'] + assert response.data['contextData']['welcomePageRedirectUrl'] == redirect_url @skip_unless_lms diff --git a/openedx/core/djangoapps/user_authn/api/views.py b/openedx/core/djangoapps/user_authn/api/views.py index f190ab565a..b4f04fd466 100644 --- a/openedx/core/djangoapps/user_authn/api/views.py +++ b/openedx/core/djangoapps/user_authn/api/views.py @@ -81,10 +81,16 @@ class MFEContextView(APIView): if settings.ENABLE_DYNAMIC_REGISTRATION_FIELDS: if request_params.get('is_welcome_page'): optional_fields = self._get_optional_fields_context() + context = { + 'context_data': { + 'welcomePageRedirectUrl': redirect_to if redirect_to == request_params.get('next') else None, + }, + 'optional_fields': optional_fields, + } return Response( status=status.HTTP_200_OK, data=MFEContextSerializer( - {'optional_fields': optional_fields} if optional_fields else {} + context if optional_fields else {} ).data ) diff --git a/openedx/core/djangoapps/user_authn/serializers.py b/openedx/core/djangoapps/user_authn/serializers.py index 9bbed367e6..c088b7eda7 100644 --- a/openedx/core/djangoapps/user_authn/serializers.py +++ b/openedx/core/djangoapps/user_authn/serializers.py @@ -53,6 +53,7 @@ class ContextDataSerializer(serializers.Serializer): autoSubmitRegForm = serializers.BooleanField(default=False) syncLearnerProfileData = serializers.BooleanField(default=False) countryCode = serializers.CharField(allow_null=True) + welcomePageRedirectUrl = serializers.CharField(allow_null=True) pipelineUserDetails = serializers.SerializerMethodField() def get_pipelineUserDetails(self, obj):