authentik/passbook/core/signals.py

25 lines
956 B
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 09:24:10 +01:00
from structlog import get_logger
LOGGER = get_logger()
2019-03-21 10:29:11 +00:00
user_signed_up = Signal(providing_args=['request', 'user'])
2018-12-10 13:21:42 +00:00
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 15:33:48 +01:00
def invalidate_policy_cache(sender, instance, **_):
2019-03-21 10:29:11 +00:00
"""Invalidate Policy cache when policy is updated"""
from passbook.core.models import Policy
if isinstance(instance, Policy):
LOGGER.debug("Invalidating policy cache", policy=instance)
2019-03-21 10:29:11 +00:00
keys = cache.keys("%s#*" % instance.pk)
cache.delete_many(keys)
LOGGER.debug("Deleted %d keys", len(keys))