events: pass Event's user to Notification policy engine when present

This commit is contained in:
Jens Langhammer 2021-02-11 19:56:39 +01:00
parent bba43c5109
commit ce0140ef67
1 changed files with 3 additions and 1 deletions

View File

@ -2,6 +2,7 @@
from guardian.shortcuts import get_anonymous_user from guardian.shortcuts import get_anonymous_user
from structlog import get_logger from structlog import get_logger
from authentik.core.models import User
from authentik.events.models import ( from authentik.events.models import (
Event, Event,
Notification, Notification,
@ -53,7 +54,8 @@ def event_trigger_handler(event_uuid: str, trigger_name: str):
return return
LOGGER.debug("e(trigger): checking if trigger applies", trigger=trigger) LOGGER.debug("e(trigger): checking if trigger applies", trigger=trigger)
policy_engine = PolicyEngine(trigger, get_anonymous_user()) user = User.objects.filter(pk=event.user.get("pk")) or get_anonymous_user()
policy_engine = PolicyEngine(trigger, user)
policy_engine.mode = PolicyEngineMode.MODE_OR policy_engine.mode = PolicyEngineMode.MODE_OR
policy_engine.empty_result = False policy_engine.empty_result = False
policy_engine.use_cache = False policy_engine.use_cache = False