From fb9e2ac9f633b695e240057847e3f86ebfcf2978 Mon Sep 17 00:00:00 2001 From: ibuler Date: Wed, 6 Nov 2019 17:18:39 +0800 Subject: [PATCH] =?UTF-8?q?[Update]=20=E4=BF=AE=E6=94=B9=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E5=92=8C=E7=94=A8=E6=88=B7=E7=BB=84=E5=85=B3=E7=B3=BB=E5=8F=91?= =?UTF-8?q?=E7=94=9F=E5=8F=98=E5=8C=96=E6=97=B6=EF=BC=8C=E5=88=B7=E6=96=B0?= =?UTF-8?q?=E6=9D=83=E9=99=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/perms/signals_handler.py | 7 ------- apps/users/signals_handler.py | 15 +++++++++++++-- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/apps/perms/signals_handler.py b/apps/perms/signals_handler.py index eecd101e8..4a7fe389c 100644 --- a/apps/perms/signals_handler.py +++ b/apps/perms/signals_handler.py @@ -11,13 +11,6 @@ from .utils.asset_permission import AssetPermissionUtilV2 logger = get_logger(__file__) -permission_m2m_senders = ( - AssetPermission.nodes.through, - AssetPermission.assets.through, - AssetPermission.users.through, - AssetPermission.user_groups.through, -) - @receiver([post_save, post_delete], sender=AssetPermission) @on_transaction_commit diff --git a/apps/users/signals_handler.py b/apps/users/signals_handler.py index 4c6afc663..a33d9eec9 100644 --- a/apps/users/signals_handler.py +++ b/apps/users/signals_handler.py @@ -2,11 +2,11 @@ # from django.dispatch import receiver -# from django.db.models.signals import post_save +from django.db.models.signals import post_save, m2m_changed from common.utils import get_logger from .signals import post_user_create -# from .models import User +from .models import User logger = get_logger(__file__) @@ -28,3 +28,14 @@ def on_user_create(sender, user=None, **kwargs): logger.info(" - Sending welcome mail ...".format(user.name)) if user.email: send_user_created_mail(user) + + +@receiver(m2m_changed, sender=User.groups.through) +def on_user_groups_change(sender, instance=None, action='', **kwargs): + """ + 资产节点发生变化时,刷新节点 + """ + if action.startswith('post'): + logger.debug("User group member change signal recv: {}".format(instance)) + from perms.utils import AssetPermissionUtilV2 + AssetPermissionUtilV2.expire_all_user_tree_cache()