mirror of
https://github.com/jumpserver/jumpserver.git
synced 2025-09-27 15:54:14 +00:00
[Update] 系统用户资产管理页面获取相关的所有资产 (#3038)
* [Update] 系统用户资产管理页面获取相关的所有资产 * [Update] 系统用户资产管理页面获取相关的所有资产2
This commit is contained in:
@@ -4,12 +4,15 @@
|
||||
|
||||
import logging
|
||||
|
||||
from functools import reduce
|
||||
from django.db import models
|
||||
from django.db.models import Q
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
from django.core.validators import MinValueValidator, MaxValueValidator
|
||||
|
||||
from common.utils import get_signer
|
||||
from .base import AssetUser
|
||||
from .asset import Asset
|
||||
|
||||
|
||||
__all__ = ['AdminUser', 'SystemUser']
|
||||
@@ -144,6 +147,19 @@ class SystemUser(AssetUser):
|
||||
return False, matched_cmd
|
||||
return True, None
|
||||
|
||||
def get_all_assets(self):
|
||||
args = [Q(systemuser=self)]
|
||||
pattern = set()
|
||||
nodes_keys = self.nodes.all().values_list('key', flat=True)
|
||||
for key in nodes_keys:
|
||||
pattern.add(r'^{0}$|^{0}:'.format(key))
|
||||
pattern = '|'.join(list(pattern))
|
||||
if pattern:
|
||||
args.append(Q(nodes__key__regex=pattern))
|
||||
args = reduce(lambda x, y: x | y, args)
|
||||
assets = Asset.objects.filter(args).distinct()
|
||||
return assets
|
||||
|
||||
class Meta:
|
||||
ordering = ['name']
|
||||
unique_together = [('name', 'org_id')]
|
||||
|
Reference in New Issue
Block a user