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

@@ -55,7 +55,6 @@ def generate_realm_creation_url():
kwargs={'creation_key': key}))
class ConfirmationManager(models.Manager):
def confirm(self, confirmation_key):
# type: (str) -> Union[bool, PreregistrationUser, EmailChangeStatus]
if B16_RE.search(confirmation_key):
@@ -90,19 +89,6 @@ class ConfirmationManager(models.Manager):
# type: () -> int
return getattr(settings, 'EMAIL_CONFIRMATION_DAYS', 10)
def send_confirmation(self, obj, template_prefix, to_email, additional_context=None, host=None):
# type: (ContentType, str, Text, Optional[Dict[str, Any]], Optional[str]) -> Confirmation
confirmation_key = generate_key()
activate_url = self.get_activation_url(confirmation_key, host=host)
context = {
'activate_url': activate_url,
}
if additional_context is not None:
context.update(additional_context)
send_email(template_prefix, to_email, from_email=settings.DEFAULT_FROM_EMAIL, context=context)
return self.create(content_object=obj, date_sent=timezone_now(), confirmation_key=confirmation_key)
class EmailChangeConfirmationManager(ConfirmationManager):
def get_activation_url(self, key, host=None):
# type: (Text, Optional[str]) -> Text