Browse Source

Add a link to check's details page in Slack notifications

Fixes: #486
pull/488/head
Pēteris Caune 4 years ago
parent
commit
5321f772fe
No known key found for this signature in database GPG Key ID: E28D7679E9A9EDE2
8 changed files with 49 additions and 1 deletions
  1. +1
    -0
      CHANGELOG.md
  2. +1
    -0
      hc/accounts/views.py
  3. +3
    -0
      hc/api/models.py
  4. +3
    -0
      hc/api/tests/test_notify_slack.py
  5. +29
    -0
      hc/front/tests/test_uncloak.py
  6. +1
    -0
      hc/front/urls.py
  7. +9
    -0
      hc/front/views.py
  8. +2
    -1
      templates/integrations/slack_message.json

+ 1
- 0
CHANGELOG.md View File

@ -8,6 +8,7 @@ All notable changes to this project will be documented in this file.
- Implement email body decoding in the "Ping Details" dialog
- Add a "Subject" field in the "Ping Details" dialog
- Improve HTML email display in the "Ping Details" dialog
- Add a link to check's details page in Slack notifications
## Bug Fixes
- Fix downtime summary to handle months when the check didn't exist yet (#472)


+ 1
- 0
hc/accounts/views.py View File

@ -41,6 +41,7 @@ POST_LOGIN_ROUTES = (
"hc-add-pushover",
"hc-add-telegram",
"hc-project-settings",
"hc-uncloak",
)
FIDO2_SERVER = Fido2Server(PublicKeyCredentialRpEntity(settings.RP_ID, "healthchecks"))


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

@ -118,6 +118,9 @@ class Check(models.Model):
def details_url(self):
return settings.SITE_ROOT + reverse("hc-details", args=[self.code])
def cloaked_url(self):
return settings.SITE_ROOT + reverse("hc-uncloak", args=[self.unique_key])
def email(self):
return "%s@%s" % (self.code, settings.PING_EMAIL_DOMAIN)


+ 3
- 0
hc/api/tests/test_notify_slack.py View File

@ -39,6 +39,9 @@ class NotifyTestCase(BaseTestCase):
fields = {f["title"]: f["value"] for f in attachment["fields"]}
self.assertEqual(fields["Last Ping"], "an hour ago")
uncloak_url = "/cloaked/%s/" % self.check.unique_key
self.assertTrue(attachment["title_link"].endswith(uncloak_url))
@patch("hc.api.transports.requests.request")
def test_slack_with_complex_value(self, mock_post):
v = json.dumps({"incoming_webhook": {"url": "123"}})


+ 29
- 0
hc/front/tests/test_uncloak.py View File

@ -0,0 +1,29 @@
from hc.api.models import Check
from hc.test import BaseTestCase
class UncloakTestCase(BaseTestCase):
def setUp(self):
super().setUp()
self.check = Check.objects.create(project=self.project, status="paused")
self.url = "/cloaked/%s/" % self.check.unique_key
self.redirect_url = "/checks/%s/details/" % self.check.code
def test_it_redirects(self):
self.client.login(username="[email protected]", password="password")
r = self.client.get(self.url)
self.assertRedirects(r, self.redirect_url)
def test_it_handles_bad_unique_key(self):
self.client.login(username="[email protected]", password="password")
r = self.client.get("/cloaked/0beec7b5ea3f0fdbc95d0dd47f3c5bc275da8a33/")
self.assertEqual(r.status_code, 404)
def test_it_checks_access(self):
self.client.login(username="[email protected]", password="password")
r = self.client.get(self.url)
self.assertEqual(r.status_code, 404)
def test_it_requires_logged_in_user(self):
r = self.client.get(self.url)
self.assertRedirects(r, "/accounts/login/?next=" + self.url)

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

@ -92,6 +92,7 @@ urlpatterns = [
path("tv/", views.dashboard, name="hc-dashboard"),
path("checks/cron_preview/", views.cron_preview),
path("checks/<uuid:code>/", include(check_urls)),
path("cloaked/<sha1:unique_key>/", views.uncloak, name="hc-uncloak"),
path("integrations/", include(channel_urls)),
path("projects/<uuid:code>/", include(project_urls)),
path("docs/", views.serve_doc, name="hc-docs"),


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

@ -637,6 +637,15 @@ def details(request, code):
return render(request, "front/details.html", ctx)
@login_required
def uncloak(request, unique_key):
for check in request.profile.checks_from_all_projects().only("code"):
if check.unique_key == unique_key:
return redirect("hc-details", check.code)
raise Http404("not found")
@login_required
def transfer(request, code):
check = _get_rw_check_for_user(request, code)


+ 2
- 1
templates/integrations/slack_message.json View File

@ -11,7 +11,8 @@
"fallback": "The check \"{{ check.name_then_code|escapejs }}\" is {{ check.status|upper }}.",
"mrkdwn_in": ["fields"],
"text": "“{{ check.name_then_code|escapejs }}” is {{ check.status|upper }}.",
"title": "“{{ check.name_then_code|escapejs }}” is {{ check.status|upper }}.",
"title_link": "{{ check.cloaked_url }}",
"fields": [
{% if check.desc %}
{"title": "Description",


Loading…
Cancel
Save