Browse Source

fix: 开启授权规则signal信号监听;解决授权规则变动用户授权树没有即使刷新的问题

pull/9239/head
Bai 2 years ago
parent
commit
ab6518e60e
  1. 1
      apps/assets/signal_handlers/asset.py
  2. 2
      apps/perms/apps.py
  3. 3
      apps/perms/models/perm_node.py
  4. 4
      apps/perms/signal_handlers/__init__.py
  5. 7
      apps/perms/utils/user_perm_tree.py

1
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'

2
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

3
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

4
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 *

7
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()

Loading…
Cancel
Save