浏览代码

refactor(api): use template inheritance for confirmation emails

Peter Thomassen 3 年之前
父节点
当前提交
4900c0cdc3

+ 1 - 2
api/desecapi/models.py

@@ -181,12 +181,11 @@ class User(ExportModelOperationsMixin('User'), AbstractBaseUser):
         context = context or {}
         content = get_template(f'emails/{reason}/content.txt').render(context)
         content += f'\nSupport Reference: user_id = {self.pk}\n'
-        footer = get_template('emails/footer.txt').render()
 
         logger.warning(f'Queuing email for user account {self.pk} (reason: {reason}, lane: {lanes[reason]})')
         num_queued = EmailMessage(
             subject=get_template(f'emails/{reason}/subject.txt').render(context).strip(),
-            body=content + footer,
+            body=content,
             from_email=get_template('emails/from.txt').render(),
             to=[recipient or self.email],
             connection=get_connection(lane=lanes[reason], debug={'user': self.pk, 'reason': reason})

+ 3 - 1
api/desecapi/templates/emails/activate-account/content.txt

@@ -1,4 +1,5 @@
-{% load action_extras %}Hi there,
+{% extends "emails/content.txt" %}
+{% block content %}{% load action_extras %}Hi there,
 
 Thank you for registering with deSEC!{% if domain is not None %} You are about to set up the
 following domain: {{ domain }}{% endif %}
@@ -25,3 +26,4 @@ We hope you enjoy deSEC!
 
 Stay secure,
 Nils
+{% endblock %}

+ 3 - 1
api/desecapi/templates/emails/change-email-confirmation-old-email/content.txt

@@ -1,4 +1,5 @@
-Hi there,
+{% extends "emails/content.txt" %}
+{% block content %}Hi there,
 
 We're writing to let you know that the email address associated with
 your deSEC account has been changed to another address.
@@ -8,3 +9,4 @@ support@desec.io.
 
 Stay secure,
 The deSEC Team
+{% endblock  %}

+ 3 - 1
api/desecapi/templates/emails/change-email/content.txt

@@ -1,4 +1,5 @@
-{% load action_extras %}Hi,
+{% extends "emails/content.txt" %}
+{% block content %}{% load action_extras %}Hi,
 
 You requested to change the email address associated with your deSEC
 account from:
@@ -19,3 +20,4 @@ After your confirmation, we will perform the change.
 
 Stay secure,
 The deSEC Team
+{% endblock %}

+ 3 - 1
api/desecapi/templates/emails/confirm-account/content.txt

@@ -1,4 +1,5 @@
-{% load action_extras %}Hi there,
+{% extends "emails/content.txt" %}
+{% block content %}{% load action_extras %}Hi there,
 
 You have registered with deSEC a long time ago (on {{ action_serializer.action_user.created|date:"Y-m-d" }}), probably to
 set up a DNS domain (e.g. under dedyn.io).  At the time when you registered
@@ -23,3 +24,4 @@ We apologize for the slight inconvenience, and hope you enjoy deSEC!
 
 Stay secure,
 Nils
+{% endblock %}

+ 3 - 2
api/desecapi/templates/emails/footer.txt → api/desecapi/templates/emails/content.txt

@@ -1,5 +1,5 @@
-
--- 
+{% block content %}{% endblock %}
+--
 Like our community service? 💛
 Please consider donating at
 
@@ -12,3 +12,4 @@ Germany
 
 Vorstandsvorsitz: Nils Wisiol
 Registergericht: AG Berlin (Charlottenburg) VR 37525
+{% block trailer %}{% endblock %}

+ 3 - 1
api/desecapi/templates/emails/delete-account/content.txt

@@ -1,4 +1,5 @@
-{% load action_extras %}Hi there,
+{% extends "emails/content.txt" %}
+{% block content %}{% load action_extras %}Hi there,
 
 Sad to see you leave! 😢 We know there's always room for improvement.
 If your wish to leave deSEC is due to any shortcomings of our service,
@@ -14,3 +15,4 @@ Note that this action is irreversible! We cannot recover your account.
 
 Wherever you go, stay secure!
 The deSEC Team
+{% endblock %}

+ 3 - 1
api/desecapi/templates/emails/donation/donor-content.txt

@@ -1,4 +1,5 @@
-Dear supporter,
+{% extends "emails/content.txt" %}
+{% block content %}Dear supporter,
 
 We hereby confirm your donation to deSEC. We would like to THANK YOU for
 your support. If you have any questions concerning your donation, how
@@ -16,3 +17,4 @@ Again, thank you so much.
 
 Cheers,
 Nils
+{% endblock %}

+ 3 - 1
api/desecapi/templates/emails/password-change-confirmation/content.txt

@@ -1,4 +1,5 @@
-Hi,
+{% extends "emails/content.txt" %}
+{% block content %}Hi,
 
 This is to let you know that the password for your deSEC account has
 been changed.
@@ -8,3 +9,4 @@ support@desec.io.
 
 Stay secure,
 The deSEC Team
+{% endblock %}

+ 3 - 1
api/desecapi/templates/emails/renew-domain/content.txt

@@ -1,4 +1,5 @@
-{% load action_extras %}Hi there,
+{% extends "emails/content.txt" %}
+{% block content %}{% load action_extras %}Hi there,
 
 You are the owner of the following domain name(s):
 {% for instance in action_serializer.instance %}
@@ -26,3 +27,4 @@ In case you have questions, feel free to contact us!
 
 Stay secure,
 The deSEC Team
+{% endblock %}

+ 3 - 1
api/desecapi/templates/emails/reset-password/content.txt

@@ -1,4 +1,5 @@
-{% load action_extras %}Hi,
+{% extends "emails/content.txt" %}
+{% block content %}{% load action_extras %}Hi,
 
 We received a request to reset the password for your deSEC account.
 This may happen when someone uses the "Reset Password" function on our
@@ -14,3 +15,4 @@ After your confirmation, you can provide your new password.
 
 Stay secure,
 The deSEC Team
+{% endblock %}

+ 1 - 2
api/desecapi/views.py

@@ -480,9 +480,8 @@ class DonationList(generics.CreateAPIView):
         if instance.email:
             content_tmpl = get_template('emails/donation/donor-content.txt')
             subject_tmpl = get_template('emails/donation/donor-subject.txt')
-            footer_tmpl = get_template('emails/footer.txt')
             email = EmailMessage(subject_tmpl.render(context),
-                                 content_tmpl.render(context) + footer_tmpl.render(),
+                                 content_tmpl.render(context),
                                  from_tmpl.render(context),
                                  [instance.email])
             email.send()