Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(backend): 单据通知适配器,接入bkchat #8755 #8757

Open
wants to merge 2 commits into
base: v1.5.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions dbm-ui/backend/components/bkchat/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# -*- coding: utf-8 -*-
"""
TencentBlueKing is pleased to support the open source community by making 蓝鲸智云-DB管理系统(BlueKing-BK-DBM) available.
Copyright (C) 2017-2023 THL A29 Limited, a Tencent company. All rights reserved.
Licensed under the MIT License (the "License"); you may not use this file except in compliance with the License.
You may obtain a copy of the License at https://opensource.org/licenses/MIT
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
specific language governing permissions and limitations under the License.
"""
30 changes: 30 additions & 0 deletions dbm-ui/backend/components/bkchat/client.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# -*- coding: utf-8 -*-
"""
TencentBlueKing is pleased to support the open source community by making 蓝鲸智云-DB管理系统(BlueKing-BK-DBM) available.
Copyright (C) 2017-2023 THL A29 Limited, a Tencent company. All rights reserved.
Licensed under the MIT License (the "License"); you may not use this file except in compliance with the License.
You may obtain a copy of the License at https://opensource.org/licenses/MIT
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
specific language governing permissions and limitations under the License.
"""

from django.utils.translation import ugettext_lazy as _

from ..base import BaseApi
from ..domains import BKCHAT_APIGW_DOMAIN


class _BkChatApi(BaseApi):
MODULE = _("蓝鲸信息流")
BASE = BKCHAT_APIGW_DOMAIN

def __init__(self):
self.send_msg = self.generate_data_api(
method="POST",
url="dbm_ticket_send/",
description=_("dbm消息发送"),
)


BkChatApi = _BkChatApi()
12 changes: 0 additions & 12 deletions dbm-ui/backend/components/cmsi/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@

from django.utils.translation import ugettext_lazy as _

from blue_krill.data_types.enum import EnumField, StructuredEnum

from ..base import BaseApi
from ..domains import CMSI_APIGW_DOMAIN

Expand All @@ -21,16 +19,6 @@ class _CmsiApi(BaseApi):
MODULE = _("消息管理")
BASE = CMSI_APIGW_DOMAIN

class MsgType(str, StructuredEnum):
SMS = EnumField("sms", _("短信"))
WEIXIN = EnumField("weixin", _("微信"))
MAIL = EnumField("mail", _("邮件"))
VOICE = EnumField("voice", _("语音"))
RTX = EnumField("rtx", _("企业微信"))
WECOM_ROBOT = EnumField("wecom_robot", _("企业微信机器人"))
# 未知发送类型,配置此type一般用于跳过消息发送
UNKNOWN = EnumField("unknown", _("未知"))

def __init__(self):
self.send_msg = self.generate_data_api(
method="POST",
Expand Down
66 changes: 0 additions & 66 deletions dbm-ui/backend/components/cmsi/handler.py

This file was deleted.

1 change: 1 addition & 0 deletions dbm-ui/backend/components/domains.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
ESB_APIGW_DOMAIN = env.ESB_APIGW_DOMAIN or ESB_DOMAIN_TPL.format("esb")
USER_MANAGE_APIGW_DOMAIN = env.USER_MANAGE_APIGW_DOMAIN or ESB_DOMAIN_TPL.format("usermanage")
CMSI_APIGW_DOMAIN = env.CMSI_APIGW_DOMAIN or ESB_DOMAIN_TPL.format("cmsi")
BKCHAT_APIGW_DOMAIN = env.BKCHAT_APIGW_DOMAIN
ITSM_APIGW_DOMAIN = env.ITSM_APIGW_DOMAIN or ESB_DOMAIN_TPL.format("itsm")
BKLOG_APIGW_DOMAIN = env.BKLOG_APIGW_DOMAIN or ESB_DOMAIN_TPL.format("bk_log")
BKNODEMAN_APIGW_DOMAIN = env.BKNODEMAN_APIGW_DOMAIN or ESB_DOMAIN_TPL.format("nodeman")
Expand Down
3 changes: 2 additions & 1 deletion dbm-ui/backend/configuration/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,12 @@ class BizSettingsEnum(str, StructuredEnum):

OPEN_AREA_VARS = EnumField("OPEN_AREA_VARS", _("开区模板的渲染变量"))
INDEPENDENT_HOSTING_DB_TYPES = EnumField("INDEPENDENT_HOSTING_DB_TYPES", _("独立托管机器的数据库类型"))
# TODO: 后续待删除
# TODO: SKIP_GRAMMAR_CHECK 后续待删除
SKIP_GRAMMAR_CHECK = EnumField("SKIP_GRAMMAR_CHECK", _("是否跳过语义检查"))
SQL_IMPORT_FORCE_ITSM = EnumField("SQL_IMPORT_FORCE_ITSM", _("是否变更SQL强制需要审批流"))
BIZ_ASSISTANCE_VARS = EnumField("BIZ_ASSISTANCE_VARS", _("业务协助人员变量"))
BIZ_ASSISTANCE_SWITCH = EnumField("BIZ_ASSISTANCE_SWITCH", _("业务协助开关"))
NOTIFY_CONFIG = EnumField("NOTIFY_CONFIG", _("业务通知渠道配置"))


DEFAULT_DB_ADMINISTRATORS = ["admin"]
Expand Down
5 changes: 3 additions & 2 deletions dbm-ui/backend/configuration/views/system.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
from backend.flow.utils.cc_manage import CcManage
from backend.iam_app.dataclass.actions import ActionEnum
from backend.iam_app.handlers.drf_perm.base import DBManagePermission, RejectPermission, ResourceActionPermission
from backend.iam_app.handlers.drf_perm.dbconfig import BizAssistancePermission
from backend.iam_app.handlers.drf_perm.dbconfig import BizBatchSettingsPermission, BizSettingsPermission

tags = [_("系统设置")]

Expand Down Expand Up @@ -134,7 +134,8 @@ class BizSettingsViewSet(viewsets.AuditedModelViewSet):
queryset = BizSettings.objects.all()

action_permission_map = {
("batch_update_settings",): [BizAssistancePermission()],
("batch_update_settings",): [BizBatchSettingsPermission()],
("update_settings",): [BizSettingsPermission()],
}
default_permission_class = [DBManagePermission()]

Expand Down
12 changes: 12 additions & 0 deletions dbm-ui/backend/core/notify/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# -*- coding: utf-8 -*-
"""
TencentBlueKing is pleased to support the open source community by making 蓝鲸智云-DB管理系统(BlueKing-BK-DBM) available.
Copyright (C) 2017-2023 THL A29 Limited, a Tencent company. All rights reserved.
Licensed under the MIT License (the "License"); you may not use this file except in compliance with the License.
You may obtain a copy of the License at https://opensource.org/licenses/MIT
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
specific language governing permissions and limitations under the License.
"""

from .handlers import NotifyAdapter, send_msg
31 changes: 31 additions & 0 deletions dbm-ui/backend/core/notify/constants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# -*- coding: utf-8 -*-
"""
TencentBlueKing is pleased to support the open source community by making 蓝鲸智云-DB管理系统(BlueKing-BK-DBM) available.
Copyright (C) 2017-2023 THL A29 Limited, a Tencent company. All rights reserved.
Licensed under the MIT License (the "License"); you may not use this file except in compliance with the License.
You may obtain a copy of the License at https://opensource.org/licenses/MIT
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
specific language governing permissions and limitations under the License.
"""
from django.utils.translation import ugettext as _

from backend.ticket.constants import TicketStatus
from blue_krill.data_types.enum import EnumField, StructuredEnum


class MsgType(str, StructuredEnum):
SMS = EnumField("sms", _("短信"))
WEIXIN = EnumField("weixin", _("微信"))
MAIL = EnumField("mail", _("邮件"))
VOICE = EnumField("voice", _("语音"))
RTX = EnumField("rtx", _("企业微信"))
WECOM_ROBOT = EnumField("wecom_robot", _("企业微信机器人"))
# 未知发送类型,配置此type一般用于跳过消息发送
UNKNOWN = EnumField("unknown", _("未知"))


# 默认通知:微信和邮件
DEFAULT_BIZ_NOTIFY_CONFIG = {
status: {MsgType.RTX.value: True, MsgType.MAIL.value: True} for status in TicketStatus.get_values()
}
19 changes: 19 additions & 0 deletions dbm-ui/backend/core/notify/exceptions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# -*- coding: utf-8 -*-
"""
TencentBlueKing is pleased to support the open source community by making 蓝鲸智云-DB管理系统(BlueKing-BK-DBM) available.
Copyright (C) 2017-2023 THL A29 Limited, a Tencent company. All rights reserved.
Licensed under the MIT License (the "License"); you may not use this file except in compliance with the License.
You may obtain a copy of the License at https://opensource.org/licenses/MIT
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
specific language governing permissions and limitations under the License.
"""


from django.utils.translation import ugettext_lazy as _

from ..exceptions import CoreBaseException


class NotifyBaseException(CoreBaseException):
MESSAGE = _("通知失败")
Loading