Skip to content

Commit

Permalink
minor: add default content_html for sms notifition template (#1226)
Browse files Browse the repository at this point in the history
  • Loading branch information
narasux authored Sep 8, 2023
1 parent 75c8ac7 commit 9839a8d
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 17 deletions.
10 changes: 3 additions & 7 deletions src/bk-user/bkuser/apps/data_source/plugins/local/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,16 +98,12 @@ class NotificationTemplate(BaseModel):
# 模板内容(text)格式
content: str
# 模板内容(html)格式
content_html: Optional[str] = None
content_html: str

@model_validator(mode="after")
def validate_attrs(self) -> "NotificationTemplate":
if self.method == NotificationMethod.EMAIL:
if not self.title:
raise ValueError(_("邮件通知模板需要提供标题"))

if not self.content_html:
raise ValueError(_("邮件通知模板需要提供 HTML 格式内容"))
if self.method == NotificationMethod.EMAIL and not self.title:
raise ValueError(_("邮件通知模板需要提供标题"))

return self

Expand Down
39 changes: 29 additions & 10 deletions src/bk-user/bkuser/biz/data_source_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def _get_default_local_plugin_config(self) -> BaseModel:
content=(
"您好:\n"
+ "您的蓝鲸智云帐户已经成功创建,以下是您的帐户信息\n"
+ " 登录帐户:{username},初始登录密码:{password}\n"
+ "登录帐户:{username},初始登录密码:{password}\n"
+ "为了保障帐户安全,建议您尽快登录平台修改密码:{url}\n"
+ "此邮件为系统自动发送,请勿回复。"
),
Expand Down Expand Up @@ -111,11 +111,17 @@ def _get_default_local_plugin_config(self) -> BaseModel:
content=(
"您好:\n"
+ "您的蓝鲸智云帐户已经成功创建,以下是您的帐户信息\n"
+ " 登录帐户:{username},初始登录密码:{password}\n"
+ "登录帐户:{username},初始登录密码:{password}\n"
+ "为了保障帐户安全,建议您尽快登录平台修改密码:{url}\n"
+ "此邮件为系统自动发送,请勿回复。"
+ "该短信为系统自动发送,请勿回复。"
),
content_html=(
"<p>您好:</p>"
+ "<p>您的蓝鲸智云帐户已经成功创建,以下是您的帐户信息</p>"
+ "<p>登录帐户:{username},初始登录密码:{password}</p>"
+ "<p>为了保障帐户安全,建议您尽快登录平台修改密码:{url}</p>"
+ "<p>该短信为系统自动发送,请勿回复。</p>"
),
content_html=None,
),
NotificationTemplate(
method=NotificationMethod.SMS,
Expand All @@ -126,9 +132,14 @@ def _get_default_local_plugin_config(self) -> BaseModel:
"您好:\n"
+ "我们收到了您重置密码的申请,请点击下方链接进行密码重置:{url}\n"
+ "该链接有效时间为 3 小时,过期后请重新点击密码重置链接:{reset_url}\n"
+ "此邮件为系统自动发送,请勿回复。"
+ "该短信为系统自动发送,请勿回复。"
),
content_html=(
"<p>您好:</p>"
+ "<p>我们收到了您重置密码的申请,请点击下方链接进行密码重置:{url} </p>"
+ "<p>该链接有效时间为 3 小时,过期后请重新点击密码重置链接:{reset_url}</p>"
+ "<p>该短信为系统自动发送,请勿回复。</p>"
),
content_html=None,
),
],
),
Expand Down Expand Up @@ -178,9 +189,13 @@ def _get_default_local_plugin_config(self) -> BaseModel:
content=(
"{username},您好:\n"
+ "您的蓝鲸智云平台密码将于 {expired_at} 天后过期,为避免影响使用,请尽快登陆平台修改密码。\n" # noqa: E501
+ "此邮件为系统自动发送,请勿回复。"
+ "该短信为系统自动发送,请勿回复。"
),
content_html=(
"<p>{username},您好:</p>"
+ "<p>您的蓝鲸智云平台密码将于 {expired_at} 天后过期,为避免影响使用,请尽快登陆平台修改密码。</p>" # noqa: E501
+ "<p>该短信为系统自动发送,请勿回复。</p>"
),
content_html=None,
),
NotificationTemplate(
method=NotificationMethod.SMS,
Expand All @@ -190,9 +205,13 @@ def _get_default_local_plugin_config(self) -> BaseModel:
content=(
"{username},您好:\n"
+ "您的蓝鲸智云平台密码已过期,为避免影响使用,请尽快登陆平台修改密码。\n" # noqa: E501
+ "此邮件为系统自动发送,请勿回复。"
+ "该短信为系统自动发送,请勿回复。"
),
content_html=(
"<p>{username},您好:</p>"
+ "<p>您的蓝鲸智云平台密码已过期,为避免影响使用,请尽快登陆平台修改密码。</p>" # noqa: E501
+ "<p>该短信为系统自动发送,请勿回复。</p>"
),
content_html=None,
),
],
),
Expand Down

0 comments on commit 9839a8d

Please sign in to comment.