refactor: 重构资产授权工具、资产授权账号工具类

pull/8991/head
Jiangjie.Bai 2 years ago
parent c41e0148d9
commit 2c04ad6465

@ -43,7 +43,8 @@ class AssetPermissionUtil(object):
def get_permissions_for_user_groups(user_groups, flat=False):
""" 获取用户组的授权规则 """
group_ids = user_groups.values_list('id', flat=True).distinct()
group_perm_ids = AssetPermission.user_groups.through.objects.filter(usergroup_id__in=group_ids) \
group_perm_ids = AssetPermission.user_groups.through.objects\
.filter(usergroup_id__in=group_ids)\
.values_list('assetpermission_id', flat=True).distinct()
if flat:
return group_perm_ids
@ -66,8 +67,15 @@ class AssetPermissionUtil(object):
return perms
@staticmethod
def get_permissions_for_nodes(nodes, flat=False):
def get_permissions_for_nodes(nodes, with_ancestor=False, flat=False):
""" 获取节点的授权规则 """
if with_ancestor:
node_ids = set()
for node in nodes:
_nodes = node.get_ancestors(with_self=True)
_node_ids = _nodes.values_list('id', flat=True).distinct()
node_ids.update(_node_ids)
else:
node_ids = nodes.values_list('id', flat=True).distinct()
node_perm_ids = AssetPermission.nodes.through.objects.filter(node_id__in=node_ids) \
.values_list('assetpermission_id', flat=True).distinct()

Loading…
Cancel
Save