Add a "Subject" field in the "Ping Details" dialog

This commit is contained in:
Pēteris Caune 2021-02-26 11:19:44 +02:00
parent 1bc89f0d5d
commit 2a63d24812
No known key found for this signature in database
GPG Key ID: E28D7679E9A9EDE2
4 changed files with 24 additions and 0 deletions

View File

@ -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)

View File

@ -142,3 +142,16 @@ class PingDetailsTestCase(BaseTestCase):
# PGI+aGVsbG88L2I+ is base64("<b>hello</b>")
self.assertContains(r, "PGI+aGVsbG88L2I+")
self.assertContains(r, "&lt;b&gt;hello&lt;/b&gt;")
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)

View File

@ -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:

View File

@ -62,6 +62,15 @@
</p>
</div>
{% endif %}
{% if subject %}
<div class="col-sm-12">
<p>
<strong>Subject</strong>
<span>{{ subject }}</span>
</p>
</div>
{% endif %}
</div>
{% if ping.body %}