From c521b44d205ca074d2a56d2e008e4026be12d290 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C4=93teris=20Caune?= Date: Wed, 8 Jan 2020 10:50:29 +0200 Subject: [PATCH] hc.api.views.bounce handles transient email bounces (logs error, does not disable the integration) --- hc/api/tests/test_bounce.py | 10 ++++++++++ hc/api/views.py | 5 +++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/hc/api/tests/test_bounce.py b/hc/api/tests/test_bounce.py index 46562345..7835abc7 100644 --- a/hc/api/tests/test_bounce.py +++ b/hc/api/tests/test_bounce.py @@ -54,3 +54,13 @@ class BounceTestCase(BaseTestCase): url = "/api/v1/notifications/%s/bounce" % self.n.code r = self.client.get(url) self.assertEqual(r.status_code, 405) + + def test_does_not_unsubscribe_transient_bounces(self): + url = "/api/v1/notifications/%s/bounce?type=Transient" % self.n.code + self.client.post(url, "foo", content_type="text/plain") + + self.n.refresh_from_db() + self.assertEqual(self.n.error, "foo") + + self.channel.refresh_from_db() + self.assertTrue(self.channel.email_verified) diff --git a/hc/api/views.py b/hc/api/views.py index 2e7a9830..4604aa79 100644 --- a/hc/api/views.py +++ b/hc/api/views.py @@ -272,8 +272,9 @@ def bounce(request, code): notification.error = request.body.decode()[:200] notification.save() - notification.channel.email_verified = False - notification.channel.save() + if request.GET.get("type") in (None, "Permanent"): + notification.channel.email_verified = False + notification.channel.save() return HttpResponse()