Skip to content

Commit e28d90d

Browse files
authored
feat: support CUCloud SMN notification provider (casdoor#3502)
1 parent 4fc7600 commit e28d90d

File tree

7 files changed

+57
-16
lines changed

7 files changed

+57
-16
lines changed

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ require (
1212
github.com/casdoor/go-sms-sender v0.25.0
1313
github.com/casdoor/gomail/v2 v2.0.1
1414
github.com/casdoor/ldapserver v1.2.0
15-
github.com/casdoor/notify v0.45.0
15+
github.com/casdoor/notify v1.0.0
1616
github.com/casdoor/oss v1.8.0
1717
github.com/casdoor/xorm-adapter/v3 v3.1.0
1818
github.com/casvisor/casvisor-go-sdk v1.4.0

go.sum

+2-2
Original file line numberDiff line numberDiff line change
@@ -1093,8 +1093,8 @@ github.com/casdoor/gomail/v2 v2.0.1 h1:J+FG6x80s9e5lBHUn8Sv0Y56mud34KiWih5YdmudR
10931093
github.com/casdoor/gomail/v2 v2.0.1/go.mod h1:VnGPslEAtpix5FjHisR/WKB1qvZDBaujbikxDe9d+2Q=
10941094
github.com/casdoor/ldapserver v1.2.0 h1:HdSYe+ULU6z9K+2BqgTrJKQRR4//ERAXB64ttOun6Ow=
10951095
github.com/casdoor/ldapserver v1.2.0/go.mod h1:VwYU2vqQ2pA8sa00PRekH71R2XmgfzMKhmp1XrrDu2s=
1096-
github.com/casdoor/notify v0.45.0 h1:OlaFvcQFjGOgA4mRx07M8AH1gvb5xNo21mcqrVGlLgk=
1097-
github.com/casdoor/notify v0.45.0/go.mod h1:wNHQu0tiDROMBIvz0j3Om3Lhd5yZ+AIfnFb8MYb8OLQ=
1096+
github.com/casdoor/notify v1.0.0 h1:oldsaaQFPrlufm/OA314z8DwFVE1Tc9Gt1z4ptRHhXw=
1097+
github.com/casdoor/notify v1.0.0/go.mod h1:wNHQu0tiDROMBIvz0j3Om3Lhd5yZ+AIfnFb8MYb8OLQ=
10981098
github.com/casdoor/oss v1.8.0 h1:uuyKhDIp7ydOtV4lpqhAY23Ban2Ln8La8+QT36CwylM=
10991099
github.com/casdoor/oss v1.8.0/go.mod h1:uaqO7KBI2lnZcnB8rF7O6C2bN7llIbfC5Ql8ex1yR1U=
11001100
github.com/casdoor/xorm-adapter/v3 v3.1.0 h1:NodWayRtSLVSeCvL9H3Hc61k0G17KhV9IymTCNfh3kk=

notification/cucloud.go

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Copyright 2025 The Casdoor Authors. All Rights Reserved.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package notification
16+
17+
import (
18+
"github.com/casdoor/notify"
19+
"github.com/casdoor/notify/service/cucloud"
20+
)
21+
22+
func NewCucloudProvider(accessKey, secretKey, topicName, messageTitle, cloudRegionCode, accountId, notifyType string) (notify.Notifier, error) {
23+
cucloud := cucloud.New(accessKey, secretKey, topicName, messageTitle, cloudRegionCode, accountId, notifyType)
24+
25+
notifier := notify.New()
26+
notifier.UseServices(cucloud)
27+
28+
return notifier, nil
29+
}

notification/provider.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ package notification
1616

1717
import "github.com/casdoor/notify"
1818

19-
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) {
19+
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) {
2020
if typ == "Telegram" {
2121
return NewTelegramProvider(clientSecret, receiver)
2222
} else if typ == "Custom HTTP" {
@@ -53,6 +53,8 @@ func GetNotificationProvider(typ string, clientId string, clientSecret string, c
5353
return NewRocketChatProvider(clientId, clientSecret, appId, receiver)
5454
} else if typ == "Viber" {
5555
return NewViberProvider(clientId, clientSecret, appId, receiver)
56+
} else if typ == "CUCloud" {
57+
return NewCucloudProvider(clientId, clientSecret, appId, title, regionId, clientId2, metaData)
5658
}
5759

5860
return nil, nil

object/notification.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import (
2323

2424
func getNotificationClient(provider *Provider) (notify.Notifier, error) {
2525
var client notify.Notifier
26-
client, err := notification.GetNotificationProvider(provider.Type, provider.ClientId, provider.ClientSecret, provider.ClientId2, provider.ClientSecret2, provider.AppId, provider.Receiver, provider.Method, provider.Title, provider.Metadata)
26+
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)
2727
if err != nil {
2828
return nil, err
2929
}

web/src/ProviderEditPage.js

+16-11
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,8 @@ class ProviderEditPage extends React.Component {
297297
return Setting.getLabel(i18next.t("provider:Scene"), i18next.t("provider:Scene - Tooltip"));
298298
} else if (provider.type === "WeChat Pay") {
299299
return Setting.getLabel(i18next.t("provider:App ID"), i18next.t("provider:App ID - Tooltip"));
300+
} else if (provider.type === "CUCloud") {
301+
return Setting.getLabel(i18next.t("provider:Account ID"), i18next.t("provider:Account ID - Tooltip"));
300302
} else {
301303
return Setting.getLabel(i18next.t("provider:Client ID 2"), i18next.t("provider:Client ID 2 - Tooltip"));
302304
}
@@ -393,6 +395,9 @@ class ProviderEditPage extends React.Component {
393395
} else if (provider.type === "Line" || provider.type === "Matrix" || provider.type === "Rocket Chat") {
394396
text = i18next.t("provider:App Key");
395397
tooltip = i18next.t("provider:App Key - Tooltip");
398+
} else if (provider.type === "CUCloud") {
399+
text = i18next.t("provider:Topic name");
400+
tooltip = i18next.t("provider:Topic name - Tooltip");
396401
}
397402
}
398403

@@ -771,7 +776,7 @@ class ProviderEditPage extends React.Component {
771776
)
772777
}
773778
{
774-
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 : (
779+
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 : (
775780
<React.Fragment>
776781
<Row style={{marginTop: "20px"}} >
777782
<Col style={{marginTop: "5px"}} span={(Setting.isMobile()) ? 22 : 2}>
@@ -784,7 +789,7 @@ class ProviderEditPage extends React.Component {
784789
</Col>
785790
</Row>
786791
{
787-
(this.state.provider.type === "WeChat Pay") || (this.state.provider.category === "Email" && (this.state.provider.type === "Azure ACS" || this.state.provider.type === "SendGrid")) ? null : (
792+
(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 : (
788793
<Row style={{marginTop: "20px"}} >
789794
<Col style={{marginTop: "5px"}} span={(Setting.isMobile()) ? 22 : 2}>
790795
{this.getClientSecret2Label(this.state.provider)} :
@@ -870,9 +875,9 @@ class ProviderEditPage extends React.Component {
870875
</Row>
871876
)
872877
}
873-
{this.state.provider.category === "Storage" || ["Custom HTTP SMS", "Custom HTTP Email"].includes(this.state.provider.type) ? (
878+
{this.state.provider.category === "Storage" || ["Custom HTTP SMS", "Custom HTTP Email", "CUCloud"].includes(this.state.provider.type) ? (
874879
<div>
875-
{["Local File System"].includes(this.state.provider.type) ? null : (
880+
{["Local File System", "CUCloud"].includes(this.state.provider.type) ? null : (
876881
<Row style={{marginTop: "20px"}} >
877882
<Col style={{marginTop: "5px"}} span={2}>
878883
{Setting.getLabel(i18next.t("provider:Endpoint"), i18next.t("provider:Region endpoint for Internet"))} :
@@ -884,7 +889,7 @@ class ProviderEditPage extends React.Component {
884889
</Col>
885890
</Row>
886891
)}
887-
{["Custom HTTP SMS", "Local File System", "MinIO", "Tencent Cloud COS", "Google Cloud Storage", "Qiniu Cloud Kodo", "Synology", "Casdoor"].includes(this.state.provider.type) ? null : (
892+
{["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 : (
888893
<Row style={{marginTop: "20px"}} >
889894
<Col style={{marginTop: "5px"}} span={2}>
890895
{Setting.getLabel(i18next.t("provider:Endpoint (Intranet)"), i18next.t("provider:Region endpoint for Intranet"))} :
@@ -896,7 +901,7 @@ class ProviderEditPage extends React.Component {
896901
</Col>
897902
</Row>
898903
)}
899-
{["Custom HTTP SMS", "Local File System"].includes(this.state.provider.type) ? null : (
904+
{["Custom HTTP SMS", "Local File System", "CUCloud"].includes(this.state.provider.type) ? null : (
900905
<Row style={{marginTop: "20px"}} >
901906
<Col style={{marginTop: "5px"}} span={2}>
902907
{["Casdoor"].includes(this.state.provider.type) ?
@@ -910,7 +915,7 @@ class ProviderEditPage extends React.Component {
910915
</Col>
911916
</Row>
912917
)}
913-
{["Custom HTTP SMS"].includes(this.state.provider.type) ? null : (
918+
{["Custom HTTP SMS", "CUCloud"].includes(this.state.provider.type) ? null : (
914919
<Row style={{marginTop: "20px"}} >
915920
<Col style={{marginTop: "5px"}} span={2}>
916921
{Setting.getLabel(i18next.t("provider:Path prefix"), i18next.t("provider:Path prefix - Tooltip"))} :
@@ -922,7 +927,7 @@ class ProviderEditPage extends React.Component {
922927
</Col>
923928
</Row>
924929
)}
925-
{["Custom HTTP SMS", "Synology", "Casdoor"].includes(this.state.provider.type) ? null : (
930+
{["Custom HTTP SMS", "Synology", "Casdoor", "CUCloud"].includes(this.state.provider.type) ? null : (
926931
<Row style={{marginTop: "20px"}} >
927932
<Col style={{marginTop: "5px"}} span={2}>
928933
{Setting.getLabel(i18next.t("provider:Domain"), i18next.t("provider:Domain - Tooltip"))} :
@@ -946,7 +951,7 @@ class ProviderEditPage extends React.Component {
946951
</Col>
947952
</Row>
948953
) : null}
949-
{["AWS S3", "Tencent Cloud COS", "Qiniu Cloud Kodo", "Casdoor", "CUCloud OSS", "MinIO"].includes(this.state.provider.type) ? (
954+
{["AWS S3", "Tencent Cloud COS", "Qiniu Cloud Kodo", "Casdoor", "CUCloud OSS", "MinIO", "CUCloud"].includes(this.state.provider.type) ? (
950955
<Row style={{marginTop: "20px"}} >
951956
<Col style={{marginTop: "5px"}} span={2}>
952957
{["Casdoor"].includes(this.state.provider.type) ?
@@ -985,7 +990,7 @@ class ProviderEditPage extends React.Component {
985990
</Col>
986991
</Row>
987992
) : null}
988-
{["Custom HTTP"].includes(this.state.provider.type) ? (
993+
{["Custom HTTP", "CUCloud"].includes(this.state.provider.type) ? (
989994
<Row style={{marginTop: "20px"}} >
990995
<Col style={{marginTop: "5px"}} span={(Setting.isMobile()) ? 22 : 2}>
991996
{Setting.getLabel(i18next.t("provider:Parameter"), i18next.t("provider:Parameter - Tooltip"))} :
@@ -997,7 +1002,7 @@ class ProviderEditPage extends React.Component {
9971002
</Col>
9981003
</Row>
9991004
) : null}
1000-
{["Google Chat"].includes(this.state.provider.type) ? (
1005+
{["Google Chat", "CUCloud"].includes(this.state.provider.type) ? (
10011006
<Row style={{marginTop: "20px"}} >
10021007
<Col style={{marginTop: "5px"}} span={(Setting.isMobile()) ? 22 : 2}>
10031008
{Setting.getLabel(i18next.t("provider:Metadata"), i18next.t("provider:Metadata - Tooltip"))} :

web/src/Setting.js

+5
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,10 @@ export const OtherProviderInfo = {
405405
logo: `${StaticBaseUrl}/img/social_viber.png`,
406406
url: "https://www.viber.com/",
407407
},
408+
"CUCloud": {
409+
logo: `${StaticBaseUrl}/img/cucloud.png`,
410+
url: "https://www.cucloud.cn/",
411+
},
408412
},
409413
};
410414

@@ -1137,6 +1141,7 @@ export function getProviderTypeOptions(category) {
11371141
{id: "Reddit", name: "Reddit"},
11381142
{id: "Rocket Chat", name: "Rocket Chat"},
11391143
{id: "Viber", name: "Viber"},
1144+
{id: "CUCloud", name: "CUCloud"},
11401145
]);
11411146
} else {
11421147
return [];

0 commit comments

Comments
 (0)