Commit 18cddf6e by Asad Iqbal

Merge pull request #12488 from edx/asadiqbal08/WL-477

Got two thumbs up, so merging. 
WL-477 Route direct references to email address configurations through theming.helpers
parents 6b390f2e 1c19ebb4
...@@ -24,6 +24,7 @@ from util.password_policy_validators import ( ...@@ -24,6 +24,7 @@ from util.password_policy_validators import (
validate_password_complexity, validate_password_complexity,
validate_password_dictionary, validate_password_dictionary,
) )
from openedx.core.djangoapps.theming import helpers as theming_helpers
class PasswordResetFormNoActive(PasswordResetForm): class PasswordResetFormNoActive(PasswordResetForm):
...@@ -57,7 +58,7 @@ class PasswordResetFormNoActive(PasswordResetForm): ...@@ -57,7 +58,7 @@ class PasswordResetFormNoActive(PasswordResetForm):
email_template_name='registration/password_reset_email.html', email_template_name='registration/password_reset_email.html',
use_https=False, use_https=False,
token_generator=default_token_generator, token_generator=default_token_generator,
from_email=settings.DEFAULT_FROM_EMAIL, from_email=theming_helpers.get_value('default_from_email', settings.DEFAULT_FROM_EMAIL),
request=None request=None
): ):
""" """
......
...@@ -22,6 +22,7 @@ from edxmako.tests import mako_middleware_process_request ...@@ -22,6 +22,7 @@ from edxmako.tests import mako_middleware_process_request
from util.request import safe_get_host from util.request import safe_get_host
from util.testing import EventTestMixin from util.testing import EventTestMixin
from openedx.core.djangoapps.theming.test_util import with_is_edx_domain from openedx.core.djangoapps.theming.test_util import with_is_edx_domain
from openedx.core.djangoapps.theming import helpers as theming_helpers
class TestException(Exception): class TestException(Exception):
...@@ -57,7 +58,7 @@ class EmailTestMixin(object): ...@@ -57,7 +58,7 @@ class EmailTestMixin(object):
email_user.assert_called_with( email_user.assert_called_with(
mock_render_to_string(subject_template, subject_context), mock_render_to_string(subject_template, subject_context),
mock_render_to_string(body_template, body_context), mock_render_to_string(body_template, body_context),
settings.DEFAULT_FROM_EMAIL theming_helpers.get_value('default_from_email', settings.DEFAULT_FROM_EMAIL)
) )
def append_allowed_hosts(self, hostname): def append_allowed_hosts(self, hostname):
...@@ -298,7 +299,7 @@ class EmailChangeRequestTests(EventTestMixin, TestCase): ...@@ -298,7 +299,7 @@ class EmailChangeRequestTests(EventTestMixin, TestCase):
send_mail.assert_called_with( send_mail.assert_called_with(
mock_render_to_string('emails/email_change_subject.txt', context), mock_render_to_string('emails/email_change_subject.txt', context),
mock_render_to_string('emails/email_change.txt', context), mock_render_to_string('emails/email_change.txt', context),
settings.DEFAULT_FROM_EMAIL, theming_helpers.get_value('default_from_email', settings.DEFAULT_FROM_EMAIL),
[new_email] [new_email]
) )
self.assert_event_emitted( self.assert_event_emitted(
......
...@@ -26,6 +26,7 @@ from student.tests.test_email import mock_render_to_string ...@@ -26,6 +26,7 @@ from student.tests.test_email import mock_render_to_string
from util.testing import EventTestMixin from util.testing import EventTestMixin
from .test_microsite import fake_microsite_get_value from .test_microsite import fake_microsite_get_value
from openedx.core.djangoapps.theming import helpers as theming_helpers
@ddt.ddt @ddt.ddt
...@@ -124,7 +125,7 @@ class ResetPasswordTests(EventTestMixin, CacheIsolationTestCase): ...@@ -124,7 +125,7 @@ class ResetPasswordTests(EventTestMixin, CacheIsolationTestCase):
(subject, msg, from_addr, to_addrs) = send_email.call_args[0] (subject, msg, from_addr, to_addrs) = send_email.call_args[0]
self.assertIn("Password reset", subject) self.assertIn("Password reset", subject)
self.assertIn("You're receiving this e-mail because you requested a password reset", msg) self.assertIn("You're receiving this e-mail because you requested a password reset", msg)
self.assertEquals(from_addr, settings.DEFAULT_FROM_EMAIL) self.assertEquals(from_addr, theming_helpers.get_value('default_from_email', settings.DEFAULT_FROM_EMAIL))
self.assertEquals(len(to_addrs), 1) self.assertEquals(len(to_addrs), 1)
self.assertIn(self.user.email, to_addrs) self.assertIn(self.user.email, to_addrs)
......
...@@ -128,6 +128,7 @@ from openedx.core.djangoapps.credit.email_utils import get_credit_provider_displ ...@@ -128,6 +128,7 @@ from openedx.core.djangoapps.credit.email_utils import get_credit_provider_displ
from openedx.core.djangoapps.user_api.preferences import api as preferences_api from openedx.core.djangoapps.user_api.preferences import api as preferences_api
from openedx.core.djangoapps.programs.utils import get_programs_for_dashboard, get_display_category from openedx.core.djangoapps.programs.utils import get_programs_for_dashboard, get_display_category
from openedx.core.djangoapps.programs.models import ProgramsApiConfig from openedx.core.djangoapps.programs.models import ProgramsApiConfig
from openedx.core.djangoapps.theming import helpers as theming_helpers
log = logging.getLogger("edx.student") log = logging.getLogger("edx.student")
...@@ -1789,7 +1790,7 @@ def create_account_with_params(request, params): ...@@ -1789,7 +1790,7 @@ def create_account_with_params(request, params):
subject = ''.join(subject.splitlines()) subject = ''.join(subject.splitlines())
message = render_to_string('emails/activation_email.txt', context) message = render_to_string('emails/activation_email.txt', context)
from_address = microsite.get_value( from_address = theming_helpers.get_value(
'email_from_address', 'email_from_address',
settings.DEFAULT_FROM_EMAIL settings.DEFAULT_FROM_EMAIL
) )
...@@ -2098,7 +2099,7 @@ def password_reset(request): ...@@ -2098,7 +2099,7 @@ def password_reset(request):
form = PasswordResetFormNoActive(request.POST) form = PasswordResetFormNoActive(request.POST)
if form.is_valid(): if form.is_valid():
form.save(use_https=request.is_secure(), form.save(use_https=request.is_secure(),
from_email=microsite.get_value('email_from_address', settings.DEFAULT_FROM_EMAIL), from_email=theming_helpers.get_value('email_from_address', settings.DEFAULT_FROM_EMAIL),
request=request, request=request,
domain_override=request.get_host()) domain_override=request.get_host())
# When password change is complete, a "edx.user.settings.changed" event will be emitted. # When password change is complete, a "edx.user.settings.changed" event will be emitted.
...@@ -2244,9 +2245,13 @@ def reactivation_email_for_user(user): ...@@ -2244,9 +2245,13 @@ def reactivation_email_for_user(user):
message = render_to_string('emails/activation_email.txt', context) message = render_to_string('emails/activation_email.txt', context)
try: try:
user.email_user(subject, message, settings.DEFAULT_FROM_EMAIL) user.email_user(subject, message, theming_helpers.get_value('default_from_email', settings.DEFAULT_FROM_EMAIL))
except Exception: # pylint: disable=broad-except except Exception: # pylint: disable=broad-except
log.error(u'Unable to send reactivation email from "%s"', settings.DEFAULT_FROM_EMAIL, exc_info=True) log.error(
u'Unable to send reactivation email from "%s"',
theming_helpers.get_value('default_from_email', settings.DEFAULT_FROM_EMAIL),
exc_info=True
)
return JsonResponse({ return JsonResponse({
"success": False, "success": False,
"error": _('Unable to send reactivation email') "error": _('Unable to send reactivation email')
...@@ -2304,7 +2309,7 @@ def do_email_change_request(user, new_email, activation_key=None): ...@@ -2304,7 +2309,7 @@ def do_email_change_request(user, new_email, activation_key=None):
message = render_to_string('emails/email_change.txt', context) message = render_to_string('emails/email_change.txt', context)
from_address = microsite.get_value( from_address = theming_helpers.get_value(
'email_from_address', 'email_from_address',
settings.DEFAULT_FROM_EMAIL settings.DEFAULT_FROM_EMAIL
) )
...@@ -2365,7 +2370,11 @@ def confirm_email_change(request, key): # pylint: disable=unused-argument ...@@ -2365,7 +2370,11 @@ def confirm_email_change(request, key): # pylint: disable=unused-argument
u_prof.save() u_prof.save()
# Send it to the old email... # Send it to the old email...
try: try:
user.email_user(subject, message, settings.DEFAULT_FROM_EMAIL) user.email_user(
subject,
message,
theming_helpers.get_value('default_from_email', settings.DEFAULT_FROM_EMAIL)
)
except Exception: # pylint: disable=broad-except except Exception: # pylint: disable=broad-except
log.warning('Unable to send confirmation email to old address', exc_info=True) log.warning('Unable to send confirmation email to old address', exc_info=True)
response = render_to_response("email_change_failed.html", {'email': user.email}) response = render_to_response("email_change_failed.html", {'email': user.email})
...@@ -2377,7 +2386,11 @@ def confirm_email_change(request, key): # pylint: disable=unused-argument ...@@ -2377,7 +2386,11 @@ def confirm_email_change(request, key): # pylint: disable=unused-argument
pec.delete() pec.delete()
# And send it to the new email... # And send it to the new email...
try: try:
user.email_user(subject, message, settings.DEFAULT_FROM_EMAIL) user.email_user(
subject,
message,
theming_helpers.get_value('default_from_email', settings.DEFAULT_FROM_EMAIL)
)
except Exception: # pylint: disable=broad-except except Exception: # pylint: disable=broad-except
log.warning('Unable to send confirmation email to new address', exc_info=True) log.warning('Unable to send confirmation email to new address', exc_info=True)
response = render_to_response("email_change_failed.html", {'email': pec.new_email}) response = render_to_response("email_change_failed.html", {'email': pec.new_email})
......
...@@ -53,6 +53,7 @@ from instructor_task.subtasks import ( ...@@ -53,6 +53,7 @@ from instructor_task.subtasks import (
) )
from util.query import use_read_replica_if_available from util.query import use_read_replica_if_available
from util.date_utils import get_default_time_display from util.date_utils import get_default_time_display
from openedx.core.djangoapps.theming import helpers as theming_helpers
log = logging.getLogger('edx.celery.task') log = logging.getLogger('edx.celery.task')
...@@ -422,7 +423,10 @@ def _get_source_address(course_id, course_title, truncate=True): ...@@ -422,7 +423,10 @@ def _get_source_address(course_id, course_title, truncate=True):
return from_addr_format.format( return from_addr_format.format(
course_title=course_title_no_quotes, course_title=course_title_no_quotes,
course_name=course_name, course_name=course_name,
from_email=settings.BULK_EMAIL_DEFAULT_FROM_EMAIL, from_email=theming_helpers.get_value(
'bulk_email_default_from_email',
settings.BULK_EMAIL_DEFAULT_FROM_EMAIL
)
) )
from_addr = format_address(course_title_no_quotes) from_addr = format_address(course_title_no_quotes)
......
...@@ -25,6 +25,7 @@ from openedx.core.djangoapps.user_api.models import UserPreference ...@@ -25,6 +25,7 @@ from openedx.core.djangoapps.user_api.models import UserPreference
from microsite_configuration import microsite from microsite_configuration import microsite
from xmodule.modulestore.django import modulestore from xmodule.modulestore.django import modulestore
from xmodule.modulestore.exceptions import ItemNotFoundError from xmodule.modulestore.exceptions import ItemNotFoundError
from openedx.core.djangoapps.theming import helpers as theming_helpers
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
...@@ -426,7 +427,7 @@ def send_mail_to_student(student, param_dict, language=None): ...@@ -426,7 +427,7 @@ def send_mail_to_student(student, param_dict, language=None):
# Email subject *must not* contain newlines # Email subject *must not* contain newlines
subject = ''.join(subject.splitlines()) subject = ''.join(subject.splitlines())
from_address = microsite.get_value( from_address = theming_helpers.get_value(
'email_from_address', 'email_from_address',
settings.DEFAULT_FROM_EMAIL settings.DEFAULT_FROM_EMAIL
) )
......
...@@ -109,6 +109,7 @@ from opaque_keys.edx.keys import CourseKey, UsageKey ...@@ -109,6 +109,7 @@ from opaque_keys.edx.keys import CourseKey, UsageKey
from opaque_keys.edx.locations import SlashSeparatedCourseKey from opaque_keys.edx.locations import SlashSeparatedCourseKey
from opaque_keys import InvalidKeyError from opaque_keys import InvalidKeyError
from openedx.core.djangoapps.course_groups.cohorts import is_course_cohorted from openedx.core.djangoapps.course_groups.cohorts import is_course_cohorted
from openedx.core.djangoapps.theming import helpers as theming_helpers
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
...@@ -1737,7 +1738,7 @@ def generate_registration_codes(request, course_id): ...@@ -1737,7 +1738,7 @@ def generate_registration_codes(request, course_id):
log.exception('Exception at creating pdf file.') log.exception('Exception at creating pdf file.')
pdf_file = None pdf_file = None
from_address = microsite.get_value('email_from_address', settings.DEFAULT_FROM_EMAIL) from_address = theming_helpers.get_value('email_from_address', settings.DEFAULT_FROM_EMAIL)
context = { context = {
'invoice': sale_invoice, 'invoice': sale_invoice,
'site_name': site_name, 'site_name': site_name,
......
...@@ -61,6 +61,7 @@ from util.date_utils import get_default_time_display ...@@ -61,6 +61,7 @@ from util.date_utils import get_default_time_display
from util.db import outer_atomic from util.db import outer_atomic
from xmodule.modulestore.django import modulestore from xmodule.modulestore.django import modulestore
from django.contrib.staticfiles.storage import staticfiles_storage from django.contrib.staticfiles.storage import staticfiles_storage
from openedx.core.djangoapps.theming import helpers as theming_helpers
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
...@@ -1100,7 +1101,7 @@ class SubmitPhotosView(View): ...@@ -1100,7 +1101,7 @@ class SubmitPhotosView(View):
subject = _("Verification photos received") subject = _("Verification photos received")
message = render_to_string('emails/photo_submission_confirmation.txt', context) message = render_to_string('emails/photo_submission_confirmation.txt', context)
from_address = microsite.get_value('default_from_email', settings.DEFAULT_FROM_EMAIL) from_address = theming_helpers.get_value('default_from_email', settings.DEFAULT_FROM_EMAIL)
to_address = user.email to_address = user.email
try: try:
...@@ -1219,7 +1220,7 @@ def _send_email(user_id, subject, message): ...@@ -1219,7 +1220,7 @@ def _send_email(user_id, subject, message):
Returns: Returns:
None None
""" """
from_address = microsite.get_value( from_address = theming_helpers.get_value(
'email_from_address', 'email_from_address',
settings.DEFAULT_FROM_EMAIL settings.DEFAULT_FROM_EMAIL
) )
......
...@@ -27,6 +27,7 @@ from microsite_configuration import microsite ...@@ -27,6 +27,7 @@ from microsite_configuration import microsite
from openedx.core.djangoapps.commerce.utils import ecommerce_api_client from openedx.core.djangoapps.commerce.utils import ecommerce_api_client
from openedx.core.djangoapps.credit.models import CreditConfig, CreditProvider from openedx.core.djangoapps.credit.models import CreditConfig, CreditProvider
from xmodule.modulestore.django import modulestore from xmodule.modulestore.django import modulestore
from openedx.core.djangoapps.theming import helpers as theming_helpers
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
...@@ -124,7 +125,7 @@ def send_credit_notifications(username, course_key): ...@@ -124,7 +125,7 @@ def send_credit_notifications(username, course_key):
notification_msg.attach(logo_image) notification_msg.attach(logo_image)
# add email addresses of sender and receiver # add email addresses of sender and receiver
from_address = microsite.get_value('default_from_email', settings.DEFAULT_FROM_EMAIL) from_address = theming_helpers.get_value('default_from_email', settings.DEFAULT_FROM_EMAIL)
to_address = user.email to_address = user.email
# send the root email message # send the root email message
......
...@@ -33,6 +33,7 @@ from .serializers import ( ...@@ -33,6 +33,7 @@ from .serializers import (
AccountLegacyProfileSerializer, AccountUserSerializer, AccountLegacyProfileSerializer, AccountUserSerializer,
UserReadOnlySerializer, _visible_fields # pylint: disable=invalid-name UserReadOnlySerializer, _visible_fields # pylint: disable=invalid-name
) )
from openedx.core.djangoapps.theming import helpers as theming_helpers
# Public access point for this function. # Public access point for this function.
...@@ -397,7 +398,7 @@ def request_password_change(email, orig_host, is_secure): ...@@ -397,7 +398,7 @@ def request_password_change(email, orig_host, is_secure):
# Generate a single-use link for performing a password reset # Generate a single-use link for performing a password reset
# and email it to the user. # and email it to the user.
form.save( form.save(
from_email=settings.DEFAULT_FROM_EMAIL, from_email=theming_helpers.get_value('default_from_email', settings.DEFAULT_FROM_EMAIL),
domain_override=orig_host, domain_override=orig_host,
use_https=is_secure use_https=is_secure
) )
......
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