Commit cd56cc56 by Matt Drayer Committed by GitHub

Merge pull request #15030 from edx/mattdrayer/ENT-318

ENT-318: Update activation email subject and message text
parents 3aba9da8 5e94c63d
......@@ -94,6 +94,8 @@ from lms.envs.common import (
HELP_TOKENS_BOOKS,
SUPPORT_SITE_LINK,
CONTACT_EMAIL,
)
from path import Path as path
from warnings import simplefilter
......
......@@ -6,7 +6,7 @@ import mock
from student.tests.factories import UserFactory, RegistrationFactory, PendingEmailChangeFactory
from student.views import (
reactivation_email_for_user, do_email_change_request, confirm_email_change,
validate_new_email, SETTING_CHANGE_INITIATED
validate_new_email, SETTING_CHANGE_INITIATED, generate_activation_email_context
)
from student.models import UserProfile, PendingEmailChange, Registration
from third_party_auth.views import inactive_user_view
......@@ -72,16 +72,16 @@ class EmailTestMixin(object):
class ActivationEmailTests(TestCase):
"""Test sending of the activation email. """
ACTIVATION_SUBJECT = u"Activate Your {} Account".format(settings.PLATFORM_NAME)
ACTIVATION_SUBJECT = u"Action Required: Activate your {} account".format(settings.PLATFORM_NAME)
# Text fragments we expect in the body of an email
# sent from an OpenEdX installation.
OPENEDX_FRAGMENTS = [
u"Thank you for creating an account with {platform}!".format(platform=settings.PLATFORM_NAME),
u"high-quality {platform} courses".format(platform=settings.PLATFORM_NAME),
"http://edx.org/activate/",
(
"Check the help section of the "
u"{platform} website".format(platform=settings.PLATFORM_NAME)
"please use our web form at "
u"{support_url} ".format(support_url=settings.SUPPORT_SITE_LINK)
)
]
......@@ -170,10 +170,7 @@ class ReactivationEmailTests(EmailTestMixin, TestCase):
def assertReactivateEmailSent(self, email_user):
"""Assert that the correct reactivation email has been sent"""
context = {
'name': self.user.profile.name,
'key': self.registration.activation_key
}
context = generate_activation_email_context(self.user, self.registration)
self.assertEmailUser(
email_user,
......
......@@ -583,6 +583,24 @@ def is_course_blocked(request, redeemed_registration_codes, course_key):
return blocked
def generate_activation_email_context(user, registration):
"""
Constructs a dictionary for use in activation email contexts
Arguments:
user (User): Currently logged-in user
registration (Registration): Registration object for the currently logged-in user
"""
return {
'name': user.profile.name,
'key': registration.activation_key,
'lms_url': configuration_helpers.get_value('LMS_ROOT_URL', settings.LMS_ROOT_URL),
'platform_name': configuration_helpers.get_value('PLATFORM_NAME', settings.PLATFORM_NAME),
'support_url': configuration_helpers.get_value('SUPPORT_SITE_LINK', settings.SUPPORT_SITE_LINK),
'support_email': configuration_helpers.get_value('CONTACT_EMAIL', settings.CONTACT_EMAIL),
}
def compose_and_send_activation_email(user, profile, user_registration=None):
"""
Construct all the required params and send the activation email
......@@ -596,10 +614,7 @@ def compose_and_send_activation_email(user, profile, user_registration=None):
dest_addr = user.email
if user_registration is None:
user_registration = Registration.objects.get(user=user)
context = {
'name': profile.name,
'key': user_registration.activation_key,
}
context = generate_activation_email_context(user, user_registration)
subject = render_to_string('emails/activation_email_subject.txt', context)
# Email subject *must not* contain newlines
subject = ''.join(subject.splitlines())
......@@ -2484,7 +2499,7 @@ def password_reset_confirm_wrapper(request, uidb36=None, token=None):
def reactivation_email_for_user(user):
try:
reg = Registration.objects.get(user=user)
registration = Registration.objects.get(user=user)
except Registration.DoesNotExist:
return JsonResponse({
"success": False,
......@@ -2492,10 +2507,7 @@ def reactivation_email_for_user(user):
}) # TODO: this should be status code 400 # pylint: disable=fixme
try:
context = {
'name': user.profile.name,
'key': reg.activation_key,
}
context = generate_activation_email_context(user, registration)
except ObjectDoesNotExist:
log.error(
u'Unable to send reactivation email due to unavailable profile for the user "%s"',
......@@ -2511,6 +2523,7 @@ def reactivation_email_for_user(user):
subject = ''.join(subject.splitlines())
message = render_to_string('emails/activation_email.txt', context)
from_address = configuration_helpers.get_value('email_from_address', settings.DEFAULT_FROM_EMAIL)
from_address = configuration_helpers.get_value('ACTIVATION_EMAIL_FROM_ADDRESS', from_address)
try:
user.email_user(subject, message, from_address)
......
......@@ -234,6 +234,9 @@ PRESS_EMAIL = ENV_TOKENS.get('PRESS_EMAIL', PRESS_EMAIL)
CONTACT_MAILING_ADDRESS = ENV_TOKENS.get('CONTACT_MAILING_ADDRESS', CONTACT_MAILING_ADDRESS)
# Account activation email sender address
ACTIVATION_EMAIL_FROM_ADDRESS = ENV_TOKENS.get('ACTIVATION_EMAIL_FROM_ADDRESS', ACTIVATION_EMAIL_FROM_ADDRESS)
# Currency
PAID_COURSE_REGISTRATION_CURRENCY = ENV_TOKENS.get('PAID_COURSE_REGISTRATION_CURRENCY',
PAID_COURSE_REGISTRATION_CURRENCY)
......
......@@ -838,6 +838,9 @@ FINANCE_EMAIL = ''
# Platform mailing address
CONTACT_MAILING_ADDRESS = ''
# Account activation email sender address
ACTIVATION_EMAIL_FROM_ADDRESS = ''
ADMINS = ()
MANAGERS = ADMINS
......
......@@ -443,6 +443,7 @@ MICROSITE_CONFIGURATION = {
"platform_name": "Test Site",
"logo_image_url": "test_site/images/header-logo.png",
"email_from_address": "test_site@edx.org",
"ACTIVATION_EMAIL_FROM_ADDRESS": "test_activate@edx.org",
"payment_support_email": "test_site@edx.org",
"ENABLE_MKTG_SITE": False,
"SITE_NAME": "test_site.localhost",
......@@ -474,6 +475,7 @@ MICROSITE_CONFIGURATION = {
"platform_name": "Test logistration",
"logo_image_url": "test_site/images/header-logo.png",
"email_from_address": "test_site@edx.org",
"ACTIVATION_EMAIL_FROM_ADDRESS": "test_activate@edx.org",
"payment_support_email": "test_site@edx.org",
"ENABLE_MKTG_SITE": False,
"ENABLE_COMBINED_LOGIN_REGISTRATION": True,
......@@ -596,3 +598,5 @@ LMS_ROOT_URL = "http://localhost:8000"
ECOMMERCE_API_URL = 'https://ecommerce.example.com/api/v2/'
ENTERPRISE_API_URL = 'http://enterprise.example.com/enterprise/api/v1/'
ACTIVATION_EMAIL_FROM_ADDRESS = 'test_activate@edx.org'
<%! from django.utils.translation import ugettext as _ %>
<%! from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers %>
${_("Thank you for creating an account with {platform_name}!").format(
platform_name=configuration_helpers.get_value('PLATFORM_NAME', settings.PLATFORM_NAME)
)}
${_("There's just one more step before you can enroll in a course: "
"you need to activate your {platform_name} account. To activate "
"your account, click the following link. If that doesn't work, "
"copy and paste the link into your browser's address bar.").format(
platform_name=configuration_helpers.get_value('PLATFORM_NAME', settings.PLATFORM_NAME)
)}
${_("You're almost there! Use the link to activate your account to access engaging, high-quality "
"{platform_name} courses. Note that you will not be able to log back into your account until "
"you have activated it.").format(platform_name=platform_name)}
% if is_secure:
https://${ site }/activate/${ key }
% else:
http://${ site }/activate/${ key }
% endif
${_("If you didn't create an account, you don't need to do anything; you "
"won't receive any more email from us. If you need assistance, please "
"do not reply to this email message. Check the help section of the "
"{platform_name} website.").format(platform_name=configuration_helpers.get_value('PLATFORM_NAME', settings.PLATFORM_NAME))}
${_("Enjoy learning with {platform_name}.").format(platform_name=platform_name)}
${_("The {platform_name} Team").format(platform_name=platform_name)}
${_("If you need help, please use our web form at {support_url} or email {support_email}.").format(
support_url=support_url, support_email=support_email
)}
${_("This email message was automatically sent by {lms_url} because someone attempted to create an "
"account on {platform_name} using this email address.").format(
lms_url=lms_url, platform_name=platform_name
)}
\ No newline at end of file
<%! from django.utils.translation import ugettext as _ %>
<%! from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers %>
${_("Activate Your {platform_name} Account").format(
platform_name=configuration_helpers.get_value('PLATFORM_NAME', settings.PLATFORM_NAME
))}
${_("Action Required: Activate your {platform_name} account").format(platform_name=platform_name)}
......@@ -53,6 +53,7 @@ class InterceptErrorsTest(TestCase):
@mock.patch('openedx.core.djangoapps.user_api.helpers.LOGGER')
def test_logs_errors(self, mock_logger):
self.maxDiff = None
exception = 'openedx.core.djangoapps.user_api.tests.test_helpers.FakeInputException'
expected_log_msg = (
u"An unexpected error occurred when calling 'intercepted_function' with arguments '()' and "
......
......@@ -1625,10 +1625,10 @@ class RegistrationViewTest(ThirdPartyAuthTestMixin, UserAPITestCase):
self.assertEqual(sent_email.to, [self.EMAIL])
self.assertEqual(
sent_email.subject,
u"Activate Your {platform} Account".format(platform=settings.PLATFORM_NAME)
u"Action Required: Activate your {platform} account".format(platform=settings.PLATFORM_NAME)
)
self.assertIn(
u"you need to activate your {platform} account".format(platform=settings.PLATFORM_NAME),
u"high-quality {platform} courses".format(platform=settings.PLATFORM_NAME),
sent_email.body
)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment