events: improve information sent in notification emails

This commit is contained in:
Jens Langhammer 2021-02-04 21:44:06 +01:00
parent 580d59e921
commit 1f8130e685
3 changed files with 39 additions and 6 deletions

View File

@ -272,17 +272,24 @@ class NotificationTransport(models.Model):
def send_email(self, notification: "Notification") -> list[str]:
"""Send notification via global email configuration"""
body_trunc = (
(notification.body[:75] + "..")
if len(notification.body) > 75
else notification.body
)
subject = "authentik Notification: "
key_value = {}
if notification.event:
subject += notification.event.action
for key, value in notification.event.context.items():
if not isinstance(value, str):
continue
key_value[key] = value
else:
subject += notification.body[:75]
mail = TemplateEmailMessage(
subject=f"authentik Notification: {body_trunc}",
subject=subject,
template_name="email/generic.html",
to=[notification.user.email],
template_context={
"title": subject,
"body": notification.body,
"key_value": key_value,
},
)
# Email is sent directly here, as the call to send() should have been from a task.

View File

@ -1,5 +1,7 @@
{% extends "email/base.html" %}
{% load i18n %}
{% block content %}
<tr>
<td class="alert alert-brand">
@ -14,6 +16,29 @@
{{ body }}
</td>
</tr>
{% if key_value %}
<tr>
<td class="content-block aligncenter">
<table class="invoice">
<tr>
<td>{% trans "Additional Information" %}</td>
</tr>
<tr>
<td>
<table class="invoice-items" cellpadding="0" cellspacing="0">
{% for key, value in key_value.items %}
<tr>
<td>{{ key }}</td>
<td class="alignright">{{ value }}</td>
</tr>
{% endfor %}
</table>
</td>
</tr>
</table>
</td>
</tr>
{% endif %}
</table>
</td>
</tr>

View File

@ -2,6 +2,7 @@ import { gettext } from "django";
import { css, CSSResult, customElement, html, LitElement, property, TemplateResult } from "lit-element";
import { Event } from "../../api/Events";
import { COMMON_STYLES } from "../../common/styles";
import "./EventInfo";
@customElement("ak-event-info-page")
export class EventInfoPage extends LitElement {