mirror of https://github.com/jumpserver/jumpserver
fix: 批量命令bug
parent
89c7e514eb
commit
9e47bf6ec5
|
@ -5,6 +5,7 @@
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from django.db import models
|
from django.db import models
|
||||||
|
from django.db.models import Q
|
||||||
from django.utils.translation import ugettext_lazy as _
|
from django.utils.translation import ugettext_lazy as _
|
||||||
from django.core.validators import MinValueValidator, MaxValueValidator
|
from django.core.validators import MinValueValidator, MaxValueValidator
|
||||||
from django.core.cache import cache
|
from django.core.cache import cache
|
||||||
|
|
|
@ -38,6 +38,7 @@ class CommandExecution(OrgModelMixin):
|
||||||
with tmp_to_org(self.run_as.org_id):
|
with tmp_to_org(self.run_as.org_id):
|
||||||
super().save(*args, **kwargs)
|
super().save(*args, **kwargs)
|
||||||
|
|
||||||
|
@property
|
||||||
def inventory(self):
|
def inventory(self):
|
||||||
if self.run_as.username_same_with_user:
|
if self.run_as.username_same_with_user:
|
||||||
username = self.user.username
|
username = self.user.username
|
||||||
|
@ -105,7 +106,7 @@ class CommandExecution(OrgModelMixin):
|
||||||
return allow_assets
|
return allow_assets
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
print('-'*10 + ' ' + ugettext('Task start') + ' ' + '-'*10)
|
print('-' * 10 + ' ' + ugettext('Task start') + ' ' + '-' * 10)
|
||||||
org = Organization.get_instance(self.run_as.org_id)
|
org = Organization.get_instance(self.run_as.org_id)
|
||||||
org.change_to()
|
org.change_to()
|
||||||
self.date_start = timezone.now()
|
self.date_start = timezone.now()
|
||||||
|
@ -117,7 +118,7 @@ class CommandExecution(OrgModelMixin):
|
||||||
print(f'资产{asset}: 命令{self.command}不允许执行')
|
print(f'资产{asset}: 命令{self.command}不允许执行')
|
||||||
if not allow_assets:
|
if not allow_assets:
|
||||||
self.result = {
|
self.result = {
|
||||||
"error": _('There are currently no assets that can be executed')
|
"error": 'There are currently no assets that can be executed'
|
||||||
}
|
}
|
||||||
self.save()
|
self.save()
|
||||||
return self.result
|
return self.result
|
||||||
|
@ -147,10 +148,10 @@ class CommandExecution(OrgModelMixin):
|
||||||
'user': str(self.user),
|
'user': str(self.user),
|
||||||
'risk_level': 5,
|
'risk_level': 5,
|
||||||
}).publish_async()
|
}).publish_async()
|
||||||
self.result = {"error": msg}
|
self.result = {"error": msg}
|
||||||
self.org_id = self.run_as.org_id
|
self.org_id = self.run_as.org_id
|
||||||
self.is_finished = True
|
self.is_finished = True
|
||||||
self.date_finished = timezone.now()
|
self.date_finished = timezone.now()
|
||||||
self.save()
|
self.save()
|
||||||
print('-'*10 + ' ' + ugettext('Task end') + ' ' + '-'*10)
|
print('-' * 10 + ' ' + ugettext('Task end') + ' ' + '-' * 10)
|
||||||
return self.result
|
return self.result
|
||||||
|
|
Loading…
Reference in New Issue