From 8420989509e55a347d43c7e73dda5e5051a78202 Mon Sep 17 00:00:00 2001
From: feng <1304903146@qq.com>
Date: Wed, 10 Sep 2025 14:02:09 +0800
Subject: [PATCH] perf: Notify info css optimization
---
apps/acls/notifications.py | 17 ++++--
.../templates/acls/asset_login_reminder.html | 2 +
.../templates/acls/user_login_reminder.html | 1 +
apps/audits/signal_handlers/login_log.py | 2 +-
apps/authentication/api/connection_token.py | 3 +-
apps/terminal/api/session/command.py | 4 +-
apps/terminal/notifications.py | 4 ++
.../terminal/_msg_command_warning.html | 53 +++++++++++--------
8 files changed, 58 insertions(+), 28 deletions(-)
diff --git a/apps/acls/notifications.py b/apps/acls/notifications.py
index 0ad562127..1dcc6339c 100644
--- a/apps/acls/notifications.py
+++ b/apps/acls/notifications.py
@@ -2,6 +2,7 @@ from django.template.loader import render_to_string
from django.utils.translation import gettext_lazy as _
from accounts.models import Account
+from acls.models import LoginACL, LoginAssetACL
from assets.models import Asset
from audits.models import UserLoginLog
from notifications.notifications import UserMessage
@@ -11,8 +12,9 @@ from users.models import User
class UserLoginReminderMsg(UserMessage):
subject = _('User login reminder')
- def __init__(self, user, user_log: UserLoginLog):
+ def __init__(self, user, user_log: UserLoginLog, acl: LoginACL):
self.user_log = user_log
+ self.acl_name = str(acl)
super().__init__(user)
def get_html_msg(self) -> dict:
@@ -22,6 +24,7 @@ class UserLoginReminderMsg(UserMessage):
'city': user_log.city,
'username': user_log.username,
'recipient': self.user,
+ 'acl_name': self.acl_name,
'user_agent': user_log.user_agent,
}
message = render_to_string('acls/user_login_reminder.html', context)
@@ -41,21 +44,29 @@ class UserLoginReminderMsg(UserMessage):
class AssetLoginReminderMsg(UserMessage):
subject = _('User login alert for asset')
- def __init__(self, user, asset: Asset, login_user: User, account: Account, input_username):
+ def __init__(
+ self, user, asset: Asset, login_user: User,
+ account: Account, acl: LoginAssetACL,
+ ip, input_username
+ ):
+ self.ip = ip
self.asset = asset
- self.login_user = login_user
self.account = account
+ self.acl_name = str(acl)
+ self.login_user = login_user
self.input_username = input_username
super().__init__(user)
def get_html_msg(self) -> dict:
context = {
+ 'ip': self.ip,
'recipient': self.user,
'username': self.login_user.username,
'name': self.login_user.name,
'asset': str(self.asset),
'account': self.input_username,
'account_name': self.account.name,
+ 'acl_name': self.acl_name,
}
message = render_to_string('acls/asset_login_reminder.html', context)
diff --git a/apps/acls/templates/acls/asset_login_reminder.html b/apps/acls/templates/acls/asset_login_reminder.html
index 4d31fc3fc..846797f7f 100644
--- a/apps/acls/templates/acls/asset_login_reminder.html
+++ b/apps/acls/templates/acls/asset_login_reminder.html
@@ -6,8 +6,10 @@
{% trans 'Asset details' %}:
- {% trans 'User' %}: [{{ name }}({{ username }})]
+ - IP: [{{ ip }}]
- {% trans 'Assets' %}: [{{ asset }}]
- {% trans 'Account' %}: [{{ account_name }}({{ account }})]
+ - {% trans 'Login asset acl' %}: [{{ acl_name }}]
diff --git a/apps/acls/templates/acls/user_login_reminder.html b/apps/acls/templates/acls/user_login_reminder.html
index 521d7d41a..826da7bd2 100644
--- a/apps/acls/templates/acls/user_login_reminder.html
+++ b/apps/acls/templates/acls/user_login_reminder.html
@@ -9,6 +9,7 @@
IP: [{{ ip }}]
{% trans 'Login city' %}: [{{ city }}]
{% trans 'User agent' %}: [{{ user_agent }}]
+ {% trans 'Login acl' %}: [{{ acl_name }}]
diff --git a/apps/audits/signal_handlers/login_log.py b/apps/audits/signal_handlers/login_log.py
index 11000830b..02a4c15c8 100644
--- a/apps/audits/signal_handlers/login_log.py
+++ b/apps/audits/signal_handlers/login_log.py
@@ -116,7 +116,7 @@ def send_login_info_to_reviewers(instance: UserLoginLog | str, auth_acl_id):
reviewers = acl.reviewers.all()
for reviewer in reviewers:
- UserLoginReminderMsg(reviewer, instance).publish_async()
+ UserLoginReminderMsg(reviewer, instance, acl).publish_async()
@receiver(post_auth_success)
diff --git a/apps/authentication/api/connection_token.py b/apps/authentication/api/connection_token.py
index a80bc248d..7d802f069 100644
--- a/apps/authentication/api/connection_token.py
+++ b/apps/authentication/api/connection_token.py
@@ -525,7 +525,8 @@ class ConnectionTokenViewSet(AuthFaceMixin, ExtraActionApiMixin, RootOrgViewMixi
self._record_operate_log(acl, asset)
for reviewer in reviewers:
AssetLoginReminderMsg(
- reviewer, asset, user, account, self.input_username
+ reviewer, asset, user, account, acl,
+ ip, self.input_username
).publish_async()
def create_face_verify(self, response):
diff --git a/apps/terminal/api/session/command.py b/apps/terminal/api/session/command.py
index baec8f0fa..32f67704a 100644
--- a/apps/terminal/api/session/command.py
+++ b/apps/terminal/api/session/command.py
@@ -1,6 +1,5 @@
# -*- coding: utf-8 -*-
#
-import uuid
from django.utils import timezone
from rest_framework import generics
from rest_framework.fields import DateTimeField
@@ -228,6 +227,9 @@ class InsecureCommandAlertAPI(generics.CreateAPIView):
command.update({
'_account': session.account,
'_org_name': session.org.name,
+ '_protocol': session.protocol,
+ '_remote_addr': session.remote_addr,
+ '_login_from': session.get_login_from_display(),
})
if risk_level in [RiskLevelChoices.reject, RiskLevelChoices.review_reject]:
diff --git a/apps/terminal/notifications.py b/apps/terminal/notifications.py
index d833a5172..a8b298666 100644
--- a/apps/terminal/notifications.py
+++ b/apps/terminal/notifications.py
@@ -98,10 +98,14 @@ class CommandWarningMessage(CommandAlertMixin, UserMessage):
cmd_group_name = cmd_group.name if cmd_group else ''
context = {
+ 'recipient': self.user,
'command': command['input'],
'user': command['user'],
'asset': command['asset'],
'account': command.get('_account', ''),
+ 'protocol': command.get('_protocol', ''),
+ 'remote_addr': command.get('_remote_addr', ''),
+ 'login_from': command.get('_login_from', ''),
'cmd_filter_acl': cmd_acl_name,
'cmd_group': cmd_group_name,
'risk_level': RiskLevelChoices.get_label(command['risk_level']),
diff --git a/apps/terminal/templates/terminal/_msg_command_warning.html b/apps/terminal/templates/terminal/_msg_command_warning.html
index df7315341..4d9d7594d 100644
--- a/apps/terminal/templates/terminal/_msg_command_warning.html
+++ b/apps/terminal/templates/terminal/_msg_command_warning.html
@@ -1,25 +1,34 @@
{% load i18n %}
-
-
{% trans 'Asset' %}: {{ asset }}
-
-
{% trans 'User' %}: {{ user }}
-
-
{% trans 'Account' %}: {{ account }}
-
-
{% trans 'Risk level' %}: {{ risk_level }}
-
-
{% trans 'Command acl' %}: {{ cmd_filter_acl }}
-
-
{% trans 'Command group' %}: {{ cmd_group}}
-
- {% if session_url %}
-
{% trans 'Session' %}:
-
{% trans 'View' %}
-
+
{% trans 'Dear' %}: {{ recipient.name }} [{{ recipient.username }}]
+
+
{% trans 'We would like to inform you that a command alert has been triggered with the following details:' %}
+
+
{% trans 'Alert details' %}:
+
+ - {% trans 'User' %}: [{{ user }}]
+ - {% trans 'Asset' %}: [{{ asset }}]
+ - {% trans 'Account' %}: [{{ account }}]
+ {% if remote_addr %}
+ - IP: [{{ remote_addr }}]
{% endif %}
- {% trans 'Organization' %}: {{ org }}
-
- {% trans 'Command' %}: {{ command }}
-
-
+ {% if login_from %}
+ {% trans 'Login from' %}: [{{ login_from }}]
+ {% endif %}
+ {% if protocol %}
+ {% trans 'Protocol' %}: [{{ protocol }}]
+ {% endif %}
+ {% trans 'Risk level' %}: [{{ risk_level }}]
+ {% trans 'Command acl' %}: [{{ cmd_filter_acl }}]
+ {% trans 'Command group' %}: [{{ cmd_group }}]
+ {% if session_url %}
+ {% trans 'Session' %}: {% trans 'View session' %}
+ {% endif %}
+ {% trans 'Organization' %}: [{{ org }}]
+ {% trans 'Command' %}: [{{ command }}]
+
+
+
+{% trans 'Please review this command execution to ensure it complies with your organization’s security policies. If you did not authorize this action or notice anything unusual, please take the necessary actions immediately.' %}
+
+{% trans 'Thank you for your attention to this matter' %}!
\ No newline at end of file