Skip to content

Commit

Permalink
update other transports
Browse files Browse the repository at this point in the history
Signed-off-by: Jens Langhammer <jens@goauthentik.io>
  • Loading branch information
BeryJu committed May 8, 2023
1 parent 226a88e commit 9927cd1
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
11 changes: 10 additions & 1 deletion authentik/events/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,9 @@ def send_webhook(self, notification: "Notification") -> list[str]:
"user_email": notification.user.email,
"user_username": notification.user.username,
}
if notification.event and notification.event.user:
default_body["event_user_email"] = notification.event.user.get("email", None)
default_body["event_user_username"] = notification.event.user.get("username", None)
if self.webhook_mapping:
default_body = sanitize_item(
self.webhook_mapping.evaluate(
Expand Down Expand Up @@ -437,7 +440,13 @@ def send_webhook_slack(self, notification: "Notification") -> list[str]:
def send_email(self, notification: "Notification") -> list[str]:
"""Send notification via global email configuration"""
subject = "authentik Notification: "
key_value = {}
key_value = {
"user_email": notification.user.email,
"user_username": notification.user.username,
}
if notification.event and notification.event.user:
key_value["event_user_email"] = notification.event.user.get("email", None)
key_value["event_user_username"] = notification.event.user.get("username", None)
if notification.event:
subject += notification.event.action
for key, value in notification.event.context.items():
Expand Down
2 changes: 2 additions & 0 deletions authentik/events/tests/test_transports.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ def test_transport_webhook(self):
"severity": "alert",
"user_email": self.user.email,
"user_username": self.user.username,
"event_user_email": self.user.email,
"event_user_username": self.user.username,
},
)

Expand Down
8 changes: 6 additions & 2 deletions website/docs/events/transports.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,12 @@ This will send a POST request to the given URL with the following contents:
{
"body": "body of the notification message",
"severity": "severity level as configured in the trigger",
"user_email": "user's email",
"user_username": "user's username"
// User that the notification was created for, i.e. a member of the group selected in the rule
"user_email": "notification user's email",
"user_username": "notification user's username",
// User that created the event
"event_user_email": "event user's email",
"event_user_username": "event user's username"
}
```

Expand Down

0 comments on commit 9927cd1

Please sign in to comment.