feat: 登录资产消息提醒 (#11747)

Co-authored-by: feng <1304903146@qq.com>
pull/11748/head
fit2bot 1 year ago committed by GitHub
parent f206d963a0
commit 60399fae29
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -1,6 +1,7 @@
from django.template.loader import render_to_string
from django.utils.translation import gettext_lazy as _
from assets.models import Asset
from audits.models import UserLoginLog
from notifications.notifications import UserMessage
from users.models import User
@ -35,3 +36,31 @@ class UserLoginReminderMsg(UserMessage):
user = User.objects.first()
user_log = UserLoginLog.objects.first()
return cls(user, user_log)
class AssetLoginReminderMsg(UserMessage):
subject = _('Asset login reminder')
def __init__(self, user, asset: Asset, login_user: User):
self.asset = asset
self.login_user = login_user
super().__init__(user)
def get_html_msg(self) -> dict:
context = {
'recipient': self.user.username,
'username': self.login_user.username,
'asset': str(self.asset),
}
message = render_to_string('acls/asset_login_reminder.html', context)
return {
'subject': str(self.subject),
'message': message
}
@classmethod
def gen_test_msg(cls):
user = User.objects.first()
asset = Asset.objects.first()
return cls(user, asset, user)

@ -0,0 +1,12 @@
{% load i18n %}
<h3>{% trans 'Respectful' %}{{ recipient }}</h3>
<hr>
<p><strong>{% trans 'Username' %}:</strong> [{{ username }}]</p>
<p><strong>{% trans 'Assets' %}:</strong> [{{ asset }}]</p>
<hr>
<p>{% trans 'The user has just successfully logged into the asset. Please ensure that this is an authorized operation. If you suspect that this is an unauthorized access, please take appropriate measures immediately.' %}</p>
<p>{% trans 'Thank you' %}</p>

@ -15,6 +15,7 @@ from rest_framework.request import Request
from rest_framework.response import Response
from accounts.const import AliasAccount
from acls.notifications import AssetLoginReminderMsg
from common.api import JMSModelViewSet
from common.exceptions import JMSException
from common.utils import random_string, get_logger, get_request_ip
@ -409,6 +410,10 @@ class ConnectionTokenViewSet(ExtraActionApiMixin, RootOrgViewMixin, JMSModelView
assignees=acl.reviewers.all(), org_id=asset.org_id
)
return ticket
if acl.is_action(acl.ActionChoices.notice):
reviewers = acl.reviewers.all()
for reviewer in reviewers:
AssetLoginReminderMsg(reviewer, asset, user).publish_async()
class SuperConnectionTokenViewSet(ConnectionTokenViewSet):

Loading…
Cancel
Save