Browse Source

Disable channel (mark as email_verified=False) when email bounces.

pull/142/head
Pēteris Caune 7 years ago
parent
commit
ddd940688e
5 changed files with 49 additions and 2 deletions
  1. +4
    -0
      hc/api/tests/test_bounce.py
  2. +3
    -0
      hc/api/views.py
  3. +27
    -1
      hc/front/tests/test_channels.py
  4. +5
    -0
      static/css/channels.css
  5. +10
    -1
      templates/front/channels.html

+ 4
- 0
hc/api/tests/test_bounce.py View File

@ -14,6 +14,7 @@ class BounceTestCase(BaseTestCase):
self.channel = Channel(user=self.alice, kind="email") self.channel = Channel(user=self.alice, kind="email")
self.channel.value = "[email protected]" self.channel.value = "[email protected]"
self.channel.email_verified = True
self.channel.save() self.channel.save()
self.n = Notification(owner=self.check, channel=self.channel) self.n = Notification(owner=self.check, channel=self.channel)
@ -27,6 +28,9 @@ class BounceTestCase(BaseTestCase):
self.n.refresh_from_db() self.n.refresh_from_db()
self.assertEqual(self.n.error, "foo") self.assertEqual(self.n.error, "foo")
self.channel.refresh_from_db()
self.assertFalse(self.channel.email_verified)
def test_it_checks_ttl(self): def test_it_checks_ttl(self):
self.n.created = self.n.created - timedelta(minutes=60) self.n.created = self.n.created - timedelta(minutes=60)
self.n.save() self.n.save()


+ 3
- 0
hc/api/views.py View File

@ -200,6 +200,9 @@ def bounce(request, code):
notification.error = request.body[:200] notification.error = request.body[:200]
notification.save() notification.save()
notification.channel.email_verified = False
notification.channel.save()
return HttpResponse() return HttpResponse()


+ 27
- 1
hc/front/tests/test_channels.py View File

@ -1,6 +1,6 @@
import json import json
from hc.api.models import Channel
from hc.api.models import Check, Channel, Notification
from hc.test import BaseTestCase from hc.test import BaseTestCase
@ -47,3 +47,29 @@ class ChannelsTestCase(BaseTestCase):
self.assertEqual(r.status_code, 200) self.assertEqual(r.status_code, 200)
self.assertContains(r, "fake-key") self.assertContains(r, "fake-key")
self.assertContains(r, "(normal priority)") 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 = "[email protected]"
channel.save()
n = Notification(owner=check, channel=channel, error="Invalid address")
n.save()
self.client.login(username="[email protected]", 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 = "[email protected]"
channel.save()
self.client.login(username="[email protected]", password="password")
r = self.client.get("/integrations/")
self.assertEqual(r.status_code, 200)
self.assertContains(r, "(unconfirmed)")

+ 5
- 0
static/css/channels.css View File

@ -54,6 +54,11 @@ table.channels-table > tbody > tr > th {
font-size: small; font-size: small;
} }
.channel-disabled {
font-size: small;
}
.channels-help-hidden { .channels-help-hidden {
display: none; display: none;
} }


+ 10
- 1
templates/front/channels.html View File

@ -32,7 +32,16 @@
<span class="preposition">to</span> <span class="preposition">to</span>
{{ ch.value }} {{ ch.value }}
{% if not ch.email_verified %} {% if not ch.email_verified %}
<span class="channel-unconfirmed">(unconfirmed)</span>
{% if ch.latest_notification and ch.latest_notification.error %}
<span class="channel-disabled">
(bounced, disabled)
</span>
{% else %}
<span class="channel-unconfirmed">
(unconfirmed)
</span>
{% endif %}
</span>
{% endif %} {% endif %}
{% elif ch.kind == "pd" %} {% elif ch.kind == "pd" %}
{% if ch.pd_account %} {% if ch.pd_account %}


Loading…
Cancel
Save