mirror of https://github.com/jumpserver/jumpserver
fix: Add with_expired param to permission utils
parent
ecfd338428
commit
5d18d6dee0
|
@ -23,14 +23,14 @@ class AssetPermissionUtil(object):
|
||||||
# group
|
# group
|
||||||
if with_group:
|
if with_group:
|
||||||
groups = user.groups.all()
|
groups = user.groups.all()
|
||||||
group_perm_ids = self.get_permissions_for_user_groups(groups, flat=True)
|
group_perm_ids = self.get_permissions_for_user_groups(groups, flat=True, with_expired=with_expired)
|
||||||
perm_ids.update(group_perm_ids)
|
perm_ids.update(group_perm_ids)
|
||||||
perms = self.get_permissions(ids=perm_ids, with_expired=with_expired)
|
perms = self.get_permissions(ids=perm_ids, with_expired=with_expired)
|
||||||
if flat:
|
if flat:
|
||||||
return perms.values_list('id', flat=True)
|
return perms.values_list('id', flat=True)
|
||||||
return perms
|
return perms
|
||||||
|
|
||||||
def get_permissions_for_user_groups(self, user_groups, flat=False):
|
def get_permissions_for_user_groups(self, user_groups, flat=False, with_expired=False):
|
||||||
""" 获取用户组的授权规则 """
|
""" 获取用户组的授权规则 """
|
||||||
if isinstance(user_groups, list):
|
if isinstance(user_groups, list):
|
||||||
group_ids = [g.id for g in user_groups]
|
group_ids = [g.id for g in user_groups]
|
||||||
|
@ -39,7 +39,7 @@ class AssetPermissionUtil(object):
|
||||||
perm_ids = AssetPermission.user_groups.through.objects \
|
perm_ids = AssetPermission.user_groups.through.objects \
|
||||||
.filter(usergroup_id__in=group_ids) \
|
.filter(usergroup_id__in=group_ids) \
|
||||||
.values_list('assetpermission_id', flat=True).distinct()
|
.values_list('assetpermission_id', flat=True).distinct()
|
||||||
perms = self.get_permissions(ids=perm_ids)
|
perms = self.get_permissions(ids=perm_ids, with_expired=with_expired)
|
||||||
if flat:
|
if flat:
|
||||||
return perms.values_list('id', flat=True)
|
return perms.values_list('id', flat=True)
|
||||||
return perms
|
return perms
|
||||||
|
|
Loading…
Reference in New Issue