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

@@ -2416,3 +2416,6 @@ DEFAULT_EMAIL_LOGO_URL = 'https://edx-cdn.org/v3/default/logo.png'
############## Settings for course import olx validation ############################
COURSE_OLX_VALIDATION_STAGE = 1
COURSE_OLX_VALIDATION_IGNORE_LIST = None
################# show account activate cta after register ########################
SHOW_ACTIVATE_CTA_POPUP_COOKIE_NAME = 'show-account-activation-popup'

View File

@@ -26,8 +26,7 @@ from common.djangoapps.student.views import (
SETTING_CHANGE_INITIATED,
confirm_email_change,
do_email_change_request,
validate_new_email
)
validate_new_email)
from common.djangoapps.third_party_auth.views import inactive_user_view
from common.djangoapps.util.testing import EventTestMixin
from lms.djangoapps.courseware.toggles import COURSEWARE_PROCTORING_IMPROVEMENTS

View File

@@ -741,6 +741,8 @@ def student_dashboard(request): # lint-amnesty, pylint: disable=too-many-statem
enr for enr in course_enrollments if entitlement.enrollment_course_run.course_id != enr.course_id
]
show_account_activation_popup = request.COOKIES.get(settings.SHOW_ACTIVATE_CTA_POPUP_COOKIE_NAME, None)
context = {
'urls': urls,
'programs_data': programs_data,
@@ -772,6 +774,7 @@ def student_dashboard(request): # lint-amnesty, pylint: disable=too-many-statem
'denied_banner': denied_banner,
'billing_email': settings.PAYMENT_SUPPORT_EMAIL,
'user': user,
'show_account_activation_popup': show_account_activation_popup,
'logout_url': reverse('logout'),
'platform_name': platform_name,
'enrolled_courses_either_paid': enrolled_courses_either_paid,
@@ -826,4 +829,8 @@ def student_dashboard(request): # lint-amnesty, pylint: disable=too-many-statem
'resume_button_urls': resume_button_urls
})
return render_to_response('dashboard.html', context)
response = render_to_response('dashboard.html', context)
if show_account_activation_popup:
response.delete_cookie(settings.SHOW_ACTIVATE_CTA_POPUP_COOKIE_NAME)
return response

View File

@@ -4672,3 +4672,6 @@ DEFAULT_EMAIL_LOGO_URL = 'https://edx-cdn.org/v3/default/logo.png'
################# Settings for olx validation. #################
COURSE_OLX_VALIDATION_STAGE = 1
COURSE_OLX_VALIDATION_IGNORE_LIST = None
################# show account activate cta after register ########################
SHOW_ACTIVATE_CTA_POPUP_COOKIE_NAME = 'show-account-activation-popup'

View File

@@ -224,6 +224,29 @@
return false;
});
$('#send_cta_email').click(function(e) {
$.ajax({
type: 'POST',
url: urls.sendAccountActivationEmail,
data: $(this).serializeArray()
});
e.preventDefault();
$('#activate-account-modal').css('display', 'none');
$('#lean_overlay').css({display: 'none'});
});
$('#activate-account-modal').on('click', '#button', function() {
$('#activate-account-modal').css('display', 'none');
$('#lean_overlay').css({display: 'none'});
});
if ($('#activate-account-modal').css('display') === 'block') {
$('#lean_overlay').css({
display: 'block',
'z-index': 0
});
}
$('.action-email-settings').each(function(index) {
$(this).attr('id', 'email-settings-' + index);
// a bit of a hack, but gets the unique selector for the modal trigger

View File

@@ -1636,6 +1636,41 @@ a.fade-cover {
}
}
#activate-account-modal {
display: block;
position: fixed;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
margin-top: -60px;
text-align: left;
height: 252px;
width: 450px;
box-shadow: none;
background: none;
.inner-wrapper {
h3 {
padding: 1.5rem 1rem 1rem 1rem;
text-align: left;
font-weight: bold;
font-size: 1.3rem;
line-height: 1.75rem;
}
border: none;
border-radius: 5px;
}
}
.activate-account-modal-button {
text-align: right;
display: block;
padding: 1rem 1rem 1rem 0;
}
.activate-account-modal-body {
padding: 0 1rem;
}
.reasons_survey {
margin: 20px;

View File

@@ -5,6 +5,7 @@
<%!
import pytz
import six
import logging
from datetime import datetime, timedelta
from django.urls import reverse
from django.utils.translation import ugettext as _
@@ -46,7 +47,8 @@ from common.djangoapps.student.models import CourseEnrollment
edx.dashboard.legacy.init({
dashboard: "${reverse('dashboard') | n, js_escaped_string}",
signInUser: "${reverse('signin_user') | n, js_escaped_string}",
changeEmailSettings: "${reverse('change_email_settings') | n, js_escaped_string}"
changeEmailSettings: "${reverse('change_email_settings') | n, js_escaped_string}",
sendAccountActivationEmail: "${reverse('send_account_activation_email') | n, js_escaped_string}"
});
});
</script>
@@ -314,6 +316,29 @@ from common.djangoapps.student.models import CourseEnrollment
</div>
</div>
</main>
%if show_account_activation_popup:
<div id="activate-account-modal" class="modal activate-account-modal" aria-hidden="true">
<div class="inner-wrapper" role="dialog" aria-labelledby="activate-account-modal-title" aria-live="polite">
<h3>
${_("Activate your account so you can log back in")}
<span class="sr">,
## Translators: this text gives status on if the modal interface (a menu or piece of UI that takes the full focus of the screen) is open or not
${_("window open")}
</span>
</h3>
<p class="activate-account-modal-body">${Text(_("We sent an email to {strong_start}{email}{strong_end} with a link to activate your account. Cant find it? Check your spam folder or {link_start}resend the email.{link_end}")).format(
strong_start=HTML('<strong>'),
email=user.email,
strong_end=HTML('</strong>'),
link_start=HTML('<a href="#" id="send_cta_email" >'),
link_end=HTML('</a>')
)}
</p>
<div class="activate-account-modal-button"><button class="btn btn-primary" id="button"> ${Text(_("Continue to {platform_name}")).format(platform_name=settings.PLATFORM_NAME)}</button></div>
</div>
</div>
%endif
<div id="email-settings-modal" class="modal" aria-hidden="true">
<div class="inner-wrapper" role="dialog" aria-labelledby="email-settings-title">

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):