Browse Source

Add "Test!" function in the Integrations page. Fixes #207

pull/248/head
Pēteris Caune 6 years ago
parent
commit
ab86580b32
No known key found for this signature in database GPG Key ID: E28D7679E9A9EDE2
6 changed files with 73 additions and 3 deletions
  1. +1
    -0
      CHANGELOG.md
  2. +30
    -0
      hc/front/tests/test_send_test_notification.py
  3. +1
    -0
      hc/front/urls.py
  4. +24
    -0
      hc/front/views.py
  5. +6
    -2
      static/css/channels.css
  6. +11
    -1
      templates/front/channels.html

+ 1
- 0
CHANGELOG.md View File

@ -8,6 +8,7 @@ All notable changes to this project will be documented in this file.
- Show "Badges" and "Settings" in top navigation (#234)
- Upgrade to Django 2.2
- Can configure the email integration to only report the "down" events (#231)
- Add "Test!" function in the Integrations page (#207)
## 1.6.0 - 2019-04-01


+ 30
- 0
hc/front/tests/test_send_test_notification.py View File

@ -0,0 +1,30 @@
from django.core import mail
from hc.api.models import Channel
from hc.test import BaseTestCase
class SendTestNotificationTestCase(BaseTestCase):
def setUp(self):
super(SendTestNotificationTestCase, self).setUp()
self.channel = Channel(kind="email", project=self.project)
self.channel.email_verified = True
self.channel.value = "[email protected]"
self.channel.save()
self.url = "/integrations/%s/test/" % self.channel.code
def test_it_sends_test_email(self):
self.client.login(username="[email protected]", password="password")
r = self.client.post(self.url, {}, follow=True)
self.assertRedirects(r, "/integrations/")
self.assertContains(r, "Test notification sent!")
# And email should have been sent
self.assertEqual(len(mail.outbox), 1)
email = mail.outbox[0]
self.assertEqual(email.to[0], "[email protected]")
self.assertTrue("X-Bounce-Url" in email.extra_headers)
self.assertTrue("List-Unsubscribe" in email.extra_headers)

+ 1
- 0
hc/front/urls.py View File

@ -40,6 +40,7 @@ channel_urls = [
path('add_matrix/', views.add_matrix, name="hc-add-matrix"),
path('<uuid:code>/checks/', views.channel_checks, name="hc-channel-checks"),
path('<uuid:code>/name/', views.update_channel_name, name="hc-channel-name"),
path('<uuid:code>/test/', views.send_test_notification, name="hc-channel-test"),
path('<uuid:code>/remove/', views.remove_channel, name="hc-remove-channel"),
path('<uuid:code>/verify/<slug:token>/', views.verify_email,
name="hc-verify-email"),


+ 24
- 0
hc/front/views.py View File

@ -659,6 +659,30 @@ def unsubscribe_email(request, code, token):
return render(request, "front/unsubscribe_success.html")
@require_POST
@login_required
def send_test_notification(request, code):
channel = get_object_or_404(Channel, code=code)
if channel.project_id != request.project.id:
return HttpResponseForbidden()
dummy = Check(name="TEST", status="down")
dummy.last_ping = timezone.now() - td(days=1)
dummy.n_pings = 42
if channel.kind == "email":
error = channel.transport.notify(dummy, channel.get_unsub_link())
else:
error = channel.transport.notify(dummy)
if error:
messages.warning(request, "Could not send a test notification: %s" % error)
else:
messages.success(request, "Test notification sent!")
return redirect("hc-channels")
@require_POST
@login_required
def remove_channel(request, code):


+ 6
- 2
static/css/channels.css View File

@ -105,11 +105,15 @@ table.channels-table > tbody > tr > th {
color: #000;
}
.channel-remove {
.channel-row .actions form {
display: inline;
}
.channel-row .actions .btn {
visibility: hidden;
}
.channel-row:hover .channel-remove {
.channel-row:hover .actions .btn {
visibility: visible;
}


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

@ -131,7 +131,17 @@
<p>Used {{ profile.sms_sent_this_month }} of {{ profile.sms_limit }} sends this month.</p>
{% endif %}
</td>
<td>
<td class="actions">
<form action="{% url 'hc-channel-test' ch.code %}" method="post">
{% csrf_token %}
<button
class="btn btn-sm btn-default"
data-toggle="tooltip"
title="Send a test notification using this integration"
type="submit">
Test!
</button>
</form>
<button
data-kind="{{ ch.get_kind_display }}"
data-url="{% url 'hc-remove-channel' ch.code %}"


Loading…
Cancel
Save