diff --git a/apps/authentication/templates/authentication/_msg_different_city.html b/apps/authentication/templates/authentication/_msg_different_city.html index b12e9aab6..02dbf4271 100644 --- a/apps/authentication/templates/authentication/_msg_different_city.html +++ b/apps/authentication/templates/authentication/_msg_different_city.html @@ -11,6 +11,7 @@ {% trans 'Login city' %}: {{ city }}({{ ip }})
+-{% trans 'If you suspect that the login behavior is abnormal, please modify the account password in time.' %}
\ No newline at end of file diff --git a/apps/authentication/templates/authentication/_msg_reset_password.html b/apps/authentication/templates/authentication/_msg_reset_password.html index 7bb80a17d..f53bda209 100644 --- a/apps/authentication/templates/authentication/_msg_reset_password.html +++ b/apps/authentication/templates/authentication/_msg_reset_password.html @@ -11,9 +11,8 @@ +-{% trans 'This link is valid for 1 hour. After it expires' %} - - {% trans 'request new one' %} - + {% trans 'request new one' %}
diff --git a/apps/authentication/templates/authentication/_msg_rest_password_success.html b/apps/authentication/templates/authentication/_msg_rest_password_success.html index a12d611f7..dce3ee13c 100644 --- a/apps/authentication/templates/authentication/_msg_rest_password_success.html +++ b/apps/authentication/templates/authentication/_msg_rest_password_success.html @@ -8,6 +8,7 @@ {% trans 'IP' %}: {{ ip_address }}
{% trans 'If the password update was not initiated by you, your account may have security issues' %}
{% trans 'If you have any questions, you can contact the administrator' %}
diff --git a/apps/authentication/templates/authentication/_msg_rest_public_key_success.html b/apps/authentication/templates/authentication/_msg_rest_public_key_success.html
index a95bfdd9b..c8e8fabb6 100644
--- a/apps/authentication/templates/authentication/_msg_rest_public_key_success.html
+++ b/apps/authentication/templates/authentication/_msg_rest_public_key_success.html
@@ -8,6 +8,7 @@
{% trans 'IP' %}: {{ ip_address }}
{% trans 'Browser' %}: {{ browser }}
{% trans 'If the public key update was not initiated by you, your account may have security issues' %}
{% trans 'If you have any questions, you can contact the administrator' %}
diff --git a/apps/common/sdk/im/dingtalk/__init__.py b/apps/common/sdk/im/dingtalk/__init__.py
index af57f2cf5..f18cd4b35 100644
--- a/apps/common/sdk/im/dingtalk/__init__.py
+++ b/apps/common/sdk/im/dingtalk/__init__.py
@@ -151,12 +151,29 @@ class DingTalk:
'data': data
}
data = self._request.post(URL.SEND_MESSAGE_BY_TEMPLATE, json=body, with_token=True)
+ return data
+
+ def send_markdown(self, user_ids, title, msg):
+ body = {
+ 'agent_id': self._agentid,
+ 'userid_list': ','.join(user_ids),
+ 'to_all_user': False,
+ 'msg': {
+ 'msgtype': 'markdown',
+ 'markdown': {
+ 'title': title,
+ 'text': msg
+ }
+ }
+ }
+ logger.info(f'Dingtalk send markdown to user {user_ids}: {msg}')
+ data = self._request.post(URL.SEND_MESSAGE, json=body, with_token=True)
+ return data
def send_text(self, user_ids, msg):
body = {
'agent_id': self._agentid,
'userid_list': ','.join(user_ids),
- # 'dept_id_list': '',
'to_all_user': False,
'msg': {
'msgtype': 'text',
@@ -165,7 +182,7 @@ class DingTalk:
}
}
}
- logger.info(f'Dingtalk send text: user_ids={user_ids} msg={msg}')
+ logger.info(f'Dingtalk send msg to user {user_ids}: {msg}')
data = self._request.post(URL.SEND_MESSAGE, json=body, with_token=True)
return data
diff --git a/apps/common/sdk/im/wecom/__init__.py b/apps/common/sdk/im/wecom/__init__.py
index 6d7c2bf66..ceda292c7 100644
--- a/apps/common/sdk/im/wecom/__init__.py
+++ b/apps/common/sdk/im/wecom/__init__.py
@@ -90,7 +90,10 @@ class WeCom(RequestMixin):
timeout=timeout
)
- def send_text(self, users: Iterable, msg: AnyStr, **kwargs):
+ def send_markdown(self, users: Iterable, msg: AnyStr, **kwargs):
+ pass
+
+ def send_text(self, users: Iterable, msg: AnyStr, markdown=False, **kwargs):
"""
https://open.work.weixin.qq.com/api/doc/90000/90135/90236
@@ -115,6 +118,13 @@ class WeCom(RequestMixin):
},
**extra_params
}
+ if markdown:
+ body['msgtype'] = 'markdown'
+ body["markdown"] = {
+ "content": msg
+ }
+ body.pop('text', '')
+
logger.info(f'Wecom send text: users={users} msg={msg}')
data = self._requests.post(URL.SEND_MESSAGE, json=body, check_errcode_is_0=False)
diff --git a/apps/notifications/backends/dingtalk.py b/apps/notifications/backends/dingtalk.py
index 426a05fc0..52d11d041 100644
--- a/apps/notifications/backends/dingtalk.py
+++ b/apps/notifications/backends/dingtalk.py
@@ -16,7 +16,7 @@ class DingTalk(BackendBase):
def send_msg(self, users, message, subject=None):
accounts, __, __ = self.get_accounts(users)
- return self.dingtalk.send_text(accounts, message)
+ return self.dingtalk.send_markdown(accounts, subject, message)
backend = DingTalk
diff --git a/apps/notifications/backends/wecom.py b/apps/notifications/backends/wecom.py
index c2aadd4a9..fa615b7e7 100644
--- a/apps/notifications/backends/wecom.py
+++ b/apps/notifications/backends/wecom.py
@@ -17,7 +17,7 @@ class WeCom(BackendBase):
def send_msg(self, users, message, subject=None):
accounts, __, __ = self.get_accounts(users)
- return self.wecom.send_text(accounts, message)
+ return self.wecom.send_text(accounts, message, markdown=True)
backend = WeCom
diff --git a/apps/notifications/notifications.py b/apps/notifications/notifications.py
index 11e8f7011..481a4bc08 100644
--- a/apps/notifications/notifications.py
+++ b/apps/notifications/notifications.py
@@ -94,7 +94,7 @@ class Message(metaclass=MessageType):
traceback.print_exc()
@classmethod
- def send_test_msg(cls, ding=True):
+ def send_test_msg(cls, ding=True, wecom=False):
msg = cls.gen_test_msg()
if not msg:
return
@@ -104,6 +104,8 @@ class Message(metaclass=MessageType):
backends = []
if ding:
backends.append(BACKEND.DINGTALK)
+ if wecom:
+ backends.append(BACKEND.WECOM)
msg.send_msg(users, backends)
@staticmethod
@@ -113,8 +115,17 @@ class Message(metaclass=MessageType):
def get_html_msg(self) -> dict:
return self.get_common_msg()
+ def get_markdown_msg(self) -> dict:
+ h = HTML2Text()
+ h.body_width = 300
+ msg = self.get_html_msg()
+ content = msg['message']
+ msg['message'] = h.handle(content)
+ return msg
+
def get_text_msg(self) -> dict:
h = HTML2Text()
+ h.body_width = 90
msg = self.get_html_msg()
content = msg['message']
h.ignore_links = self.text_msg_ignore_links
@@ -130,6 +141,10 @@ class Message(metaclass=MessageType):
msg = self.get_text_msg()
return msg
+ @lazyproperty
+ def markdown_msg(self):
+ return self.get_markdown_msg()
+
@lazyproperty
def html_msg(self) -> dict:
msg = self.get_html_msg()
@@ -167,17 +182,17 @@ class Message(metaclass=MessageType):
# 支持不同发送消息的方式定义自己的消息内容,比如有些支持 html 标签
def get_dingtalk_msg(self) -> dict:
# 钉钉相同的消息一天只能发一次,所以给所有消息添加基于时间的序号,使他们不相同
- message = self.text_msg['message']
+ message = self.markdown_msg['message']
time = local_now().strftime('%Y-%m-%d %H:%M:%S')
suffix = '\n{}: {}'.format(_('Time'), time)
return {
- 'subject': self.text_msg['subject'],
+ 'subject': self.markdown_msg['subject'],
'message': message + suffix
}
def get_wecom_msg(self) -> dict:
- return self.text_msg
+ return self.markdown_msg
def get_feishu_msg(self) -> dict:
return self.text_msg
@@ -207,12 +222,12 @@ class Message(metaclass=MessageType):
return messages_cls
@classmethod
- def test_all_messages(cls):
+ def test_all_messages(cls, ding=True, wecom=False):
messages_cls = cls.get_all_sub_messages()
for _cls in messages_cls:
try:
- msg = _cls.send_test_msg()
+ _cls.send_test_msg(ding=ding, wecom=wecom)
except NotImplementedError:
continue
diff --git a/apps/perms/templates/perms/_msg_permed_items_expire.html b/apps/perms/templates/perms/_msg_permed_items_expire.html
index 74df4556d..f50c59933 100644
--- a/apps/perms/templates/perms/_msg_permed_items_expire.html
+++ b/apps/perms/templates/perms/_msg_permed_items_expire.html
@@ -16,6 +16,7 @@
+-
{% trans 'If you have any question, please contact the administrator' %}
diff --git a/apps/users/templates/users/_msg_password_expire_reminder.html b/apps/users/templates/users/_msg_password_expire_reminder.html index 0c8175c23..bfd290156 100644 --- a/apps/users/templates/users/_msg_password_expire_reminder.html +++ b/apps/users/templates/users/_msg_password_expire_reminder.html @@ -11,7 +11,7 @@ {% trans 'Click here update password' %}{% trans 'If your password has expired, please click the link below to' %} {% trans 'Reset password' %} diff --git a/apps/users/templates/users/_msg_user_created.html b/apps/users/templates/users/_msg_user_created.html index 678ca237f..3b1c36ed5 100644 --- a/apps/users/templates/users/_msg_user_created.html +++ b/apps/users/templates/users/_msg_user_created.html @@ -15,6 +15,9 @@ {% trans 'click here to set your password' %}
+ + + -{% trans 'This link is valid for 1 hour. After it expires' %} {% trans 'request new one' %}