fix: 高危命令告警偶发 session 不存在

pull/6868/head
xinwen 2021-09-15 16:30:39 +08:00 committed by Jiangjie.Bai
parent dee45ce2e0
commit 8c3f89ee51
1 changed files with 9 additions and 2 deletions

View File

@ -9,6 +9,7 @@ from notifications.notifications import SystemMessage
from terminal.models import Session, Command from terminal.models import Session, Command
from notifications.models import SystemMsgSubscription from notifications.models import SystemMsgSubscription
from notifications.backends import BACKEND from notifications.backends import BACKEND
from orgs.utils import tmp_to_root_org
from common.utils import lazyproperty from common.utils import lazyproperty
logger = get_logger(__name__) logger = get_logger(__name__)
@ -69,7 +70,10 @@ class CommandAlertMessage(CommandAlertMixin, SystemMessage):
def get_text_msg(self) -> dict: def get_text_msg(self) -> dict:
command = self.command command = self.command
with tmp_to_root_org():
session = Session.objects.get(id=command['session']) session = Session.objects.get(id=command['session'])
session_detail_url = reverse( session_detail_url = reverse(
'api-terminal:session-detail', kwargs={'pk': command['session']}, 'api-terminal:session-detail', kwargs={'pk': command['session']},
external=True, api_to_ui=True external=True, api_to_ui=True
@ -97,7 +101,10 @@ Session: %(session_detail_url)s?oid=%(oid)s
def get_html_msg(self) -> dict: def get_html_msg(self) -> dict:
command = self.command command = self.command
with tmp_to_root_org():
session = Session.objects.get(id=command['session']) session = Session.objects.get(id=command['session'])
session_detail_url = reverse( session_detail_url = reverse(
'api-terminal:session-detail', kwargs={'pk': command['session']}, 'api-terminal:session-detail', kwargs={'pk': command['session']},
external=True, api_to_ui=True external=True, api_to_ui=True