From caa675442a76e305d3420520268706193d0188df Mon Sep 17 00:00:00 2001 From: Ewall555 Date: Tue, 9 Sep 2025 10:00:53 +0000 Subject: [PATCH] feat: add organization details to command alert messages --- apps/ops/models/job.py | 4 ++++ apps/terminal/notifications.py | 7 ++++++- apps/terminal/templates/terminal/_msg_command_alert.html | 2 ++ .../templates/terminal/_msg_command_execute_alert.html | 2 ++ 4 files changed, 14 insertions(+), 1 deletion(-) diff --git a/apps/ops/models/job.py b/apps/ops/models/job.py index 71313d4ee..5e301bc40 100644 --- a/apps/ops/models/job.py +++ b/apps/ops/models/job.py @@ -453,6 +453,8 @@ class JobExecution(JMSOrgBaseModel): "input": self.material, "risk_level": RiskLevelChoices.reject, "user": self.creator, + 'org_id': self.org_id, + '_org_name': self.org_name, }).publish_async() raise Exception("command is rejected by ACL") elif acl.is_action(CommandFilterACL.ActionChoices.warning): @@ -491,6 +493,8 @@ class JobExecution(JMSOrgBaseModel): "input": self.material, "risk_level": RiskLevelChoices.reject, "user": self.creator, + 'org_id': self.org_id, + '_org_name': self.org_name, }).publish_async() raise CommandInBlackListException( "Command is rejected by black list: {}".format(self.current_job.args)) diff --git a/apps/terminal/notifications.py b/apps/terminal/notifications.py index d833a5172..3c6a5daa8 100644 --- a/apps/terminal/notifications.py +++ b/apps/terminal/notifications.py @@ -152,6 +152,8 @@ class CommandAlertMessage(CommandAlertMixin, SystemMessage): def gen_html_string(self, **other_context) -> dict: command = self.command level = RiskLevelChoices.get_label(command['risk_level']) + org_id = command['org_id'] + org_name = command.get('_org_name') or org_id items = { _("Asset"): command['asset'], _("User"): command['user'], @@ -161,6 +163,7 @@ class CommandAlertMessage(CommandAlertMixin, SystemMessage): context = { 'items': items, "command": command['input'], + 'org': org_name, } context.update(other_context) message = render_to_string('terminal/_msg_command_alert.html', context) @@ -212,7 +215,8 @@ class CommandExecutionAlert(CommandAlertMixin, SystemMessage): def gen_html_string(self, **other_context): command = self.command level = RiskLevelChoices.get_label(command['risk_level']) - + org_id = command['org_id'] + org_name = command.get('_org_name') or org_id items = { _("User"): command['user'], _("Level"): level, @@ -221,6 +225,7 @@ class CommandExecutionAlert(CommandAlertMixin, SystemMessage): context = { 'items': items, 'command': command['input'], + 'org': org_name, } context.update(other_context) message = render_to_string('terminal/_msg_command_execute_alert.html', context) diff --git a/apps/terminal/templates/terminal/_msg_command_alert.html b/apps/terminal/templates/terminal/_msg_command_alert.html index a3447c97d..6048cbce7 100644 --- a/apps/terminal/templates/terminal/_msg_command_alert.html +++ b/apps/terminal/templates/terminal/_msg_command_alert.html @@ -9,6 +9,8 @@ {% endfor %} {% trans 'Session' %}: {% trans 'view' %}
+ {% trans 'Organization' %}: {{ org }} +
{% trans 'Command' %}:
 {{ command }}
diff --git a/apps/terminal/templates/terminal/_msg_command_execute_alert.html b/apps/terminal/templates/terminal/_msg_command_execute_alert.html
index ff59e0c4b..b626a2238 100644
--- a/apps/terminal/templates/terminal/_msg_command_execute_alert.html
+++ b/apps/terminal/templates/terminal/_msg_command_execute_alert.html
@@ -7,6 +7,8 @@
     
     
{% endfor %} + {% trans 'Organization' %}: {{ org }} +
{% trans 'Command' %}:
 {{ command }}