mirror of
https://github.com/healthchecks/healthchecks.git
synced 2025-04-08 06:30:05 +00:00
Fix email template to use SITE_LOGO_URL (with img/logo.png fallback)
Fixes: #550
This commit is contained in:
parent
3901a2825b
commit
484c0befbc
3 changed files with 17 additions and 5 deletions
|
@ -21,6 +21,7 @@ class LoginTestCase(BaseTestCase):
|
|||
r = self.client.get("/accounts/login/")
|
||||
self.assertRedirects(r, self.checks_url)
|
||||
|
||||
@override_settings(SITE_ROOT="http://testserver")
|
||||
def test_it_sends_link(self):
|
||||
form = {"identity": "alice@example.org"}
|
||||
|
||||
|
@ -29,8 +30,16 @@ class LoginTestCase(BaseTestCase):
|
|||
|
||||
# And email should have been sent
|
||||
self.assertEqual(len(mail.outbox), 1)
|
||||
subject = "Log in to %s" % settings.SITE_NAME
|
||||
self.assertEqual(mail.outbox[0].subject, subject)
|
||||
message = mail.outbox[0]
|
||||
self.assertEqual(message.subject, f"Log in to {settings.SITE_NAME}")
|
||||
html = message.alternatives[0][0]
|
||||
self.assertIn("http://testserver/static/img/logo.png", html)
|
||||
|
||||
@override_settings(SITE_LOGO_URL="https://example.org/logo.svg")
|
||||
def test_it_uses_custom_logo(self):
|
||||
self.client.post("/accounts/login/", {"identity": "alice@example.org"})
|
||||
html = mail.outbox[0].alternatives[0][0]
|
||||
self.assertIn("https://example.org/logo.svg", html)
|
||||
|
||||
def test_it_sends_link_with_next(self):
|
||||
form = {"identity": "alice@example.org"}
|
||||
|
|
|
@ -3,6 +3,7 @@ from threading import Thread
|
|||
import time
|
||||
|
||||
from django.conf import settings
|
||||
from django.templatetags.static import static
|
||||
from django.core.mail import EmailMultiAlternatives
|
||||
from django.template.loader import render_to_string as render
|
||||
|
||||
|
@ -33,7 +34,10 @@ class EmailThread(Thread):
|
|||
|
||||
|
||||
def make_message(name, to, ctx, headers={}):
|
||||
ctx["SITE_ROOT"] = settings.SITE_ROOT
|
||||
ctx["site_logo_url"] = settings.SITE_LOGO_URL or static("img/logo.png")
|
||||
if ctx["site_logo_url"].startswith("/"):
|
||||
# If it's a relative URL, prepend SITE_ROOT
|
||||
ctx["site_logo_url"] = settings.SITE_ROOT + ctx["site_logo_url"]
|
||||
|
||||
subject = render("emails/%s-subject.html" % name, ctx).strip()
|
||||
body = render("emails/%s-body-text.html" % name, ctx)
|
||||
|
@ -41,7 +45,6 @@ def make_message(name, to, ctx, headers={}):
|
|||
|
||||
msg = EmailMultiAlternatives(subject, body, to=(to,), headers=headers)
|
||||
msg.attach_alternative(html, "text/html")
|
||||
|
||||
return msg
|
||||
|
||||
|
||||
|
|
|
@ -105,7 +105,7 @@
|
|||
<table border="0" cellpadding="0" cellspacing="0" width="100%" style="max-width: 600px;" class="wrapper">
|
||||
<tr>
|
||||
<td align="center" valign="top" style="padding: 15px 0;" class="logo">
|
||||
<img alt="Logo" src="{% site_root %}/static/img/logo-full@2x.png" width="200" height="50" style="display: block; font-family: Helvetica, Arial, sans-serif; color: #ffffff; font-size: 16px;" border="0">
|
||||
<img alt="{% site_name %}" src="{{ site_logo_url }}" height="50" style="display: block; font-family: Helvetica, Arial, sans-serif; color: #ffffff; font-size: 16px;" border="0">
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
|
Loading…
Add table
Reference in a new issue