From e28d90d0aa7cb4d5786052dfd40b1f59df1ab1d8 Mon Sep 17 00:00:00 2001 From: DacongDA Date: Fri, 17 Jan 2025 08:35:31 +0800 Subject: [PATCH] feat: support CUCloud SMN notification provider (#3502) --- go.mod | 2 +- go.sum | 4 ++-- notification/cucloud.go | 29 +++++++++++++++++++++++++++++ notification/provider.go | 4 +++- object/notification.go | 2 +- web/src/ProviderEditPage.js | 27 ++++++++++++++++----------- web/src/Setting.js | 5 +++++ 7 files changed, 57 insertions(+), 16 deletions(-) create mode 100644 notification/cucloud.go diff --git a/go.mod b/go.mod index 6193a22e..937c9b89 100644 --- a/go.mod +++ b/go.mod @@ -12,7 +12,7 @@ require ( github.com/casdoor/go-sms-sender v0.25.0 github.com/casdoor/gomail/v2 v2.0.1 github.com/casdoor/ldapserver v1.2.0 - github.com/casdoor/notify v0.45.0 + github.com/casdoor/notify v1.0.0 github.com/casdoor/oss v1.8.0 github.com/casdoor/xorm-adapter/v3 v3.1.0 github.com/casvisor/casvisor-go-sdk v1.4.0 diff --git a/go.sum b/go.sum index c703d81f..5fe05dc4 100644 --- a/go.sum +++ b/go.sum @@ -1093,8 +1093,8 @@ github.com/casdoor/gomail/v2 v2.0.1 h1:J+FG6x80s9e5lBHUn8Sv0Y56mud34KiWih5YdmudR github.com/casdoor/gomail/v2 v2.0.1/go.mod h1:VnGPslEAtpix5FjHisR/WKB1qvZDBaujbikxDe9d+2Q= github.com/casdoor/ldapserver v1.2.0 h1:HdSYe+ULU6z9K+2BqgTrJKQRR4//ERAXB64ttOun6Ow= github.com/casdoor/ldapserver v1.2.0/go.mod h1:VwYU2vqQ2pA8sa00PRekH71R2XmgfzMKhmp1XrrDu2s= -github.com/casdoor/notify v0.45.0 h1:OlaFvcQFjGOgA4mRx07M8AH1gvb5xNo21mcqrVGlLgk= -github.com/casdoor/notify v0.45.0/go.mod h1:wNHQu0tiDROMBIvz0j3Om3Lhd5yZ+AIfnFb8MYb8OLQ= +github.com/casdoor/notify v1.0.0 h1:oldsaaQFPrlufm/OA314z8DwFVE1Tc9Gt1z4ptRHhXw= +github.com/casdoor/notify v1.0.0/go.mod h1:wNHQu0tiDROMBIvz0j3Om3Lhd5yZ+AIfnFb8MYb8OLQ= github.com/casdoor/oss v1.8.0 h1:uuyKhDIp7ydOtV4lpqhAY23Ban2Ln8La8+QT36CwylM= github.com/casdoor/oss v1.8.0/go.mod h1:uaqO7KBI2lnZcnB8rF7O6C2bN7llIbfC5Ql8ex1yR1U= github.com/casdoor/xorm-adapter/v3 v3.1.0 h1:NodWayRtSLVSeCvL9H3Hc61k0G17KhV9IymTCNfh3kk= diff --git a/notification/cucloud.go b/notification/cucloud.go new file mode 100644 index 00000000..9480b237 --- /dev/null +++ b/notification/cucloud.go @@ -0,0 +1,29 @@ +// Copyright 2025 The Casdoor Authors. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// 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. + +package notification + +import ( + "github.com/casdoor/notify" + "github.com/casdoor/notify/service/cucloud" +) + +func NewCucloudProvider(accessKey, secretKey, topicName, messageTitle, cloudRegionCode, accountId, notifyType string) (notify.Notifier, error) { + cucloud := cucloud.New(accessKey, secretKey, topicName, messageTitle, cloudRegionCode, accountId, notifyType) + + notifier := notify.New() + notifier.UseServices(cucloud) + + return notifier, nil +} diff --git a/notification/provider.go b/notification/provider.go index a86af01d..26c1abc0 100644 --- a/notification/provider.go +++ b/notification/provider.go @@ -16,7 +16,7 @@ package notification import "github.com/casdoor/notify" -func GetNotificationProvider(typ string, clientId string, clientSecret string, clientId2 string, clientSecret2 string, appId string, receiver string, method string, title string, metaData string) (notify.Notifier, error) { +func GetNotificationProvider(typ string, clientId string, clientSecret string, clientId2 string, clientSecret2 string, appId string, receiver string, method string, title string, metaData string, regionId string) (notify.Notifier, error) { if typ == "Telegram" { return NewTelegramProvider(clientSecret, receiver) } else if typ == "Custom HTTP" { @@ -53,6 +53,8 @@ func GetNotificationProvider(typ string, clientId string, clientSecret string, c return NewRocketChatProvider(clientId, clientSecret, appId, receiver) } else if typ == "Viber" { return NewViberProvider(clientId, clientSecret, appId, receiver) + } else if typ == "CUCloud" { + return NewCucloudProvider(clientId, clientSecret, appId, title, regionId, clientId2, metaData) } return nil, nil diff --git a/object/notification.go b/object/notification.go index cb1b99de..7e9fd353 100644 --- a/object/notification.go +++ b/object/notification.go @@ -23,7 +23,7 @@ import ( func getNotificationClient(provider *Provider) (notify.Notifier, error) { var client notify.Notifier - client, err := notification.GetNotificationProvider(provider.Type, provider.ClientId, provider.ClientSecret, provider.ClientId2, provider.ClientSecret2, provider.AppId, provider.Receiver, provider.Method, provider.Title, provider.Metadata) + client, err := notification.GetNotificationProvider(provider.Type, provider.ClientId, provider.ClientSecret, provider.ClientId2, provider.ClientSecret2, provider.AppId, provider.Receiver, provider.Method, provider.Title, provider.Metadata, provider.RegionId) if err != nil { return nil, err } diff --git a/web/src/ProviderEditPage.js b/web/src/ProviderEditPage.js index b8409792..7f472e1c 100644 --- a/web/src/ProviderEditPage.js +++ b/web/src/ProviderEditPage.js @@ -297,6 +297,8 @@ class ProviderEditPage extends React.Component { return Setting.getLabel(i18next.t("provider:Scene"), i18next.t("provider:Scene - Tooltip")); } else if (provider.type === "WeChat Pay") { return Setting.getLabel(i18next.t("provider:App ID"), i18next.t("provider:App ID - Tooltip")); + } else if (provider.type === "CUCloud") { + return Setting.getLabel(i18next.t("provider:Account ID"), i18next.t("provider:Account ID - Tooltip")); } else { return Setting.getLabel(i18next.t("provider:Client ID 2"), i18next.t("provider:Client ID 2 - Tooltip")); } @@ -393,6 +395,9 @@ class ProviderEditPage extends React.Component { } else if (provider.type === "Line" || provider.type === "Matrix" || provider.type === "Rocket Chat") { text = i18next.t("provider:App Key"); tooltip = i18next.t("provider:App Key - Tooltip"); + } else if (provider.type === "CUCloud") { + text = i18next.t("provider:Topic name"); + tooltip = i18next.t("provider:Topic name - Tooltip"); } } @@ -771,7 +776,7 @@ class ProviderEditPage extends React.Component { ) } { - this.state.provider.category !== "Email" && this.state.provider.type !== "WeChat" && this.state.provider.type !== "Apple" && this.state.provider.type !== "Aliyun Captcha" && this.state.provider.type !== "WeChat Pay" && this.state.provider.type !== "Twitter" && this.state.provider.type !== "Reddit" ? null : ( + this.state.provider.category !== "Email" && this.state.provider.type !== "WeChat" && this.state.provider.type !== "Apple" && this.state.provider.type !== "Aliyun Captcha" && this.state.provider.type !== "WeChat Pay" && this.state.provider.type !== "Twitter" && this.state.provider.type !== "Reddit" && this.state.provider.type !== "CUCloud" ? null : ( @@ -784,7 +789,7 @@ class ProviderEditPage extends React.Component { { - (this.state.provider.type === "WeChat Pay") || (this.state.provider.category === "Email" && (this.state.provider.type === "Azure ACS" || this.state.provider.type === "SendGrid")) ? null : ( + (this.state.provider.type === "WeChat Pay" || this.state.provider.type === "CUCloud") || (this.state.provider.category === "Email" && (this.state.provider.type === "Azure ACS" || this.state.provider.type === "SendGrid")) ? null : ( {this.getClientSecret2Label(this.state.provider)} : @@ -870,9 +875,9 @@ class ProviderEditPage extends React.Component { ) } - {this.state.provider.category === "Storage" || ["Custom HTTP SMS", "Custom HTTP Email"].includes(this.state.provider.type) ? ( + {this.state.provider.category === "Storage" || ["Custom HTTP SMS", "Custom HTTP Email", "CUCloud"].includes(this.state.provider.type) ? (
- {["Local File System"].includes(this.state.provider.type) ? null : ( + {["Local File System", "CUCloud"].includes(this.state.provider.type) ? null : ( {Setting.getLabel(i18next.t("provider:Endpoint"), i18next.t("provider:Region endpoint for Internet"))} : @@ -884,7 +889,7 @@ class ProviderEditPage extends React.Component { )} - {["Custom HTTP SMS", "Local File System", "MinIO", "Tencent Cloud COS", "Google Cloud Storage", "Qiniu Cloud Kodo", "Synology", "Casdoor"].includes(this.state.provider.type) ? null : ( + {["Custom HTTP SMS", "Local File System", "MinIO", "Tencent Cloud COS", "Google Cloud Storage", "Qiniu Cloud Kodo", "Synology", "Casdoor", "CUCloud"].includes(this.state.provider.type) ? null : ( {Setting.getLabel(i18next.t("provider:Endpoint (Intranet)"), i18next.t("provider:Region endpoint for Intranet"))} : @@ -896,7 +901,7 @@ class ProviderEditPage extends React.Component { )} - {["Custom HTTP SMS", "Local File System"].includes(this.state.provider.type) ? null : ( + {["Custom HTTP SMS", "Local File System", "CUCloud"].includes(this.state.provider.type) ? null : ( {["Casdoor"].includes(this.state.provider.type) ? @@ -910,7 +915,7 @@ class ProviderEditPage extends React.Component { )} - {["Custom HTTP SMS"].includes(this.state.provider.type) ? null : ( + {["Custom HTTP SMS", "CUCloud"].includes(this.state.provider.type) ? null : ( {Setting.getLabel(i18next.t("provider:Path prefix"), i18next.t("provider:Path prefix - Tooltip"))} : @@ -922,7 +927,7 @@ class ProviderEditPage extends React.Component { )} - {["Custom HTTP SMS", "Synology", "Casdoor"].includes(this.state.provider.type) ? null : ( + {["Custom HTTP SMS", "Synology", "Casdoor", "CUCloud"].includes(this.state.provider.type) ? null : ( {Setting.getLabel(i18next.t("provider:Domain"), i18next.t("provider:Domain - Tooltip"))} : @@ -946,7 +951,7 @@ class ProviderEditPage extends React.Component { ) : null} - {["AWS S3", "Tencent Cloud COS", "Qiniu Cloud Kodo", "Casdoor", "CUCloud OSS", "MinIO"].includes(this.state.provider.type) ? ( + {["AWS S3", "Tencent Cloud COS", "Qiniu Cloud Kodo", "Casdoor", "CUCloud OSS", "MinIO", "CUCloud"].includes(this.state.provider.type) ? ( {["Casdoor"].includes(this.state.provider.type) ? @@ -985,7 +990,7 @@ class ProviderEditPage extends React.Component { ) : null} - {["Custom HTTP"].includes(this.state.provider.type) ? ( + {["Custom HTTP", "CUCloud"].includes(this.state.provider.type) ? ( {Setting.getLabel(i18next.t("provider:Parameter"), i18next.t("provider:Parameter - Tooltip"))} : @@ -997,7 +1002,7 @@ class ProviderEditPage extends React.Component { ) : null} - {["Google Chat"].includes(this.state.provider.type) ? ( + {["Google Chat", "CUCloud"].includes(this.state.provider.type) ? ( {Setting.getLabel(i18next.t("provider:Metadata"), i18next.t("provider:Metadata - Tooltip"))} : diff --git a/web/src/Setting.js b/web/src/Setting.js index e1991ead..14cbc779 100644 --- a/web/src/Setting.js +++ b/web/src/Setting.js @@ -405,6 +405,10 @@ export const OtherProviderInfo = { logo: `${StaticBaseUrl}/img/social_viber.png`, url: "https://www.viber.com/", }, + "CUCloud": { + logo: `${StaticBaseUrl}/img/cucloud.png`, + url: "https://www.cucloud.cn/", + }, }, }; @@ -1137,6 +1141,7 @@ export function getProviderTypeOptions(category) { {id: "Reddit", name: "Reddit"}, {id: "Rocket Chat", name: "Rocket Chat"}, {id: "Viber", name: "Viber"}, + {id: "CUCloud", name: "CUCloud"}, ]); } else { return [];