mirror of https://github.com/jumpserver/jumpserver
perf: update risk add reopen action
parent
cf8c4ea050
commit
6b661b6aae
|
@ -130,7 +130,8 @@ class AccountRiskViewSet(OrgBulkModelViewSet):
|
||||||
data = handler.handle(act, risk)
|
data = handler.handle(act, risk)
|
||||||
if not data:
|
if not data:
|
||||||
data = {"message": "Success"}
|
data = {"message": "Success"}
|
||||||
return Response(data)
|
s = serializers.AccountRiskSerializer(instance=data)
|
||||||
|
return Response(data=s.data)
|
||||||
|
|
||||||
|
|
||||||
class CheckAccountEngineViewSet(JMSModelViewSet):
|
class CheckAccountEngineViewSet(JMSModelViewSet):
|
||||||
|
|
|
@ -1,18 +1,21 @@
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
|
from rest_framework.serializers import ValidationError
|
||||||
|
|
||||||
from accounts.const import AutomationTypes, Source
|
from accounts.const import AutomationTypes, Source
|
||||||
from accounts.models import (
|
from accounts.models import (
|
||||||
GatheredAccount,
|
GatheredAccount,
|
||||||
AccountRisk,
|
AccountRisk,
|
||||||
SecretType,
|
SecretType,
|
||||||
AutomationExecution, RiskChoice, Account
|
AutomationExecution,
|
||||||
|
RiskChoice
|
||||||
)
|
)
|
||||||
from common.const import ConfirmOrIgnore
|
from common.const import ConfirmOrIgnore
|
||||||
from common.utils import random_string
|
from common.utils import random_string
|
||||||
|
|
||||||
TYPE_CHOICES = [
|
TYPE_CHOICES = [
|
||||||
("ignore", _("Ignore")),
|
("ignore", _("Ignore")),
|
||||||
|
("reopen", _("Reopen")),
|
||||||
("disable_remote", _("Disable remote")),
|
("disable_remote", _("Disable remote")),
|
||||||
("delete_remote", _("Delete remote")),
|
("delete_remote", _("Delete remote")),
|
||||||
("delete_both", _("Delete remote")),
|
("delete_both", _("Delete remote")),
|
||||||
|
@ -32,23 +35,28 @@ class RiskHandler:
|
||||||
def handle(self, tp, risk=""):
|
def handle(self, tp, risk=""):
|
||||||
self.risk = risk
|
self.risk = risk
|
||||||
attr = f"handle_{tp}"
|
attr = f"handle_{tp}"
|
||||||
if hasattr(self, attr):
|
|
||||||
ret = getattr(self, attr)()
|
if not hasattr(self, attr):
|
||||||
self.update_risk_if_need(tp)
|
raise ValidationError(f"Invalid risk type: {tp}")
|
||||||
return ret
|
|
||||||
else:
|
getattr(self, attr)()
|
||||||
raise ValueError(f"Invalid risk type: {tp}")
|
risk = self.update_risk_if_need(tp)
|
||||||
|
return risk
|
||||||
|
|
||||||
def update_risk_if_need(self, tp):
|
def update_risk_if_need(self, tp):
|
||||||
r = self.get_risk()
|
r = self.get_risk()
|
||||||
if not r:
|
if not r:
|
||||||
return
|
return
|
||||||
status = (
|
if tp == "ignore":
|
||||||
ConfirmOrIgnore.ignored if tp == "ignore" else ConfirmOrIgnore.confirmed
|
status = ConfirmOrIgnore.ignored
|
||||||
)
|
elif tp == "reopen":
|
||||||
|
status = ConfirmOrIgnore.pending
|
||||||
|
else:
|
||||||
|
status = ConfirmOrIgnore.confirmed
|
||||||
r.details.append({**self.process_detail, "action": tp, "status": status})
|
r.details.append({**self.process_detail, "action": tp, "status": status})
|
||||||
r.status = status
|
r.status = status
|
||||||
r.save()
|
r.save()
|
||||||
|
return r
|
||||||
|
|
||||||
def get_risk(self):
|
def get_risk(self):
|
||||||
r = AccountRisk.objects.filter(asset=self.asset, username=self.username)
|
r = AccountRisk.objects.filter(asset=self.asset, username=self.username)
|
||||||
|
@ -57,19 +65,26 @@ class RiskHandler:
|
||||||
return r.first()
|
return r.first()
|
||||||
|
|
||||||
def handle_ignore(self):
|
def handle_ignore(self):
|
||||||
GatheredAccount.objects.filter(asset=self.asset, username=self.username).update(status=ConfirmOrIgnore.ignored)
|
(GatheredAccount.objects
|
||||||
self.risk = 'ignored'
|
.filter(asset=self.asset, username=self.username)
|
||||||
|
.update(status=ConfirmOrIgnore.ignored))
|
||||||
|
|
||||||
|
def handle_reopen(self):
|
||||||
|
pass
|
||||||
|
|
||||||
def handle_review(self):
|
def handle_review(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def process_detail(self):
|
def process_detail(self):
|
||||||
return {
|
detail = {
|
||||||
"datetime": timezone.now().isoformat(),
|
"datetime": timezone.now().isoformat(),
|
||||||
"type": "process",
|
"type": "process",
|
||||||
"processor": str(self.request.user),
|
"processor": str(self.request.user),
|
||||||
}
|
}
|
||||||
|
if self.request and self.request.data and self.request.data.get('comment'):
|
||||||
|
detail['comment'] = self.request.data['comment']
|
||||||
|
return detail
|
||||||
|
|
||||||
def handle_add_account(self):
|
def handle_add_account(self):
|
||||||
data = {
|
data = {
|
||||||
|
|
Loading…
Reference in New Issue