mirror of
https://github.com/jumpserver/jumpserver.git
synced 2025-09-20 19:09:02 +00:00
perf: 安全模式返回授权的资产
This commit is contained in:
@@ -13,7 +13,7 @@ class AssetPermissionUtil(object):
|
||||
""" 资产授权相关的方法工具 """
|
||||
|
||||
@timeit
|
||||
def get_permissions_for_user(self, user, with_group=True, flat=False):
|
||||
def get_permissions_for_user(self, user, with_group=True, flat=False, with_expired=False):
|
||||
""" 获取用户的授权规则 """
|
||||
perm_ids = set()
|
||||
# user
|
||||
@@ -25,7 +25,7 @@ class AssetPermissionUtil(object):
|
||||
groups = user.groups.all()
|
||||
group_perm_ids = self.get_permissions_for_user_groups(groups, flat=True)
|
||||
perm_ids.update(group_perm_ids)
|
||||
perms = self.get_permissions(ids=perm_ids)
|
||||
perms = self.get_permissions(ids=perm_ids, with_expired=with_expired)
|
||||
if flat:
|
||||
return perms.values_list('id', flat=True)
|
||||
return perms
|
||||
@@ -102,6 +102,8 @@ class AssetPermissionUtil(object):
|
||||
return model.objects.filter(id__in=ids)
|
||||
|
||||
@staticmethod
|
||||
def get_permissions(ids):
|
||||
perms = AssetPermission.objects.filter(id__in=ids).valid().order_by('-date_expired')
|
||||
return perms
|
||||
def get_permissions(ids, with_expired=False):
|
||||
perms = AssetPermission.objects.filter(id__in=ids)
|
||||
if not with_expired:
|
||||
perms = perms.valid()
|
||||
return perms.order_by('-date_expired')
|
||||
|
Reference in New Issue
Block a user