From ab6518e60ecd4af13be8dd72bbcd98d5164f5ff4 Mon Sep 17 00:00:00 2001 From: Bai Date: Thu, 22 Dec 2022 18:56:54 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=BC=80=E5=90=AF=E6=8E=88=E6=9D=83?= =?UTF-8?q?=E8=A7=84=E5=88=99signal=E4=BF=A1=E5=8F=B7=E7=9B=91=E5=90=AC;?= =?UTF-8?q?=E8=A7=A3=E5=86=B3=E6=8E=88=E6=9D=83=E8=A7=84=E5=88=99=E5=8F=98?= =?UTF-8?q?=E5=8A=A8=E7=94=A8=E6=88=B7=E6=8E=88=E6=9D=83=E6=A0=91=E6=B2=A1?= =?UTF-8?q?=E6=9C=89=E5=8D=B3=E4=BD=BF=E5=88=B7=E6=96=B0=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/assets/signal_handlers/asset.py | 1 + apps/perms/apps.py | 2 +- apps/perms/models/perm_node.py | 3 +++ apps/perms/signal_handlers/__init__.py | 4 ++-- apps/perms/utils/user_perm_tree.py | 7 +++---- 5 files changed, 10 insertions(+), 7 deletions(-) diff --git a/apps/assets/signal_handlers/asset.py b/apps/assets/signal_handlers/asset.py index 5aac26319..86e6a0a9a 100644 --- a/apps/assets/signal_handlers/asset.py +++ b/apps/assets/signal_handlers/asset.py @@ -103,6 +103,7 @@ def on_asset_nodes_add(instance, action, reverse, pk_set, **kwargs): # m2m_model.objects.bulk_create(to_create) # + RELATED_NODE_IDS = '_related_node_ids' diff --git a/apps/perms/apps.py b/apps/perms/apps.py index f9d1e6f42..432c194cd 100644 --- a/apps/perms/apps.py +++ b/apps/perms/apps.py @@ -10,5 +10,5 @@ class PermsConfig(AppConfig): def ready(self): super().ready() - # from . import signal_handlers + from . import signal_handlers from . import notifications diff --git a/apps/perms/models/perm_node.py b/apps/perms/models/perm_node.py index 438cd5b2d..1db0f2fe7 100644 --- a/apps/perms/models/perm_node.py +++ b/apps/perms/models/perm_node.py @@ -32,6 +32,9 @@ class UserAssetGrantedTreeNodeRelation(FamilyMixin, JMSOrgBaseModel): node_assets_amount = models.IntegerField(default=0) comment = '' + def __str__(self): + return f'{self.user}|{self.node}' + @property def key(self): return self.node_key diff --git a/apps/perms/signal_handlers/__init__.py b/apps/perms/signal_handlers/__init__.py index 6a8ef9467..02faddd04 100644 --- a/apps/perms/signal_handlers/__init__.py +++ b/apps/perms/signal_handlers/__init__.py @@ -1,2 +1,2 @@ -from . import asset_permission -from . import refresh_perms +from .asset_permission import * +from .refresh_perms import * diff --git a/apps/perms/utils/user_perm_tree.py b/apps/perms/utils/user_perm_tree.py index 7937f2c6f..8888a67e9 100644 --- a/apps/perms/utils/user_perm_tree.py +++ b/apps/perms/utils/user_perm_tree.py @@ -121,9 +121,8 @@ class UserPermTreeExpireUtil(_UserPermTreeCacheMixin): for org_id, perm_id in org_perm_ids: org_perms_mapper[org_id].add(perm_id) for org_id, perms_id in org_perms_mapper.items(): - org_ids = [org_id] user_ids = AssetPermission.get_all_users_for_perms(perm_ids, flat=True) - self.expire_perm_tree_for_users_orgs(user_ids, org_ids) + self.expire_perm_tree_for_users_orgs(user_ids, [org_id]) def expire_perm_tree_for_user_group(self, user_group): group_ids = [user_group.id] @@ -138,7 +137,7 @@ class UserPermTreeExpireUtil(_UserPermTreeCacheMixin): @on_transaction_commit def expire_perm_tree_for_users_orgs(self, user_ids, org_ids): org_ids = [str(oid) for oid in org_ids] - with self.client.pipline() as p: + with self.client.pipeline() as p: for uid in user_ids: cache_key = self.get_cache_key(uid) p.srem(cache_key, *org_ids) @@ -147,7 +146,7 @@ class UserPermTreeExpireUtil(_UserPermTreeCacheMixin): def expire_perm_tree_for_all_user(self): keys = self.client.keys(self.cache_key_all_user) - with self.client.pipline() as p: + with self.client.pipeline() as p: for k in keys: p.delete(k) p.execute()