From 1cedeb40115428d61cacb2b3f4a0cdb722c6c23f Mon Sep 17 00:00:00 2001 From: hanshuaikang <1758504262@qq.com> Date: Thu, 18 Jan 2024 18:15:24 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=90=8E=E5=8F=B0=E6=8E=A5=E5=85=A5?= =?UTF-8?q?=E9=80=9A=E7=9F=A5=E4=B8=AD=E5=BF=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bin/post_compile | 3 ++ config/default.py | 2 + itsm/iadmin/contants.py | 6 ++- itsm/notice/__init__.py | 1 + itsm/notice/apps.py | 19 ++++++++++ itsm/notice/management/__init__.py | 12 ++++++ itsm/notice/management/commands/__init__.py | 12 ++++++ .../management/commands/register_notice.py | 38 +++++++++++++++++++ requirements.txt | 2 + urls.py | 1 + 10 files changed, 94 insertions(+), 2 deletions(-) create mode 100644 itsm/notice/__init__.py create mode 100644 itsm/notice/apps.py create mode 100644 itsm/notice/management/__init__.py create mode 100644 itsm/notice/management/commands/__init__.py create mode 100644 itsm/notice/management/commands/register_notice.py diff --git a/bin/post_compile b/bin/post_compile index e3bdd650e..6387049af 100644 --- a/bin/post_compile +++ b/bin/post_compile @@ -7,3 +7,6 @@ python manage.py createcachetable django_cache echo "init apigw public key" python manage.py sync_saas_apigw + +echo "register notice center" +python manage.py register_notice diff --git a/config/default.py b/config/default.py index e9d522246..335c56049 100644 --- a/config/default.py +++ b/config/default.py @@ -84,6 +84,7 @@ "itsm.trigger", "itsm.task", "itsm.openapi", + "itsm.notice", "data_migration", # 'silk', "mptt", @@ -107,6 +108,7 @@ "itsm.monitor", "blueapps.opentelemetry.instrument_app", "itsm.plugin_service", + "bk_notice_sdk", ) INSTALLED_APPS = ("itsm.helper",) + INSTALLED_APPS diff --git a/itsm/iadmin/contants.py b/itsm/iadmin/contants.py index 5f8eb1656..6bc2340e0 100644 --- a/itsm/iadmin/contants.py +++ b/itsm/iadmin/contants.py @@ -408,7 +408,7 @@ ${message}""" GENERAL_CONTENT_DONE = SMS_CONTENT_DONE = WEIXIN_CONTENT_DONE = """您的需求(${title})已经处理完成,现邀请您为我们的服务进行评价。您的反馈对我们非常重要!感谢回复与建议,祝您工作愉快! -${ticket_url}""" +${ticket_url}""" # noqa GENERAL_CONTENT_FOLLOW = SMS_CONTENT_FOLLOW = WEIXIN_CONTENT_FOLLOW = """你有一条${service_type_name}工单需要关注 标题:${title} @@ -554,7 +554,6 @@ [NOTIFY_TITLE_COMMON, SMS_CONTENT_FAILED, NODE_FAILED, GENERAL_NOTICE, "TICKET"], ] - NOTIFY_TEMPLATE = [ # title_template content_template action notify_type used_by (NOTIFY_TITLE_COMMON, """ ${message}""", SUPERVISE_OPERATE, SMS, "TICKET"), @@ -803,6 +802,7 @@ TABLE_FIELDS_SWITCH = "TABLE_FIELDS_SWITCH" FIRST_STATE_SWITCH = "FIRST_STATE_SWITCH" SMS_COMMENT_SWITCH = "SMS_COMMENT_SWITCH" +NOTICE_CENTER_SWITCH = "NOTICE_CENTER_SWITCH" DEFAULT_SETTINGS = [ [SYS_FILE_PATH, "PATH", ""], @@ -817,6 +817,8 @@ [TRIGGER_SWITCH, "FUNCTION", SWITCH_ON], [TASK_SWITCH, "FUNCTION", SWITCH_OFF], [SMS_COMMENT_SWITCH, "FUNCTION", SWITCH_OFF], + [SMS_COMMENT_SWITCH, "FUNCTION", SWITCH_OFF], + [NOTICE_CENTER_SWITCH, "FUNCTION", SWITCH_OFF], ] PROJECT_SETTING = [ diff --git a/itsm/notice/__init__.py b/itsm/notice/__init__.py new file mode 100644 index 000000000..40a96afc6 --- /dev/null +++ b/itsm/notice/__init__.py @@ -0,0 +1 @@ +# -*- coding: utf-8 -*- diff --git a/itsm/notice/apps.py b/itsm/notice/apps.py new file mode 100644 index 000000000..83953424c --- /dev/null +++ b/itsm/notice/apps.py @@ -0,0 +1,19 @@ +# -*- coding: utf-8 -*- +""" +Tencent is pleased to support the open source community by making 蓝鲸智云PaaS平台社区版 (BlueKing PaaS Community +Edition) available. +Copyright (C) 2017 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 +http://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.apps import AppConfig + + +class NoticeConfig(AppConfig): + name = "itsm.notice" + verbose_name = "Notice" diff --git a/itsm/notice/management/__init__.py b/itsm/notice/management/__init__.py new file mode 100644 index 000000000..26a6d1c27 --- /dev/null +++ b/itsm/notice/management/__init__.py @@ -0,0 +1,12 @@ +# -*- coding: utf-8 -*- +""" +Tencent is pleased to support the open source community by making 蓝鲸智云PaaS平台社区版 (BlueKing PaaS Community +Edition) available. +Copyright (C) 2017 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 +http://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. +""" diff --git a/itsm/notice/management/commands/__init__.py b/itsm/notice/management/commands/__init__.py new file mode 100644 index 000000000..26a6d1c27 --- /dev/null +++ b/itsm/notice/management/commands/__init__.py @@ -0,0 +1,12 @@ +# -*- coding: utf-8 -*- +""" +Tencent is pleased to support the open source community by making 蓝鲸智云PaaS平台社区版 (BlueKing PaaS Community +Edition) available. +Copyright (C) 2017 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 +http://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. +""" diff --git a/itsm/notice/management/commands/register_notice.py b/itsm/notice/management/commands/register_notice.py new file mode 100644 index 000000000..be44aec2f --- /dev/null +++ b/itsm/notice/management/commands/register_notice.py @@ -0,0 +1,38 @@ +# -*- coding: utf-8 -*- +""" +Tencent is pleased to support the open source community by making 蓝鲸智云PaaS平台社区版 (BlueKing PaaS Community +Edition) available. +Copyright (C) 2017 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 +http://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. +""" +import logging +from django.conf import settings +from django.core.management.base import BaseCommand +from django.core.management import call_command + +from itsm.iadmin.contants import NOTICE_CENTER_SWITCH +from itsm.iadmin.models import SystemSettings + +logger = logging.getLogger("root") + + +class Command(BaseCommand): + def handle(self, *args, **kwargs): + # 非PAAS v3 无法开启通知中心 + if not settings.IS_PAAS_V3: + print( + "[bk_itsm]current version is not open v3,skip register_bk_itsm_notice" + ) + return + try: + call_command("register_application") + SystemSettings.objects.update_or_create( + defaults={"value": "on"}, key=NOTICE_CENTER_SWITCH + ) + except Exception as e: + logger.exception("[register_bk_itsm_notice] err: {}".format(e)) diff --git a/requirements.txt b/requirements.txt index c16f53889..f681a38c4 100644 --- a/requirements.txt +++ b/requirements.txt @@ -127,3 +127,5 @@ apigw-manager[cryptography]==1.0.7 blueapps[opentelemetry,bkcrypto]==4.8.0 drf-yasg==1.20.0 + +bk-notice-sdk==1.2.0 diff --git a/urls.py b/urls.py index 7db53632d..cd1cd722f 100644 --- a/urls.py +++ b/urls.py @@ -34,6 +34,7 @@ urlpatterns = [ # Django后台数据库管理® url(r"^admin/", admin.site.urls), + url(r"^notice/", include("bk_notice_sdk.urls")), # 用户登录鉴权 # url(r'^account/', include('account.urls')), url(r"^account/", include("blueapps.account.urls")),