From 2a63d2481274b910ed22137b33637eb9d916736a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C4=93teris=20Caune?= Date: Fri, 26 Feb 2021 11:19:44 +0200 Subject: [PATCH] Add a "Subject" field in the "Ping Details" dialog --- CHANGELOG.md | 1 + hc/front/tests/test_ping_details.py | 13 +++++++++++++ hc/front/views.py | 1 + templates/front/ping_details.html | 9 +++++++++ 4 files changed, 24 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 897c9de9..7acb3d47 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ All notable changes to this project will be documented in this file. ## Improvements - Rename VictorOps -> Splunk On-Call - Implement email body decoding in the "Ping Details" dialog +- Add a "Subject" field in the "Ping Details" dialog ## Bug Fixes - Fix downtime summary to handle months when the check didn't exist yet (#472) diff --git a/hc/front/tests/test_ping_details.py b/hc/front/tests/test_ping_details.py index ddf94d3a..ad84d190 100644 --- a/hc/front/tests/test_ping_details.py +++ b/hc/front/tests/test_ping_details.py @@ -142,3 +142,16 @@ class PingDetailsTestCase(BaseTestCase): # PGI+aGVsbG88L2I+ is base64("hello") self.assertContains(r, "PGI+aGVsbG88L2I+") self.assertContains(r, "<b>hello</b>") + + def test_it_decodes_email_subject(self): + Ping.objects.create( + owner=self.check, + scheme="email", + body="Subject: =?UTF-8?B?aGVsbG8gd29ybGQ=?=", + ) + + self.client.login(username="alice@example.org", password="password") + r = self.client.get(self.url) + + # aGVsbG8gd29ybGQ= is base64("hello world") + self.assertContains(r, "hello world", status_code=200) diff --git a/hc/front/views.py b/hc/front/views.py index 3cb12002..ae0f602e 100644 --- a/hc/front/views.py +++ b/hc/front/views.py @@ -512,6 +512,7 @@ def ping_details(request, code, n=None): if ping.scheme == "email": parsed = email.message_from_string(ping.body, policy=email.policy.SMTP) + ctx["subject"] = parsed.get("subject", "") plain_mime_part = parsed.get_body(("plain",)) if plain_mime_part: diff --git a/templates/front/ping_details.html b/templates/front/ping_details.html index ea0a8416..3e7857a4 100644 --- a/templates/front/ping_details.html +++ b/templates/front/ping_details.html @@ -62,6 +62,15 @@

{% endif %} + + {% if subject %} +
+

+ Subject + {{ subject }} +

+
+ {% endif %} {% if ping.body %}