confirmation: Remove Confirmation.objects.send_confirmation.

I think it makes sense to wrest the email sending from confirmation, now
that we have a clean email-sending interface in send_email. A few other
reasons:
* send_confirmation is get_link_for_object followed by send_email, but those
  two functions have no arguments in common.
* Sending email through confirmation obfuscates the context dict, and is a
  relatively complicated piece of the codebase anyone trying to deal with
  the email system has to understand.
* The three emails previously being sent through confirmation don't have
  that much in common, other than that they happen to have a confirmation
  link in them.

The .split('/')[-1] in registration.py is a hack, but a hack used several
places in the codebase, so maybe one day get_link_for_object will also
return the confirmation_key.
This commit is contained in:
Rishi Gupta
2017-06-10 15:39:58 -07:00
committed by Tim Abbott
parent e4d3ce953b
commit 1f77a0cdee
3 changed files with 17 additions and 39 deletions

View File

@@ -29,6 +29,7 @@ from zerver.lib.message import (
)
from zerver.lib.realm_icon import realm_icon_url
from zerver.lib.retention import move_message_to_archive
from zerver.lib.send_email import send_email
from zerver.models import Realm, RealmEmoji, Stream, UserProfile, UserActivity, \
RealmDomain, \
Subscription, Recipient, Message, Attachment, UserMessage, RealmAuditLog, \
@@ -630,22 +631,14 @@ def do_start_email_change_process(user_profile, new_email):
# type: (UserProfile, Text) -> None
old_email = user_profile.email
user_profile.email = new_email
obj = EmailChangeStatus.objects.create(new_email=new_email, old_email=old_email,
user_profile=user_profile, realm=user_profile.realm)
context = {'realm': user_profile.realm,
'old_email': old_email,
'new_email': new_email,
}
obj = EmailChangeStatus.objects.create(new_email=new_email,
old_email=old_email,
user_profile=user_profile,
realm=user_profile.realm)
EmailChangeConfirmation.objects.send_confirmation(
obj, 'zerver/emails/confirm_new_email', new_email,
additional_context=context,
host=user_profile.realm.host,
)
activation_url = EmailChangeConfirmation.objects.get_link_for_object(obj, host=user_profile.realm.host)
context = {'realm': user_profile.realm, 'old_email': old_email, 'new_email': new_email,
'activate_url': activation_url}
send_email('zerver/emails/confirm_new_email', new_email, from_email=settings.DEFAULT_FROM_EMAIL,
context=context)
def compute_irc_user_fullname(email):
# type: (NonBinaryStr) -> NonBinaryStr
@@ -3053,12 +3046,10 @@ def do_send_confirmation_email(invitee, referrer, body):
`invitee` is a PreregistrationUser.
`referrer` is a UserProfile.
"""
context = {'referrer': referrer, 'custom_body': body}
template_prefix = 'zerver/emails/invitation'
Confirmation.objects.send_confirmation(
invitee, template_prefix, invitee.email, additional_context=context,
host=referrer.realm.host)
activation_url = Confirmation.objects.get_link_for_object(invitee, host=referrer.realm.host)
context = {'referrer': referrer, 'custom_body': body, 'activate_url': activation_url}
send_email('zerver/emails/invitation', invitee.email, from_email=settings.DEFAULT_FROM_EMAIL,
context=context)
def is_inactive(email):
# type: (Text) -> None