From ddd940688e457845dbf59c4d36a2a4e89d7a3310 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C4=93teris=20Caune?= Date: Sat, 4 Nov 2017 17:35:14 +0200 Subject: [PATCH] Disable channel (mark as email_verified=False) when email bounces. --- hc/api/tests/test_bounce.py | 4 ++++ hc/api/views.py | 3 +++ hc/front/tests/test_channels.py | 28 +++++++++++++++++++++++++++- static/css/channels.css | 5 +++++ templates/front/channels.html | 11 ++++++++++- 5 files changed, 49 insertions(+), 2 deletions(-) diff --git a/hc/api/tests/test_bounce.py b/hc/api/tests/test_bounce.py index 9b51019a..f166b445 100644 --- a/hc/api/tests/test_bounce.py +++ b/hc/api/tests/test_bounce.py @@ -14,6 +14,7 @@ class BounceTestCase(BaseTestCase): self.channel = Channel(user=self.alice, kind="email") self.channel.value = "alice@example.org" + self.channel.email_verified = True self.channel.save() self.n = Notification(owner=self.check, channel=self.channel) @@ -27,6 +28,9 @@ class BounceTestCase(BaseTestCase): self.n.refresh_from_db() self.assertEqual(self.n.error, "foo") + self.channel.refresh_from_db() + self.assertFalse(self.channel.email_verified) + def test_it_checks_ttl(self): self.n.created = self.n.created - timedelta(minutes=60) self.n.save() diff --git a/hc/api/views.py b/hc/api/views.py index 6f18e853..9da65f36 100644 --- a/hc/api/views.py +++ b/hc/api/views.py @@ -200,6 +200,9 @@ def bounce(request, code): notification.error = request.body[:200] notification.save() + notification.channel.email_verified = False + notification.channel.save() + return HttpResponse() diff --git a/hc/front/tests/test_channels.py b/hc/front/tests/test_channels.py index ab194d30..f09a318f 100644 --- a/hc/front/tests/test_channels.py +++ b/hc/front/tests/test_channels.py @@ -1,6 +1,6 @@ import json -from hc.api.models import Channel +from hc.api.models import Check, Channel, Notification from hc.test import BaseTestCase @@ -47,3 +47,29 @@ class ChannelsTestCase(BaseTestCase): self.assertEqual(r.status_code, 200) self.assertContains(r, "fake-key") self.assertContains(r, "(normal priority)") + + def test_it_shows_disabled_email(self): + check = Check(user=self.alice, status="up") + check.save() + + channel = Channel(user=self.alice, kind="email") + channel.value = "alice@example.org" + channel.save() + + n = Notification(owner=check, channel=channel, error="Invalid address") + n.save() + + self.client.login(username="alice@example.org", password="password") + r = self.client.get("/integrations/") + self.assertEqual(r.status_code, 200) + self.assertContains(r, "(bounced, disabled)") + + def test_it_shows_unconfirmed_email(self): + channel = Channel(user=self.alice, kind="email") + channel.value = "alice@example.org" + channel.save() + + self.client.login(username="alice@example.org", password="password") + r = self.client.get("/integrations/") + self.assertEqual(r.status_code, 200) + self.assertContains(r, "(unconfirmed)") diff --git a/static/css/channels.css b/static/css/channels.css index 7f70960e..0d2a0d5c 100644 --- a/static/css/channels.css +++ b/static/css/channels.css @@ -54,6 +54,11 @@ table.channels-table > tbody > tr > th { font-size: small; } +.channel-disabled { + font-size: small; +} + + .channels-help-hidden { display: none; } diff --git a/templates/front/channels.html b/templates/front/channels.html index 946093ee..a9557679 100644 --- a/templates/front/channels.html +++ b/templates/front/channels.html @@ -32,7 +32,16 @@ to {{ ch.value }} {% if not ch.email_verified %} - (unconfirmed) + {% if ch.latest_notification and ch.latest_notification.error %} + + (bounced, disabled) + + {% else %} + + (unconfirmed) + + {% endif %} + {% endif %} {% elif ch.kind == "pd" %} {% if ch.pd_account %}