emails: Move verbose_support_offers into a common context.

Server settings should just be added to the context in build_email, so that
the individual email pathways (and later, the email testing framework)
doesn't have to worry about it.
This commit is contained in:
Rishi Gupta 2017-06-10 01:16:01 -07:00
parent c3aa799192
commit 056489c247
8 changed files with 5 additions and 11 deletions

View File

@ -34,7 +34,6 @@ def confirm(request, confirmation_key):
'key': confirmation_key, 'key': confirmation_key,
'full_name': request.GET.get("full_name", None), 'full_name': request.GET.get("full_name", None),
'support_email': settings.ZULIP_ADMINISTRATOR, 'support_email': settings.ZULIP_ADMINISTRATOR,
'verbose_support_offers': settings.VERBOSE_SUPPORT_OFFERS,
} }
templates = [ templates = [
'confirmation/confirm.html', 'confirmation/confirm.html',

View File

@ -632,7 +632,6 @@ def do_start_email_change_process(user_profile, new_email):
user_profile.email = new_email user_profile.email = new_email
context = {'support_email': settings.ZULIP_ADMINISTRATOR, context = {'support_email': settings.ZULIP_ADMINISTRATOR,
'verbose_support_offers': settings.VERBOSE_SUPPORT_OFFERS,
'realm': user_profile.realm, 'realm': user_profile.realm,
'old_email': old_email, 'old_email': old_email,
'new_email': new_email, 'new_email': new_email,
@ -3055,8 +3054,7 @@ def do_send_confirmation_email(invitee, referrer, body):
`referrer` is a UserProfile. `referrer` is a UserProfile.
""" """
context = {'referrer': referrer, context = {'referrer': referrer,
'support_email': settings.ZULIP_ADMINISTRATOR, 'support_email': settings.ZULIP_ADMINISTRATOR}
'verbose_support_offers': settings.VERBOSE_SUPPORT_OFFERS}
if referrer.realm.is_zephyr_mirror_realm: if referrer.realm.is_zephyr_mirror_realm:
template_prefix = 'zerver/emails/invitation_mit' template_prefix = 'zerver/emails/invitation_mit'

View File

@ -404,7 +404,6 @@ def enqueue_welcome_emails(email, name):
unsubscribe_link = one_click_unsubscribe_link(user_profile, "welcome") unsubscribe_link = one_click_unsubscribe_link(user_profile, "welcome")
context = common_context(user_profile) context = common_context(user_profile)
context.update({ context.update({
'verbose_support_offers': settings.VERBOSE_SUPPORT_OFFERS,
'unsubscribe_link': unsubscribe_link 'unsubscribe_link': unsubscribe_link
}) })
send_future_email( send_future_email(

View File

@ -19,6 +19,9 @@ def display_email(user):
# Intended only for test code # Intended only for test code
def build_email(template_prefix, to_email, from_email=None, reply_to_email=None, context={}): def build_email(template_prefix, to_email, from_email=None, reply_to_email=None, context={}):
# type: (str, Text, Optional[Text], Optional[Text], Dict[str, Any]) -> EmailMultiAlternatives # type: (str, Text, Optional[Text], Optional[Text], Dict[str, Any]) -> EmailMultiAlternatives
context.update({
'verbose_support_offers': settings.VERBOSE_SUPPORT_OFFERS,
})
subject = loader.render_to_string(template_prefix + '.subject', subject = loader.render_to_string(template_prefix + '.subject',
context=context, using='Jinja2_plaintext').strip() context=context, using='Jinja2_plaintext').strip()
message = loader.render_to_string(template_prefix + '.txt', message = loader.render_to_string(template_prefix + '.txt',

View File

@ -739,7 +739,6 @@ so we didn't send them an invitation. We did send invitations to everyone else!"
'referrer_name': referrer.full_name, 'referrer_name': referrer.full_name,
'referrer_email': referrer.email, 'referrer_email': referrer.email,
'referrer_realm_name': referrer.realm.name, 'referrer_realm_name': referrer.realm.name,
'verbose_support_offers': settings.VERBOSE_SUPPORT_OFFERS,
'support_email': settings.ZULIP_ADMINISTRATOR 'support_email': settings.ZULIP_ADMINISTRATOR
}) })
with self.settings(EMAIL_BACKEND='django.core.mail.backends.console.EmailBackend'): with self.settings(EMAIL_BACKEND='django.core.mail.backends.console.EmailBackend'):

View File

@ -308,8 +308,7 @@ def send_registration_completion_email(email, request, realm_creation=False):
template_prefix = 'zerver/emails/confirm_registration_mit' template_prefix = 'zerver/emails/confirm_registration_mit'
prereg_user = create_preregistration_user(email, request, realm_creation) prereg_user = create_preregistration_user(email, request, realm_creation)
context = {'support_email': settings.ZULIP_ADMINISTRATOR, context = {'support_email': settings.ZULIP_ADMINISTRATOR}
'verbose_support_offers': settings.VERBOSE_SUPPORT_OFFERS}
return Confirmation.objects.send_confirmation(prereg_user, template_prefix, email, return Confirmation.objects.send_confirmation(prereg_user, template_prefix, email,
additional_context=context, additional_context=context,
host=request.get_host()) host=request.get_host())

View File

@ -49,7 +49,6 @@ def confirm_email_change(request, confirmation_key):
do_change_user_email(obj.user_profile, obj.new_email) do_change_user_email(obj.user_profile, obj.new_email)
context = {'support_email': settings.ZULIP_ADMINISTRATOR, context = {'support_email': settings.ZULIP_ADMINISTRATOR,
'verbose_support_offers': settings.VERBOSE_SUPPORT_OFFERS,
'realm': obj.realm, 'realm': obj.realm,
'new_email': new_email, 'new_email': new_email,
} }
@ -59,7 +58,6 @@ def confirm_email_change(request, confirmation_key):
ctx = { ctx = {
'confirmed': confirmed, 'confirmed': confirmed,
'support_email': settings.ZULIP_ADMINISTRATOR, 'support_email': settings.ZULIP_ADMINISTRATOR,
'verbose_support_offers': settings.VERBOSE_SUPPORT_OFFERS,
'new_email': new_email, 'new_email': new_email,
'old_email': old_email, 'old_email': old_email,
} }

View File

@ -174,7 +174,6 @@ class ConfirmationEmailWorker(QueueProcessingWorker):
'referrer_name': referrer.full_name, 'referrer_name': referrer.full_name,
'referrer_email': referrer.email, 'referrer_email': referrer.email,
'referrer_realm_name': referrer.realm.name, 'referrer_realm_name': referrer.realm.name,
'verbose_support_offers': settings.VERBOSE_SUPPORT_OFFERS,
'support_email': settings.ZULIP_ADMINISTRATOR 'support_email': settings.ZULIP_ADMINISTRATOR
}) })
send_future_email( send_future_email(