Merge pull request #27334 from edx/aehsan/Van-434/cta_dialogue_box_added

CTA dialogue added
This commit is contained in:
Adeel Ehsan
2021-05-07 05:42:56 +05:00
committed by GitHub
11 changed files with 174 additions and 6 deletions

View File

@@ -9,6 +9,9 @@ from django.conf import settings
from django.urls import reverse
from rest_framework.test import APITestCase
from common.djangoapps.student.models import Registration
from common.djangoapps.student.tests.factories import UserFactory
from openedx.core.djangoapps.user_api.tests.test_views import UserAPITestCase
from openedx.core.djangolib.testing.utils import skip_unless_lms
from common.djangoapps.third_party_auth import pipeline
from common.djangoapps.third_party_auth.tests.testutil import ThirdPartyAuthTestMixin, simulate_running_pipeline
@@ -175,3 +178,32 @@ class MFEContextViewTest(ThirdPartyAuthTestMixin, APITestCase):
assert response.status_code == 200
assert response.data['countryCode'] == self.country_code
@skip_unless_lms
class SendAccountActivationEmail(UserAPITestCase):
"""
Test for send activation email view
"""
def setUp(self):
"""
Create a user, then log in.
"""
super().setUp()
self.user = UserFactory()
Registration().register(self.user)
result = self.client.login(username=self.user.username, password="test")
assert result, 'Could not log in'
self.path = reverse('send_account_activation_email')
@patch('common.djangoapps.student.views.management.compose_activation_email')
def test_send_email_to_inactive_user_via_cta_dialog(self, email):
"""
Tests when user clicks on resend activation email on CTA dialog box, system
sends an activation email to the user.
"""
self.user.is_active = False
self.user.save()
self.client.post(self.path)
assert email.called is True, 'method should have been called'

View File

@@ -3,10 +3,14 @@ Authn API urls
"""
from django.conf.urls import url
from openedx.core.djangoapps.user_authn.api.views import MFEContextView
from openedx.core.djangoapps.user_authn.api.views import MFEContextView, SendAccountActivationEmail
urlpatterns = [
url(r'^third_party_auth_context$', MFEContextView.as_view(), name='third_party_auth_context'),
url(r'^mfe_context$', MFEContextView.as_view(), name='mfe_context'),
url(
r'^send_account_activation_email$',
SendAccountActivationEmail.as_view(),
name='send_account_activation_email'
),
]

View File

@@ -7,9 +7,12 @@ from rest_framework import status
from rest_framework.response import Response
from rest_framework.throttling import AnonRateThrottle
from rest_framework.views import APIView
from rest_framework.permissions import IsAuthenticated
from edx_rest_framework_extensions.auth.session.authentication import SessionAuthenticationAllowInactiveUser
from common.djangoapps.student.helpers import get_next_url_for_login_page
from openedx.core.djangoapps.user_authn.views.utils import get_mfe_context
from common.djangoapps.student.views import compose_and_send_activation_email
class MFEContextThrottle(AnonRateThrottle):
@@ -45,3 +48,30 @@ class MFEContextView(APIView):
status=status.HTTP_200_OK,
data=context
)
class SendAccountActivationEmail(APIView):
"""
API to to send the account activation email using account activation cta.
"""
authentication_classes = (SessionAuthenticationAllowInactiveUser,)
permission_classes = (IsAuthenticated,)
def post(self, request, **kwargs): # lint-amnesty, pylint: disable=unused-argument
"""
Returns status code.
Arguments:
request (HttpRequest): The request, used to get the user
"""
try:
user = request.user
if not user.is_active:
compose_and_send_activation_email(user, user.profile)
return Response(
status=status.HTTP_200_OK
)
except Exception: # pylint: disable=broad-except
return Response(
status=status.HTTP_500_INTERNAL_SERVER_ERROR
)

View File

@@ -536,6 +536,13 @@ class RegistrationView(APIView):
redirect_url = get_redirect_url_with_host(root_url, redirect_to)
response = self._create_response(request, {}, status_code=200, redirect_url=redirect_url)
set_logged_in_cookies(request, response, user)
if not user.is_active:
response.set_cookie(
settings.SHOW_ACTIVATE_CTA_POPUP_COOKIE_NAME,
True,
domain=settings.SESSION_COOKIE_DOMAIN,
secure=request.is_secure()
) # setting the cookie to show account activation dialogue in platform and learning MFE
return response
def _handle_duplicate_email_username(self, request, data):