diff --git a/hc/api/tests/test_notify.py b/hc/api/tests/test_notify.py index 5d5c5883..50a38af9 100644 --- a/hc/api/tests/test_notify.py +++ b/hc/api/tests/test_notify.py @@ -1,6 +1,7 @@ import json from django.core import mail +from django.test import override_settings from hc.api.models import Channel, Check, Notification from hc.test import BaseTestCase from mock import patch @@ -12,6 +13,7 @@ class NotifyTestCase(BaseTestCase): def _setup_data(self, kind, value, status="down", email_verified=True): self.check = Check() self.check.status = status + self.check.user = self.alice self.check.save() self.channel = Channel(user=self.alice) @@ -127,6 +129,23 @@ class NotifyTestCase(BaseTestCase): self.assertEqual(n.error, "Email not verified") self.assertEqual(len(mail.outbox), 0) + @override_settings(USE_PAYMENTS=True) + def test_email_contains_upgrade_notice(self): + self._setup_data("email", "alice@example.org", status="up") + self.profile.team_access_allowed = False + self.profile.save() + + self.channel.notify(self.check) + + n = Notification.objects.get() + self.assertEqual(n.error, "") + + # Check is up, payments are enabled, and the user does not have team + # access: the email should contain upgrade note + message = mail.outbox[0] + html, _ = message.alternatives[0] + assert "/pricing/" in html + @patch("hc.api.transports.requests.request") def test_pd(self, mock_post): self._setup_data("pd", "123") diff --git a/hc/api/transports.py b/hc/api/transports.py index f651acba..644e7485 100644 --- a/hc/api/transports.py +++ b/hc/api/transports.py @@ -46,10 +46,16 @@ class Email(Transport): if not self.channel.email_verified: return "Email not verified" + show_upgrade_note = False + if settings.USE_PAYMENTS and check.status == "up": + if not check.user.profile.team_access_allowed: + show_upgrade_note = True + ctx = { "check": check, "checks": self.checks(), - "now": timezone.now() + "now": timezone.now(), + "show_upgrade_note": show_upgrade_note } emails.alert(self.channel.value, ctx) diff --git a/templates/emails/alert-body-html.html b/templates/emails/alert-body-html.html index 54158550..32a78de5 100644 --- a/templates/emails/alert-body-html.html +++ b/templates/emails/alert-body-html.html @@ -13,5 +13,12 @@ {% include "emails/summary-html.html" %} +{% if show_upgrade_note %} +
P.S. +Find this service useful? Support it by upgrading to +a premium account! +
+{% endif %} +Thanks,
The Healthchecks.io Team