authentik.enterprise.lifecycle.signals

Signal registry for the lifecycle app.

Receivers live in each feature package; importing them here connects them, as the app framework auto-imports <app>authentik.enterprise.lifecycle.signals.

 1"""Signal registry for the lifecycle app.
 2
 3Receivers live in each feature package; importing them here connects them, as
 4the app framework auto-imports `<app>.signals`.
 5"""
 6
 7from authentik.enterprise.lifecycle.expiration.signals import (
 8    expiration_on_user_logged_in,
 9    expiration_on_user_save,
10    expiration_post_rule_save,
11    expiration_pre_rule_delete,
12)
13from authentik.enterprise.lifecycle.review.signals import post_rule_save, pre_rule_delete
14
15__all__ = [
16    "expiration_on_user_logged_in",
17    "expiration_on_user_save",
18    "expiration_post_rule_save",
19    "expiration_pre_rule_delete",
20    "post_rule_save",
21    "pre_rule_delete",
22]
@receiver(user_logged_in)
def expiration_on_user_logged_in( sender, request: django.http.request.HttpRequest, user: authentik.core.models.User, **_):
14@receiver(user_logged_in)
15def expiration_on_user_logged_in(sender, request: HttpRequest, user: User, **_):
16    UserExpirationRule.withdraw_pending(user)
@receiver(post_save, sender=User)
def expiration_on_user_save( sender, instance: authentik.core.models.User, created: bool, update_fields, **_):
19@receiver(post_save, sender=User)
20def expiration_on_user_save(sender, instance: User, created: bool, update_fields, **_):
21    """Fallback for explicit `last_login` writes that bypass `login()`. Full saves are
22    skipped, execution rechecks `last_login` anyway."""
23    if created or instance.last_login is None:
24        return
25    if update_fields is None or "last_login" not in update_fields:
26        return
27    UserExpirationRule.withdraw_pending(instance, logged_in_at=instance.last_login)

Fallback for explicit last_login writes that bypass login(). Full saves are skipped, execution rechecks last_login anyway.

@receiver(post_save, sender=UserExpirationRule)
def expiration_post_rule_save( sender, instance: authentik.enterprise.lifecycle.expiration.models.UserExpirationRule, **_):
30@receiver(post_save, sender=UserExpirationRule)
31def expiration_post_rule_save(sender, instance: UserExpirationRule, **_):
32    from authentik.enterprise.lifecycle.expiration.tasks import (
33        apply_expiration_rule,
34        apply_expiration_rules,
35    )
36
37    # The schedule may not exist yet when blueprints are applied before schedules.
38    schedule = Schedule.objects.filter(actor_name=apply_expiration_rules.actor_name).first()
39    # Queue after commit, so the sweep sees the transports saved with the rule.
40    transaction.on_commit(
41        lambda: apply_expiration_rule.send_with_options(args=(str(instance.pk),), rel_obj=schedule)
42    )
@receiver(pre_delete, sender=UserExpirationRule)
def expiration_pre_rule_delete( sender, instance: authentik.enterprise.lifecycle.expiration.models.UserExpirationRule, **_):
45@receiver(pre_delete, sender=UserExpirationRule)
46def expiration_pre_rule_delete(sender, instance: UserExpirationRule, **_):
47    """Pending rows would otherwise lose their rule and run as manual offboardings."""
48    instance.offboardings.filter(status=OffboardingStatus.PENDING).delete()

Pending rows would otherwise lose their rule and run as manual offboardings.

@receiver(post_save, sender=LifecycleRule)
def post_rule_save( sender, instance: authentik.enterprise.lifecycle.review.models.LifecycleRule, created: bool, **_):
10@receiver(post_save, sender=LifecycleRule)
11def post_rule_save(sender, instance: LifecycleRule, created: bool, **_):
12    from authentik.enterprise.lifecycle.review.tasks import (
13        apply_lifecycle_rule,
14        apply_lifecycle_rules,
15    )
16
17    apply_lifecycle_rule.send_with_options(
18        args=(instance.id,),
19        rel_obj=Schedule.objects.get(actor_name=apply_lifecycle_rules.actor_name),
20    )
@receiver(pre_delete, sender=LifecycleRule)
def pre_rule_delete( sender, instance: authentik.enterprise.lifecycle.review.models.LifecycleRule, **_):
23@receiver(pre_delete, sender=LifecycleRule)
24def pre_rule_delete(sender, instance: LifecycleRule, **_):
25    instance.lifecycleiteration_set.filter(
26        Q(state=ReviewState.PENDING) | Q(state=ReviewState.OVERDUE)
27    ).update(state=ReviewState.CANCELED)