mirror of https://github.com/jumpserver/jumpserver
Merge branch 'v3' of github.com:jumpserver/jumpserver into v3
commit
88355f55bb
|
@ -6,7 +6,7 @@ from rest_framework.generics import CreateAPIView, ListAPIView
|
|||
from orgs.mixins.api import OrgBulkModelViewSet
|
||||
|
||||
from common.mixins import RecordViewLogMixin
|
||||
from assets.models import Account
|
||||
from assets.models import Account, Asset
|
||||
from assets.filters import AccountFilterSet
|
||||
from assets.tasks import verify_accounts_connectivity
|
||||
from assets import serializers
|
||||
|
@ -30,10 +30,18 @@ class AccountViewSet(OrgBulkModelViewSet):
|
|||
'su_from_accounts': 'assets.view_account',
|
||||
}
|
||||
|
||||
@action(methods=['get'], detail=True, url_path='su-from-accounts')
|
||||
@action(methods=['get'], detail=False, url_path='su-from-accounts')
|
||||
def su_from_accounts(self, request, *args, **kwargs):
|
||||
account = get_object_or_404(Account, pk=self.kwargs['pk'])
|
||||
accounts = account.get_su_from_accounts()
|
||||
account_id = request.query_params.get('account')
|
||||
asset_id = request.query_params.get('asset')
|
||||
if account_id:
|
||||
account = get_object_or_404(Account, pk=account_id)
|
||||
accounts = account.get_su_from_accounts()
|
||||
elif asset_id:
|
||||
asset = get_object_or_404(Asset, pk=asset_id)
|
||||
accounts = asset.accounts.all()
|
||||
else:
|
||||
accounts = []
|
||||
serializer = serializers.AccountSerializer(accounts, many=True)
|
||||
return Response(data=serializer.data)
|
||||
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:9f0b10566b4d35accd3a8766b14d6903243d93c5d7c55b208d930a189e590f2f
|
||||
size 106125
|
||||
oid sha256:eaeedc4823f9b7e236b36a169b5587ef5988d3c3e529d6cbede6bae5e2b57ab8
|
||||
size 106349
|
||||
|
|
|
@ -3067,19 +3067,19 @@ msgstr "跳过"
|
|||
|
||||
#: ops/models/job.py:39
|
||||
msgid "Chdir"
|
||||
msgstr ""
|
||||
msgstr "运行目录"
|
||||
|
||||
#: ops/models/job.py:40
|
||||
msgid "Timeout (Seconds)"
|
||||
msgstr ""
|
||||
msgstr "超市时间(秒)"
|
||||
|
||||
#: ops/models/job.py:45
|
||||
msgid "Runas"
|
||||
msgstr ""
|
||||
msgstr "运行用户"
|
||||
|
||||
#: ops/models/job.py:47
|
||||
msgid "Runas policy"
|
||||
msgstr ""
|
||||
msgstr "用户策略"
|
||||
|
||||
#: ops/models/job.py:48
|
||||
msgid "Use Parameter Define"
|
||||
|
|
|
@ -99,14 +99,11 @@ class JobExecution(JMSOrgBaseModel):
|
|||
date_finished = models.DateTimeField(null=True, verbose_name=_("Date finished"))
|
||||
|
||||
@property
|
||||
def count(self):
|
||||
if self.is_finished and not self.summary.get('error', None):
|
||||
return {
|
||||
"ok": len(self.summary['ok']),
|
||||
"failed": len(self.summary['failures']) + len(self.summary['dark']),
|
||||
"excludes": len(self.summary['excludes']),
|
||||
"total": self.job.assets.count()
|
||||
}
|
||||
def material(self):
|
||||
if self.job.type == 'adhoc':
|
||||
return "{}:{}".format(self.job.module, self.job.args)
|
||||
if self.job.type == 'playbook':
|
||||
return "{}:{}:{}".format(self.org.name, self.job.creator.name, self.job.playbook.name)
|
||||
|
||||
@property
|
||||
def assent_result_detail(self):
|
||||
|
@ -121,7 +118,7 @@ class JobExecution(JMSOrgBaseModel):
|
|||
"status": "ok",
|
||||
"tasks": [],
|
||||
}
|
||||
if self.summary["excludes"].get(asset.name, None):
|
||||
if self.summary.get("excludes", None) and self.summary["excludes"].get(asset.name, None):
|
||||
asset_detail.update({"status": "excludes"})
|
||||
result["detail"].append(asset_detail)
|
||||
break
|
||||
|
@ -160,9 +157,10 @@ class JobExecution(JMSOrgBaseModel):
|
|||
def get_runner(self):
|
||||
inv = self.job.inventory
|
||||
inv.write_to_file(self.inventory_path)
|
||||
self.summary = self.result = {"excludes": {}}
|
||||
if len(inv.exclude_hosts) > 0:
|
||||
self.summary['excludes'] = inv.exclude_hosts
|
||||
self.result['excludes'] = inv.exclude_hosts
|
||||
self.summary.update({"excludes": inv.exclude_hosts})
|
||||
self.result.update({"excludes": inv.exclude_hosts})
|
||||
self.save()
|
||||
|
||||
if isinstance(self.parameters, str):
|
||||
|
|
|
@ -30,17 +30,14 @@ class JobSerializer(BulkOrgResourceModelSerializer, PeriodTaskSerializerMixin):
|
|||
class JobExecutionSerializer(BulkOrgResourceModelSerializer):
|
||||
creator = ReadableHiddenField(default=serializers.CurrentUserDefault())
|
||||
job_type = serializers.ReadOnlyField(label=_("Job type"))
|
||||
count = serializers.ReadOnlyField(label=_("Count"))
|
||||
material = serializers.ReadOnlyField(label=_("Material"))
|
||||
|
||||
class Meta:
|
||||
model = JobExecution
|
||||
read_only_fields = ["id", "task_id", "timedelta", "count", "time_cost", 'is_finished', 'date_start',
|
||||
read_only_fields = ["id", "task_id", "timedelta", "time_cost", 'is_finished', 'date_start',
|
||||
'date_finished',
|
||||
'date_created',
|
||||
'is_success', 'task_id', 'short_id', 'job_type', 'creator']
|
||||
'is_success', 'task_id', 'short_id', 'job_type', 'summary', 'material']
|
||||
fields = read_only_fields + [
|
||||
"job", "parameters"
|
||||
"job", "parameters", "creator"
|
||||
]
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -96,7 +96,8 @@ class UserPermTreeRefreshUtil(_UserPermTreeCacheMixin):
|
|||
logger.info(f'Need to refresh orgs: {to_refresh_orgs}')
|
||||
return to_refresh_orgs
|
||||
|
||||
def _mark_user_orgs_refresh_finished(self, org_ids):
|
||||
def _mark_user_orgs_refresh_finished(self, orgs):
|
||||
org_ids = [str(org.id) for org in orgs]
|
||||
self.client.sadd(self.cache_key_user, *org_ids)
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue