diff --git a/common/djangoapps/student/tasks.py b/common/djangoapps/student/tasks.py index 1e96fe523e0bd97d5a0e2d0930e2f6819f843494..419ad550d029fa7d7316ed48a7835d76215f2506 100644 --- a/common/djangoapps/student/tasks.py +++ b/common/djangoapps/student/tasks.py @@ -8,18 +8,24 @@ import logging from celery.exceptions import MaxRetriesExceededError from celery.task import task # pylint: disable=no-name-in-module, import-error from django.conf import settings +from django.contrib.auth.models import User +from django.contrib.sites.models import Site from edx_ace import ace from edx_ace.errors import RecoverableChannelDeliveryError +from edx_ace.message import Message from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers +from openedx.core.lib.celery.task_utils import emulate_http_request log = logging.getLogger('edx.celery.task') @task(bind=True) -def send_activation_email(self, msg, from_address=None): +def send_activation_email(self, msg_string, from_address=None): """ Sending an activation email to the user. """ + msg = Message.from_string(msg_string) + max_retries = settings.RETRY_ACTIVATION_EMAIL_MAX_ATTEMPTS retries = self.request.retries @@ -31,8 +37,12 @@ def send_activation_email(self, msg, from_address=None): dest_addr = msg.recipient.email_address + site = Site.objects.get_current() + user = User.objects.get(username=msg.recipient.username) + try: - ace.send(msg) + with emulate_http_request(site=site, user=user): + ace.send(msg) # Log that the Activation Email has been sent to user without an exception log.info("Activation Email has been sent to User {user_email}".format( user_email=dest_addr diff --git a/common/djangoapps/student/tests/test_email.py b/common/djangoapps/student/tests/test_email.py index 4901c390b737f655f9dc722314e19924d3fd1b0b..7e0137dd8497fa3c5d750baf2f6f58a0c728d24f 100644 --- a/common/djangoapps/student/tests/test_email.py +++ b/common/djangoapps/student/tests/test_email.py @@ -31,7 +31,6 @@ from student.views import ( confirm_email_change, do_email_change_request, generate_activation_email_context, - send_reactivation_email_for_user, validate_new_email ) from third_party_auth.views import inactive_user_view @@ -104,7 +103,7 @@ class ActivationEmailTests(EmailTemplateTagMixin, CacheIsolationTestCase): # sent from an OpenEdX installation. OPENEDX_FRAGMENTS = [ ( - u"You're almost there! Use the link below to activate your account to access engaging, " + u"Use the link below to activate your account to access engaging, " u"high-quality {platform_name} courses. Note that you will not be able to log back into your " u"account until you have activated it.".format( platform_name=settings.PLATFORM_NAME diff --git a/common/djangoapps/student/tests/test_tasks.py b/common/djangoapps/student/tests/test_tasks.py index b14e8dc3e6e0ee431e0844912c17f9c0a1f6a6ef..bbebedc629ca84aa5768fe7ed11b49a38fab8e23 100644 --- a/common/djangoapps/student/tests/test_tasks.py +++ b/common/djangoapps/student/tests/test_tasks.py @@ -50,7 +50,7 @@ class SendActivationEmailTestCase(TestCase): from_address = 'task_testing@example.com' email_max_attempts = settings.RETRY_ACTIVATION_EMAIL_MAX_ATTEMPTS - send_activation_email.delay(self.msg, from_address=from_address) + send_activation_email.delay(str(self.msg), from_address=from_address) # Asserts sending email retry logging. for attempt in range(email_max_attempts): @@ -79,7 +79,7 @@ class SendActivationEmailTestCase(TestCase): """ from_address = 'task_testing@example.com' - send_activation_email.delay(self.msg, from_address=from_address) + send_activation_email.delay(str(self.msg), from_address=from_address) # Asserts that the error was logged mock_log.exception.assert_called_with( diff --git a/common/djangoapps/student/views/management.py b/common/djangoapps/student/views/management.py index 6cc3b60f32f67f171e68091d777aecb2533104bf..d4c481119ae9389b69106306e27c1e260e7e6bac 100644 --- a/common/djangoapps/student/views/management.py +++ b/common/djangoapps/student/views/management.py @@ -227,7 +227,7 @@ def compose_and_send_activation_email(user, profile, user_registration=None): root_url = configuration_helpers.get_value('LMS_ROOT_URL', settings.LMS_ROOT_URL) msg = compose_activation_email(root_url, user, user_registration, route_enabled, profile.name) - send_activation_email.delay(msg) + send_activation_email.delay(str(msg)) @login_required diff --git a/common/templates/student/edx_ace/accountactivation/email/body.html b/common/templates/student/edx_ace/accountactivation/email/body.html index d4497672da1a9d7590e96c33cd5faa24a467bd32..d6970cbba9a46e13927338b8c5c6f0c6a3d61e5d 100644 --- a/common/templates/student/edx_ace/accountactivation/email/body.html +++ b/common/templates/student/edx_ace/accountactivation/email/body.html @@ -1,5 +1,6 @@ {% extends 'ace_common/edx_ace/common/base_body.html' %} +{% load django_markup %} {% load i18n %} {% load static %} {% block content %} @@ -8,7 +9,9 @@ <tr> <td> <p style="color: rgba(0,0,0,.75);"> - {% blocktrans %}This is a routed Account Activation email for {{ routed_user }} ({{ routed_user_email }}): {{ routed_profile_name }}{% endblocktrans %} + {% filter force_escape %} + {% blocktrans %}This is a routed Account Activation email for {{ routed_user }} ({{ routed_user_email }}): {{ routed_profile_name }}{% endblocktrans %} + {% endfilter %} <br /> </p> </td> @@ -17,28 +20,35 @@ <tr> <td> <h1> - {% trans "Account Activation" %} + {% trans "Account Activation" as header_msg %}{{ header_msg | force_escape }} </h1> <p style="color: rgba(0,0,0,.75);"> - {% blocktrans %}You're almost there! Use the link below 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.{% endblocktrans %} + {% filter force_escape %} + {% blocktrans %}You're almost there! Use the link below 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.{% endblocktrans %} + {% endfilter %} <br /> </p> - {% trans "Activate Your Account" as course_cta_text %} + {% trans "Activate Your Account" as course_cta_text %}{{ course_cta_text | force_escape }} {% include "ace_common/edx_ace/common/return_to_course_cta.html" with course_cta_text=course_cta_text course_cta_url=confirm_activation_link %} </td> </tr> <tr> <td> <p style="color: rgba(0,0,0,.75);"> - {% blocktrans %}Enjoy learning with {{ platform_name }}.{% endblocktrans %} + {% filter force_escape %} + {% blocktrans %}Enjoy learning with {{ platform_name }}.{% endblocktrans %} + {% endfilter %} <br /> </p> </td> </tr> <td> <p style="color: rgba(0,0,0,.75);"> - {% blocktrans %}If you need help, please use our web form at <a href="{{ support_url }}">{{ support_url }}</a> or email <a href="mailto:{{ support_email }}">{{ support_email }}</a>.{% endblocktrans %} + {% blocktrans trimmed asvar assist_msg %} + If you need help, please use our web form at {start_anchor_web}{{ support_url }}{end_anchor} or email {start_anchor_email}{{ support_email }}{end_anchor}. + {% endblocktrans %} + {% interpolate_html assist_msg start_anchor_web='<a href="'|add:support_url|add:'">'|safe start_anchor_email='<a href="mailto:'|add:support_email|add:'">'|safe end_anchor='</a>'|safe %} <br /> </p> </td> @@ -48,7 +58,9 @@ <tr> <td> <p style="color: rgba(0,0,0,.75);"> - {% blocktrans %}This email message was automatically sent by {{ lms_url }} because someone attempted to create an account on {{ platform_name }} using this email address.{% endblocktrans %} + {% filter force_escape %} + {% blocktrans %}This email message was automatically sent by {{ lms_url }} because someone attempted to create an account on {{ platform_name }} using this email address.{% endblocktrans %} + {% endfilter %} <br /> </p> </td>