This repository has been archived on 2024-05-31. You can view files and clone it, but cannot push or open issues or pull requests.
authentik/passbook/core/signals.py

29 lines
1.0 KiB
Python
Raw Normal View History

"""passbook core signals"""
2019-03-21 10:29:11 +00:00
from django.core.cache import cache
from django.core.signals import Signal
2019-03-21 10:29:11 +00:00
from django.db.models.signals import post_save
from django.dispatch import receiver
2019-10-01 08:24:10 +00:00
from structlog import get_logger
LOGGER = get_logger()
2019-03-21 10:29:11 +00:00
2019-12-31 11:51:16 +00:00
user_signed_up = Signal(providing_args=["request", "user"])
invitation_created = Signal(providing_args=["request", "invitation"])
invitation_used = Signal(providing_args=["request", "invitation", "user"])
password_changed = Signal(providing_args=["user", "password"])
2019-03-21 10:29:11 +00:00
@receiver(post_save)
# pylint: disable=unused-argument
2019-10-07 14:33:48 +00:00
def invalidate_policy_cache(sender, instance, **_):
2019-03-21 10:29:11 +00:00
"""Invalidate Policy cache when policy is updated"""
from passbook.policies.models import Policy
from passbook.policies.process import cache_key
2019-12-31 11:51:16 +00:00
2019-03-21 10:29:11 +00:00
if isinstance(instance, Policy):
LOGGER.debug("Invalidating policy cache", policy=instance)
prefix = cache_key(instance) + "*"
keys = cache.keys(prefix)
2019-03-21 10:29:11 +00:00
cache.delete_many(keys)
LOGGER.debug("Deleted %d keys", len(keys))