Browse Source

Don't allow adding email integrations with both "up" and "down" unchecked

pull/320/head
Pēteris Caune 5 years ago
parent
commit
3649c500d2
No known key found for this signature in database GPG Key ID: E28D7679E9A9EDE2
4 changed files with 31 additions and 8 deletions
  1. +1
    -0
      CHANGELOG.md
  2. +9
    -0
      hc/front/forms.py
  3. +13
    -6
      hc/front/tests/test_add_email.py
  4. +8
    -2
      templates/integrations/add_email.html

+ 1
- 0
CHANGELOG.md View File

@ -18,6 +18,7 @@ All notable changes to this project will be documented in this file.
- For webhook integration, validate each header line separately - For webhook integration, validate each header line separately
- Fix "Send Test Notification" for webhooks that only fire on checks going up - 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 webhook integrations with both URLs blank
- Don't allow adding email integrations with both "up" and "down" unchecked
## v1.11.0 - 2019-11-22 ## v1.11.0 - 2019-11-22


+ 9
- 0
hc/front/forms.py View File

@ -96,6 +96,15 @@ class AddEmailForm(forms.Form):
down = forms.BooleanField(required=False, initial=True) down = forms.BooleanField(required=False, initial=True)
up = 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): class AddUrlForm(forms.Form):
error_css_class = "has-error" error_css_class = "has-error"


+ 13
- 6
hc/front/tests/test_add_email.py View File

@ -17,7 +17,7 @@ class AddEmailTestCase(BaseTestCase):
self.assertContains(r, "Requires confirmation") self.assertContains(r, "Requires confirmation")
def test_it_creates_channel(self): def test_it_creates_channel(self):
form = {"value": "[email protected]"}
form = {"value": "[email protected]", "down": "true", "up": "true"}
self.client.login(username="[email protected]", password="password") self.client.login(username="[email protected]", password="password")
r = self.client.post(self.url, form) r = self.client.post(self.url, form)
@ -39,7 +39,7 @@ class AddEmailTestCase(BaseTestCase):
self.assertEqual(email.to[0], "[email protected]") self.assertEqual(email.to[0], "[email protected]")
def test_team_access_works(self): def test_team_access_works(self):
form = {"value": "[email protected]"}
form = {"value": "[email protected]", "down": "true", "up": "true"}
self.client.login(username="[email protected]", password="password") self.client.login(username="[email protected]", password="password")
self.client.post(self.url, form) self.client.post(self.url, form)
@ -49,14 +49,14 @@ class AddEmailTestCase(BaseTestCase):
self.assertEqual(ch.project, self.project) self.assertEqual(ch.project, self.project)
def test_it_rejects_bad_email(self): 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="[email protected]", password="password") self.client.login(username="[email protected]", password="password")
r = self.client.post(self.url, form) r = self.client.post(self.url, form)
self.assertContains(r, "Enter a valid email address.") self.assertContains(r, "Enter a valid email address.")
def test_it_trims_whitespace(self): def test_it_trims_whitespace(self):
form = {"value": " [email protected] "}
form = {"value": " [email protected] ", "down": "true", "up": "true"}
self.client.login(username="[email protected]", password="password") self.client.login(username="[email protected]", password="password")
self.client.post(self.url, form) self.client.post(self.url, form)
@ -73,7 +73,7 @@ class AddEmailTestCase(BaseTestCase):
@override_settings(EMAIL_USE_VERIFICATION=False) @override_settings(EMAIL_USE_VERIFICATION=False)
def test_it_auto_verifies_email(self): def test_it_auto_verifies_email(self):
form = {"value": "[email protected]"}
form = {"value": "[email protected]", "down": "true", "up": "true"}
self.client.login(username="[email protected]", password="password") self.client.login(username="[email protected]", password="password")
r = self.client.post(self.url, form) r = self.client.post(self.url, form)
@ -89,7 +89,7 @@ class AddEmailTestCase(BaseTestCase):
self.assertEqual(len(mail.outbox), 0) self.assertEqual(len(mail.outbox), 0)
def test_it_auto_verifies_own_email(self): def test_it_auto_verifies_own_email(self):
form = {"value": "[email protected]"}
form = {"value": "[email protected]", "down": "true", "up": "true"}
self.client.login(username="[email protected]", password="password") self.client.login(username="[email protected]", password="password")
r = self.client.post(self.url, form) r = self.client.post(self.url, form)
@ -103,3 +103,10 @@ class AddEmailTestCase(BaseTestCase):
# Email should *not* have been sent # Email should *not* have been sent
self.assertEqual(len(mail.outbox), 0) self.assertEqual(len(mail.outbox), 0)
def test_it_rejects_unchecked_up_and_dwon(self):
form = {"value": "[email protected]"}
self.client.login(username="[email protected]", password="password")
r = self.client.post(self.url, form)
self.assertContains(r, "Please select at least one.")

+ 8
- 2
templates/integrations/add_email.html View File

@ -42,7 +42,7 @@
</div> </div>
</div> </div>
<div id="add-email-notify-group" class="form-group">
<div id="add-email-notify-group" class="form-group {{ form.down.css_classes }}">
<label class="col-sm-2 control-label">Notify When</label> <label class="col-sm-2 control-label">Notify When</label>
<div class="col-sm-10"> <div class="col-sm-10">
<label class="checkbox-container"> <label class="checkbox-container">
@ -62,11 +62,17 @@
{% if form.up.value %} checked {% endif %}> {% if form.up.value %} checked {% endif %}>
<span class="checkmark"></span> <span class="checkmark"></span>
A check goes <strong>up</strong> A check goes <strong>up</strong>
</span>
{% if form.down.errors %}
<div class="help-block">
{{ form.down.errors|join:"" }}
</div>
{% else %}
<br /> <br />
<span class="text-muted"> <span class="text-muted">
Ticketing system integrations: untick this and avoid creating new tickets Ticketing system integrations: untick this and avoid creating new tickets
when checks come back up. when checks come back up.
</span>
{% endif %}
</label> </label>
</div> </div>
</div> </div>


Loading…
Cancel
Save