mirror of https://github.com/jumpserver/jumpserver
perf(perms): 优化方法名称;授权查询语句;
parent
c02f8e499b
commit
676ee93837
|
@ -13,7 +13,7 @@ from perms.utils.asset.user_permission import (
|
||||||
get_user_direct_granted_assets, get_top_level_granted_nodes,
|
get_user_direct_granted_assets, get_top_level_granted_nodes,
|
||||||
get_user_granted_nodes_list_via_mapping_node,
|
get_user_granted_nodes_list_via_mapping_node,
|
||||||
get_user_granted_all_assets, rebuild_user_tree_if_need,
|
get_user_granted_all_assets, rebuild_user_tree_if_need,
|
||||||
get_user_all_assetpermission_ids,
|
get_user_all_assetpermissions_id,
|
||||||
)
|
)
|
||||||
|
|
||||||
from assets.models import Asset, FavoriteAsset
|
from assets.models import Asset, FavoriteAsset
|
||||||
|
@ -63,7 +63,7 @@ class UserGrantedNodeChildrenWithAssetsAsTreeForAdminApi(ForAdminMixin, UserNode
|
||||||
|
|
||||||
def get_data_on_node_indirect_granted(self, key):
|
def get_data_on_node_indirect_granted(self, key):
|
||||||
user = self.user
|
user = self.user
|
||||||
asset_perm_ids = get_user_all_assetpermission_ids(user)
|
asset_perm_ids = get_user_all_assetpermissions_id(user)
|
||||||
|
|
||||||
nodes = get_indirect_granted_node_children(user, key)
|
nodes = get_indirect_granted_node_children(user, key)
|
||||||
|
|
||||||
|
|
|
@ -1,21 +1,18 @@
|
||||||
|
from django.db.models import Q
|
||||||
from perms.models import ApplicationPermission
|
from perms.models import ApplicationPermission
|
||||||
from applications.models import Application
|
from applications.models import Application
|
||||||
|
|
||||||
|
|
||||||
def get_user_all_applicationpermission_ids(user):
|
def get_user_all_applicationpermissions_id(user):
|
||||||
application_perm_ids = set()
|
application_perm_ids = ApplicationPermission.objects.valid().filter(
|
||||||
application_perm_ids.update(
|
Q(users=user) | Q(user_groups__users=user)
|
||||||
ApplicationPermission.objects.valid().filter(users=user).distinct().values_list('id', flat=True)
|
).distinct().values_list('id', flat=True)
|
||||||
)
|
|
||||||
application_perm_ids.update(
|
|
||||||
ApplicationPermission.objects.valid().filter(user_groups__users=user).distinct().values_list('id', flat=True)
|
|
||||||
)
|
|
||||||
return application_perm_ids
|
return application_perm_ids
|
||||||
|
|
||||||
|
|
||||||
def get_user_granted_all_applications(user):
|
def get_user_granted_all_applications(user):
|
||||||
application_perm_ids = get_user_all_applicationpermission_ids(user)
|
application_perms_id = get_user_all_applicationpermissions_id(user)
|
||||||
applications = Application.objects.filter(
|
applications = Application.objects.filter(
|
||||||
granted_by_permissions__id__in=application_perm_ids
|
granted_by_permissions__id__in=application_perms_id
|
||||||
).distinct()
|
).distinct()
|
||||||
return applications
|
return applications
|
||||||
|
|
|
@ -305,7 +305,7 @@ def get_user_granted_nodes_list_via_mapping_node(user):
|
||||||
|
|
||||||
|
|
||||||
def get_user_granted_all_assets(user, via_mapping_node=True):
|
def get_user_granted_all_assets(user, via_mapping_node=True):
|
||||||
asset_perm_ids = get_user_all_assetpermission_ids(user)
|
asset_perm_ids = get_user_all_assetpermissions_id(user)
|
||||||
if via_mapping_node:
|
if via_mapping_node:
|
||||||
granted_node_keys = UserGrantedMappingNode.objects.filter(
|
granted_node_keys = UserGrantedMappingNode.objects.filter(
|
||||||
user=user, granted=True,
|
user=user, granted=True,
|
||||||
|
@ -455,21 +455,17 @@ def get_top_level_granted_nodes(user):
|
||||||
return nodes
|
return nodes
|
||||||
|
|
||||||
|
|
||||||
def get_user_all_assetpermission_ids(user: User):
|
def get_user_all_assetpermissions_id(user: User):
|
||||||
asset_perm_ids = set()
|
asset_perms_id = AssetPermission.objects.valid().filter(
|
||||||
asset_perm_ids.update(
|
Q(users=user) | Q(user_groups__users=user)
|
||||||
AssetPermission.objects.valid().filter(users=user).distinct().values_list('id', flat=True)
|
).distinct().values_list('id', flat=True)
|
||||||
)
|
return asset_perms_id
|
||||||
asset_perm_ids.update(
|
|
||||||
AssetPermission.objects.valid().filter(user_groups__users=user).distinct().values_list('id', flat=True)
|
|
||||||
)
|
|
||||||
return asset_perm_ids
|
|
||||||
|
|
||||||
|
|
||||||
def get_user_direct_granted_assets(user, asset_perm_ids=None):
|
def get_user_direct_granted_assets(user, asset_perms_id=None):
|
||||||
if asset_perm_ids is None:
|
if asset_perms_id is None:
|
||||||
asset_perm_ids = get_user_all_assetpermission_ids(user)
|
asset_perms_id = get_user_all_assetpermissions_id(user)
|
||||||
assets = Asset.org_objects.filter(granted_by_permissions__id__in=asset_perm_ids).distinct()
|
assets = Asset.org_objects.filter(granted_by_permissions__id__in=asset_perms_id).distinct()
|
||||||
return assets
|
return assets
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue