diff --git a/CHANGELOG.md b/CHANGELOG.md index 97b4886e..5b681223 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,7 @@ All notable changes to this project will be documented in this file. - For webhook integration, validate each header line separately - Fix "Send Test Notification" for webhooks that only fire on checks going up - Don't allow adding webhook integrations with both URLs blank +- Don't allow adding email integrations with both "up" and "down" unchecked ## v1.11.0 - 2019-11-22 diff --git a/hc/front/forms.py b/hc/front/forms.py index c9c86c9d..e640dbad 100644 --- a/hc/front/forms.py +++ b/hc/front/forms.py @@ -96,6 +96,15 @@ class AddEmailForm(forms.Form): down = forms.BooleanField(required=False, initial=True) up = forms.BooleanField(required=False, initial=True) + def clean(self): + super().clean() + + down = self.cleaned_data.get("down") + up = self.cleaned_data.get("up") + + if not down and not up: + self.add_error("down", "Please select at least one.") + class AddUrlForm(forms.Form): error_css_class = "has-error" diff --git a/hc/front/tests/test_add_email.py b/hc/front/tests/test_add_email.py index 3431ad42..e631ccd4 100644 --- a/hc/front/tests/test_add_email.py +++ b/hc/front/tests/test_add_email.py @@ -17,7 +17,7 @@ class AddEmailTestCase(BaseTestCase): self.assertContains(r, "Requires confirmation") def test_it_creates_channel(self): - form = {"value": "dan@example.org"} + form = {"value": "dan@example.org", "down": "true", "up": "true"} self.client.login(username="alice@example.org", password="password") r = self.client.post(self.url, form) @@ -39,7 +39,7 @@ class AddEmailTestCase(BaseTestCase): self.assertEqual(email.to[0], "dan@example.org") def test_team_access_works(self): - form = {"value": "bob@example.org"} + form = {"value": "bob@example.org", "down": "true", "up": "true"} self.client.login(username="bob@example.org", password="password") self.client.post(self.url, form) @@ -49,14 +49,14 @@ class AddEmailTestCase(BaseTestCase): self.assertEqual(ch.project, self.project) def test_it_rejects_bad_email(self): - form = {"value": "not an email address"} + form = {"value": "not an email address", "down": "true", "up": "true"} self.client.login(username="alice@example.org", password="password") r = self.client.post(self.url, form) self.assertContains(r, "Enter a valid email address.") def test_it_trims_whitespace(self): - form = {"value": " alice@example.org "} + form = {"value": " alice@example.org ", "down": "true", "up": "true"} self.client.login(username="alice@example.org", password="password") self.client.post(self.url, form) @@ -73,7 +73,7 @@ class AddEmailTestCase(BaseTestCase): @override_settings(EMAIL_USE_VERIFICATION=False) def test_it_auto_verifies_email(self): - form = {"value": "dan@example.org"} + form = {"value": "dan@example.org", "down": "true", "up": "true"} self.client.login(username="alice@example.org", password="password") r = self.client.post(self.url, form) @@ -89,7 +89,7 @@ class AddEmailTestCase(BaseTestCase): self.assertEqual(len(mail.outbox), 0) def test_it_auto_verifies_own_email(self): - form = {"value": "alice@example.org"} + form = {"value": "alice@example.org", "down": "true", "up": "true"} self.client.login(username="alice@example.org", password="password") r = self.client.post(self.url, form) @@ -103,3 +103,10 @@ class AddEmailTestCase(BaseTestCase): # Email should *not* have been sent self.assertEqual(len(mail.outbox), 0) + + def test_it_rejects_unchecked_up_and_dwon(self): + form = {"value": "alice@example.org"} + + self.client.login(username="alice@example.org", password="password") + r = self.client.post(self.url, form) + self.assertContains(r, "Please select at least one.") diff --git a/templates/integrations/add_email.html b/templates/integrations/add_email.html index 402968a7..27383dd9 100644 --- a/templates/integrations/add_email.html +++ b/templates/integrations/add_email.html @@ -42,7 +42,7 @@ -