2018-12-10 13:05:27 +00:00
|
|
|
"""passbook core signals"""
|
2019-03-21 10:29:11 +00:00
|
|
|
from django.core.cache import cache
|
2018-12-10 13:05:27 +00:00
|
|
|
from django.core.signals import Signal
|
2019-03-21 10:29:11 +00:00
|
|
|
from django.db.models.signals import post_save
|
2019-02-26 14:40:58 +00:00
|
|
|
from django.dispatch import receiver
|
2019-10-01 08:24:10 +00:00
|
|
|
from structlog import get_logger
|
2018-12-10 13:05:27 +00:00
|
|
|
|
2019-10-04 08:08:53 +00:00
|
|
|
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-02-26 14:40:58 +00:00
|
|
|
|
2019-12-31 11:45:29 +00:00
|
|
|
|
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"""
|
2020-05-16 16:07:00 +00:00
|
|
|
from passbook.policies.models import Policy
|
2020-02-24 12:15:27 +00:00
|
|
|
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):
|
2019-10-04 08:21:33 +00:00
|
|
|
LOGGER.debug("Invalidating policy cache", policy=instance)
|
2020-02-24 12:15:27 +00:00
|
|
|
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))
|