diff --git a/authentik/events/models.py b/authentik/events/models.py index 19ab7463f53..50ec8a71be6 100644 --- a/authentik/events/models.py +++ b/authentik/events/models.py @@ -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( @@ -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(): diff --git a/authentik/events/tests/test_transports.py b/authentik/events/tests/test_transports.py index e5f800aa677..3633f1ed5c0 100644 --- a/authentik/events/tests/test_transports.py +++ b/authentik/events/tests/test_transports.py @@ -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, }, ) diff --git a/website/docs/events/transports.md b/website/docs/events/transports.md index 3a52be4195c..3e95fdc6ea9 100644 --- a/website/docs/events/transports.md +++ b/website/docs/events/transports.md @@ -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" } ```