mirror of https://github.com/jumpserver/jumpserver
perf(perms): 优化根据资产获取授权的系统用户
parent
f6c24f809c
commit
c90b9d70dc
|
@ -11,16 +11,19 @@ logger = get_logger(__file__)
|
||||||
|
|
||||||
|
|
||||||
def get_asset_system_users_id_with_actions(asset_perm_queryset: BasePermissionQuerySet, asset: Asset):
|
def get_asset_system_users_id_with_actions(asset_perm_queryset: BasePermissionQuerySet, asset: Asset):
|
||||||
|
asset_perms_id = set(asset_perm_queryset.values_list('id', flat=True))
|
||||||
|
|
||||||
nodes = asset.get_nodes()
|
nodes = asset.get_nodes()
|
||||||
node_keys = set()
|
node_keys = set()
|
||||||
for node in nodes:
|
for node in nodes:
|
||||||
ancestor_keys = node.get_ancestor_keys(with_self=True)
|
ancestor_keys = node.get_ancestor_keys(with_self=True)
|
||||||
node_keys.update(ancestor_keys)
|
node_keys.update(ancestor_keys)
|
||||||
|
|
||||||
queryset = asset_perm_queryset.filter(
|
queryset = AssetPermission.objects.filter(id__in=asset_perms_id).filter(
|
||||||
Q(assets=asset) |
|
Q(assets=asset) |
|
||||||
Q(nodes__key__in=node_keys)
|
Q(nodes__key__in=node_keys)
|
||||||
)
|
)
|
||||||
|
|
||||||
asset_protocols = asset.protocols_as_dict.keys()
|
asset_protocols = asset.protocols_as_dict.keys()
|
||||||
values = queryset.filter(
|
values = queryset.filter(
|
||||||
system_users__protocol__in=asset_protocols
|
system_users__protocol__in=asset_protocols
|
||||||
|
|
Loading…
Reference in New Issue