Просмотр исходного кода

Send HTML emails for org invite

Brendan 4 лет назад
Родитель
Сommit
f7e8b94a2c

+ 19 - 0
organizations_ext/email.py

@@ -26,3 +26,22 @@ def send_email_met_quota(organization):
     msg = EmailMultiAlternatives(subject, text_content, to=to)
     msg.attach_alternative(html_content, "text/html")
     msg.send()
+
+
+def send_invitation_email(self, user, **kwargs):
+    template_html = "organizations/email/invite-user-drip.html"
+    template_txt = "organizations/email/invite-user-drip.txt"
+
+    context = {
+        "token": kwargs["token"],
+        "user": user,
+        "organization": kwargs["organization"],
+    }
+
+    html_content = render_to_string(template_html, context)
+    text_content = render_to_string(template_txt, context)
+    subject = "You are invited to GlitchTip"
+
+    msg = EmailMultiAlternatives(subject, text_content, to=[user])
+    msg.attach_alternative(html_content, "text/html")
+    msg.send()

+ 9 - 4
organizations_ext/invitation_backend.py

@@ -1,8 +1,11 @@
 from django.conf import settings
+from django.core.mail import EmailMultiAlternatives
+from django.template.loader import render_to_string
 from django.urls import re_path
 from organizations.backends.tokens import RegistrationTokenGenerator
 from organizations.backends.defaults import InvitationBackend as BaseInvitationBackend
 from .models import Organization
+from .email import send_invitation_email
 
 
 class InvitationTokenGenerator(RegistrationTokenGenerator):
@@ -32,7 +35,9 @@ class InvitationBackend(BaseInvitationBackend):
         return InvitationTokenGenerator().make_token(org_user)
 
     def send_invitation(self, user, sender=None, **kwargs):
-        kwargs["domain"] = {
-            "domain": settings.GLITCHTIP_DOMAIN.geturl(),
-        }
-        return super().send_invitation(user, sender, **kwargs)
+        kwargs.update({
+            "token": self.get_token(user),
+            "organization": user.organization,
+        })
+        send_invitation_email(self, user, **kwargs)
+        return True

+ 0 - 7
organizations_ext/templates/organizations/email/invitation_body.html

@@ -1,7 +0,0 @@
-You've been invited to join {{ organization|safe }} on {{ domain.name }} by {{ sender.first_name|safe }} {{ sender.last_name|safe }}.
-
-Follow this link to create your user account.
-
-{{ domain.domain }}{% url "invitations_register" user.pk token %}
-
-If you are unsure about this link please contact the sender.

+ 0 - 1
organizations_ext/templates/organizations/email/invitation_subject.txt

@@ -1 +0,0 @@
-{% spaceless %}You've been invited!{% endspaceless %}

Разница между файлами не показана из-за своего большого размера
+ 2 - 0
organizations_ext/templates/organizations/email/invite-user-drip.html


+ 9 - 0
organizations_ext/templates/organizations/email/invite-user-drip.txt

@@ -0,0 +1,9 @@
+{% load settings %}You are invited to GlitchTip
+
+{{ organization|safe }} is using GlitchTip for software error reporting and wants you to be a part of the team.
+ 
+Follow this link to create your user account.
+
+{% get_domain %}{% url "invitations_register" user.pk token %}
+ 
+Visit GlitchTip's homepage at {% get_domain %} if you want to learn more first.

Некоторые файлы не были показаны из-за большого количества измененных файлов