mirror of
https://github.com/zulip/zulip.git
synced 2025-11-03 21:43:21 +00:00
confirmation: Replace *_template_path arguments with template_prefix.
Relies on the fact that all the email template names now follow the same pattern. Note that there was some template_prefix-like computation being done in send_confirmation (conditioned on obj.realm.is_zephyr_mirror_realm); that computation is now being done in the callers.
This commit is contained in:
@@ -10,7 +10,7 @@ from django.db import models
|
||||
from django.core.urlresolvers import reverse
|
||||
from django.core.mail import send_mail
|
||||
from django.conf import settings
|
||||
from django.template import loader, Context
|
||||
from django.template import loader, Context, TemplateDoesNotExist
|
||||
from django.contrib.sites.models import Site
|
||||
from django.contrib.contenttypes.models import ContentType
|
||||
from django.contrib.contenttypes.fields import GenericForeignKey
|
||||
@@ -91,10 +91,9 @@ class ConfirmationManager(models.Manager):
|
||||
# type: () -> int
|
||||
return getattr(settings, 'EMAIL_CONFIRMATION_DAYS', 10)
|
||||
|
||||
def send_confirmation(self, obj, email_address, additional_context=None,
|
||||
subject_template_path=None, body_template_path=None, html_body_template_path=None,
|
||||
def send_confirmation(self, obj, template_prefix, email_address, additional_context=None,
|
||||
host=None, custom_body=None):
|
||||
# type: (ContentType, Text, Optional[Dict[str, Any]], Optional[str], Optional[str], Optional[str], Optional[str], Optional[str]) -> Confirmation
|
||||
# type: (ContentType, str, Text, Optional[Dict[str, Any]], Optional[str], Optional[str]) -> Confirmation
|
||||
confirmation_key = generate_key()
|
||||
current_site = Site.objects.get_current()
|
||||
activate_url = self.get_activation_url(confirmation_key, host=host)
|
||||
@@ -108,26 +107,14 @@ class ConfirmationManager(models.Manager):
|
||||
})
|
||||
if additional_context is not None:
|
||||
context.update(additional_context)
|
||||
if obj.realm is not None and obj.realm.is_zephyr_mirror_realm:
|
||||
template_name = "mituser"
|
||||
else:
|
||||
template_name = obj._meta.model_name
|
||||
if subject_template_path:
|
||||
template = loader.get_template(subject_template_path)
|
||||
else:
|
||||
template = loader.select_template('confirmation/%s_confirmation_email.subject' % (template_name,))
|
||||
subject = template.render(context).strip().replace(u'\n', u' ') # no newlines, please
|
||||
if body_template_path:
|
||||
template = loader.get_template(body_template_path)
|
||||
else:
|
||||
template = loader.select_template('confirmation/%s_confirmation_email.txt' % (template_name,))
|
||||
if html_body_template_path:
|
||||
html_template = loader.get_template(html_body_template_path)
|
||||
else:
|
||||
html_template = loader.get_template('confirmation/%s_confirmation_email.html' % (template_name,))
|
||||
body = template.render(context)
|
||||
if html_template:
|
||||
html_content = html_template.render(context)
|
||||
|
||||
subject = loader.get_template(template_prefix + '.subject').render(context).strip().replace(u'\n', u' ') # no newlines, please
|
||||
body = loader.get_template(template_prefix + '.txt').render(context)
|
||||
try:
|
||||
html_content = loader.get_template(template_prefix + '.html').render(context)
|
||||
except TemplateDoesNotExist:
|
||||
html_content = None
|
||||
|
||||
send_mail(subject, body, settings.DEFAULT_FROM_EMAIL, [email_address], html_message=html_content)
|
||||
return self.create(content_object=obj, date_sent=timezone_now(), confirmation_key=confirmation_key)
|
||||
|
||||
|
||||
@@ -623,7 +623,7 @@ def do_start_email_change_process(user_profile, new_email):
|
||||
realm=user_profile.realm)
|
||||
|
||||
EmailChangeConfirmation.objects.send_confirmation(
|
||||
obj, new_email,
|
||||
obj, 'confirmation/emailchangestatus_confirmation_email', new_email,
|
||||
additional_context=context,
|
||||
host=user_profile.realm.host,
|
||||
)
|
||||
@@ -3057,24 +3057,17 @@ def do_send_confirmation_email(invitee, referrer, body):
|
||||
`invitee` is a PreregistrationUser.
|
||||
`referrer` is a UserProfile.
|
||||
"""
|
||||
subject_template_path = 'confirmation/invite_email.subject'
|
||||
body_template_path = 'confirmation/invite_email.txt'
|
||||
html_body_template_path = 'confirmation/invite_email.html' # type: Optional[str]
|
||||
|
||||
context = {'referrer': referrer,
|
||||
'support_email': settings.ZULIP_ADMINISTRATOR,
|
||||
'verbose_support_offers': settings.VERBOSE_SUPPORT_OFFERS}
|
||||
|
||||
if referrer.realm.is_zephyr_mirror_realm:
|
||||
subject_template_path = 'confirmation/mituser_invite_email.subject'
|
||||
body_template_path = 'confirmation/mituser_invite_email.txt'
|
||||
html_body_template_path = None
|
||||
template_prefix = 'confirmation/mituser_invite_email'
|
||||
else:
|
||||
template_prefix = 'confirmation/invite_email'
|
||||
|
||||
Confirmation.objects.send_confirmation(
|
||||
invitee, invitee.email, additional_context=context,
|
||||
subject_template_path=subject_template_path,
|
||||
body_template_path=body_template_path,
|
||||
html_body_template_path=html_body_template_path,
|
||||
invitee, template_prefix, invitee.email, additional_context=context,
|
||||
host=referrer.realm.host, custom_body=body)
|
||||
|
||||
def is_inactive(email):
|
||||
|
||||
@@ -286,10 +286,14 @@ def send_registration_completion_email(email, request, realm_creation=False):
|
||||
Send an email with a confirmation link to the provided e-mail so the user
|
||||
can complete their registration.
|
||||
"""
|
||||
template_prefix = 'confirmation/preregistrationuser_confirmation_email'
|
||||
if prereg_user.realm and prereg_user.realm.is_zephyr_mirror_realm: # nocoverage, see next commit
|
||||
template_prefix = 'confirmation/mituser_confirmation_email' # nocoverage, see next commit
|
||||
|
||||
prereg_user = create_preregistration_user(email, request, realm_creation)
|
||||
context = {'support_email': settings.ZULIP_ADMINISTRATOR,
|
||||
'verbose_support_offers': settings.VERBOSE_SUPPORT_OFFERS}
|
||||
return Confirmation.objects.send_confirmation(prereg_user, email,
|
||||
return Confirmation.objects.send_confirmation(prereg_user, template_prefix, email,
|
||||
additional_context=context,
|
||||
host=request.get_host())
|
||||
|
||||
|
||||
Reference in New Issue
Block a user