diff --git a/internal/rpc/rpc_client.go b/internal/rpc/rpc_client.go index 061cfbb4..1254f4de 100644 --- a/internal/rpc/rpc_client.go +++ b/internal/rpc/rpc_client.go @@ -252,6 +252,10 @@ func (this *RPCClient) MessageTaskLogRPC() pb.MessageTaskLogServiceClient { return pb.NewMessageTaskLogServiceClient(this.pickConn()) } +func (this *RPCClient) MessageReceiverRPC() pb.MessageReceiverServiceClient { + return pb.NewMessageReceiverServiceClient(this.pickConn()) +} + func (this *RPCClient) IPLibraryRPC() pb.IPLibraryServiceClient { return pb.NewIPLibraryServiceClient(this.pickConn()) } diff --git a/internal/web/actions/default/admins/recipients/createPopup.go b/internal/web/actions/default/admins/recipients/createPopup.go index 0924fdec..8fe807f0 100644 --- a/internal/web/actions/default/admins/recipients/createPopup.go +++ b/internal/web/actions/default/admins/recipients/createPopup.go @@ -41,11 +41,11 @@ func (this *CreatePopupAction) RunPost(params struct { groupIds := utils.SplitNumbers(params.GroupIds) resp, err := this.RPC().MessageRecipientRPC().CreateMessageRecipient(this.AdminContext(), &pb.CreateMessageRecipientRequest{ - AdminId: params.AdminId, - InstanceId: params.InstanceId, - User: params.User, - GroupIds: groupIds, - Description: params.Description, + AdminId: params.AdminId, + MessageMediaInstanceId: params.InstanceId, + User: params.User, + MessageRecipientGroupIds: groupIds, + Description: params.Description, }) if err != nil { this.ErrorPage(err) diff --git a/internal/web/actions/default/admins/recipients/index.go b/internal/web/actions/default/admins/recipients/index.go index 120f24c5..a0d576f8 100644 --- a/internal/web/actions/default/admins/recipients/index.go +++ b/internal/web/actions/default/admins/recipients/index.go @@ -18,10 +18,10 @@ func (this *IndexAction) RunGet(params struct { }) { // TODO 增加系统用户、媒介类型等条件搜索 countResp, err := this.RPC().MessageRecipientRPC().CountAllEnabledMessageRecipients(this.AdminContext(), &pb.CountAllEnabledMessageRecipientsRequest{ - AdminId: 0, - MediaType: "", - GroupId: 0, - Keyword: "", + AdminId: 0, + MediaType: "", + MessageRecipientGroupId: 0, + Keyword: "", }) if err != nil { this.ErrorPage(err) @@ -32,12 +32,12 @@ func (this *IndexAction) RunGet(params struct { this.Data["page"] = page.AsHTML() recipientsResp, err := this.RPC().MessageRecipientRPC().ListEnabledMessageRecipients(this.AdminContext(), &pb.ListEnabledMessageRecipientsRequest{ - AdminId: 0, - MediaType: "", - GroupId: 0, - Keyword: "", - Offset: page.Offset, - Size: page.Size, + AdminId: 0, + MediaType: "", + MessageRecipientGroupId: 0, + Keyword: "", + Offset: page.Offset, + Size: page.Size, }) recipientMaps := []maps.Map{} diff --git a/internal/web/actions/default/admins/recipients/instances/index.go b/internal/web/actions/default/admins/recipients/instances/index.go index 9d7158ba..daf1e1ef 100644 --- a/internal/web/actions/default/admins/recipients/instances/index.go +++ b/internal/web/actions/default/admins/recipients/instances/index.go @@ -43,6 +43,7 @@ func (this *IndexAction) RunGet(params struct { } instanceMaps = append(instanceMaps, maps.Map{ "id": instance.Id, + "name": instance.Name, "isOn": instance.IsOn, "media": maps.Map{ "name": instance.MessageMedia.Name, diff --git a/internal/web/actions/default/admins/recipients/update.go b/internal/web/actions/default/admins/recipients/update.go index 5de631e0..c7665e98 100644 --- a/internal/web/actions/default/admins/recipients/update.go +++ b/internal/web/actions/default/admins/recipients/update.go @@ -75,13 +75,13 @@ func (this *UpdateAction) RunPost(params struct { groupIds := utils.SplitNumbers(params.GroupIds) _, err := this.RPC().MessageRecipientRPC().UpdateMessageRecipient(this.AdminContext(), &pb.UpdateMessageRecipientRequest{ - MessageRecipientId: params.RecipientId, - AdminId: params.AdminId, - InstanceId: params.InstanceId, - User: params.User, - GroupIds: groupIds, - Description: params.Description, - IsOn: params.IsOn, + MessageRecipientId: params.RecipientId, + AdminId: params.AdminId, + MessageMediaInstanceId: params.InstanceId, + User: params.User, + MessageRecipientGroupIds: groupIds, + Description: params.Description, + IsOn: params.IsOn, }) if err != nil { this.ErrorPage(err) diff --git a/internal/web/actions/default/clusters/cluster/settings/init.go b/internal/web/actions/default/clusters/cluster/settings/init.go index 48b0acd7..3b2ce45a 100644 --- a/internal/web/actions/default/clusters/cluster/settings/init.go +++ b/internal/web/actions/default/clusters/cluster/settings/init.go @@ -6,6 +6,7 @@ import ( "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/clusters/cluster/settings/dns" firewallActions "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/clusters/cluster/settings/firewall-actions" "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/clusters/cluster/settings/health" + "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/clusters/cluster/settings/message" "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/clusters/cluster/settings/services" "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/clusters/cluster/settings/toa" "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/clusters/cluster/settings/waf" @@ -36,6 +37,12 @@ func init() { Prefix("/clusters/cluster/settings/dns"). GetPost("", new(dns.IndexAction)). + // 消息 + Prefix("/clusters/cluster/settings/message"). + GetPost("", new(message.IndexAction)). + Get("/selectReceiverPopup", new(message.SelectReceiverPopupAction)). + Post("/selectedReceivers", new(message.SelectedReceiversAction)). + // TOA Prefix("/clusters/cluster/settings/toa"). GetPost("", new(toa.IndexAction)). diff --git a/internal/web/actions/default/clusters/cluster/settings/message/index.go b/internal/web/actions/default/clusters/cluster/settings/message/index.go new file mode 100644 index 00000000..054744ac --- /dev/null +++ b/internal/web/actions/default/clusters/cluster/settings/message/index.go @@ -0,0 +1,75 @@ +package message + +import ( + "encoding/json" + "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils" + "github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb" + "github.com/iwind/TeaGo/actions" + "github.com/iwind/TeaGo/maps" +) + +type IndexAction struct { + actionutils.ParentAction +} + +func (this *IndexAction) Init() { + this.Nav("", "setting", "") + this.SecondMenu("message") +} + +func (this *IndexAction) RunGet(params struct{}) { + this.Show() +} + +func (this *IndexAction) RunPost(params struct { + ClusterId int64 + ReceiversJSON []byte + + Must *actions.Must + CSRF *actionutils.CSRF +}) { + defer this.CreateLogInfo("修改集群 %d 消息接收人", params.ClusterId) + + receiverMaps := []maps.Map{} + if len(params.ReceiversJSON) > 0 { + err := json.Unmarshal(params.ReceiversJSON, &receiverMaps) + if err != nil { + this.ErrorPage(err) + return + } + } + pbReceiverOptions := &pb.UpdateMessageReceiversRequest_RecipientOptions{} + for _, receiverMap := range receiverMaps { + recipientId := int64(0) + groupId := int64(0) + receiverType := receiverMap.GetString("type") + switch receiverType { + case "recipient": + recipientId = receiverMap.GetInt64("id") + case "group": + groupId = receiverMap.GetInt64("id") + default: + continue + } + pbReceiverOptions.RecipientOptions = append(pbReceiverOptions.RecipientOptions, &pb.UpdateMessageReceiversRequest_RecipientOption{ + MessageRecipientId: recipientId, + MessageRecipientGroupId: groupId, + }) + } + + _, err := this.RPC().MessageReceiverRPC().UpdateMessageReceivers(this.AdminContext(), &pb.UpdateMessageReceiversRequest{ + NodeClusterId: params.ClusterId, + NodeId: 0, + ServerId: 0, + ParamsJSON: nil, + RecipientOptions: map[string]*pb.UpdateMessageReceiversRequest_RecipientOptions{ + "*": pbReceiverOptions, + }, + }) + if err != nil { + this.ErrorPage(err) + return + } + + this.Success() +} diff --git a/internal/web/actions/default/clusters/cluster/settings/message/selectReceiverPopup.go b/internal/web/actions/default/clusters/cluster/settings/message/selectReceiverPopup.go new file mode 100644 index 00000000..43c2a70a --- /dev/null +++ b/internal/web/actions/default/clusters/cluster/settings/message/selectReceiverPopup.go @@ -0,0 +1,77 @@ +package message + +import ( + "github.com/TeaOSLab/EdgeAdmin/internal/utils" + "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils" + "github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb" + "github.com/iwind/TeaGo/lists" + "github.com/iwind/TeaGo/maps" +) + +type SelectReceiverPopupAction struct { + actionutils.ParentAction +} + +func (this *SelectReceiverPopupAction) Init() { + this.Nav("", "", "") +} + +func (this *SelectReceiverPopupAction) RunGet(params struct { + RecipientIds string + GroupIds string +}) { + recipientIds := utils.SplitNumbers(params.RecipientIds) + groupIds := utils.SplitNumbers(params.GroupIds) + + // 所有接收人 + recipientsResp, err := this.RPC().MessageRecipientRPC().ListEnabledMessageRecipients(this.AdminContext(), &pb.ListEnabledMessageRecipientsRequest{ + AdminId: 0, + MediaType: "", + MessageRecipientGroupId: 0, + Keyword: "", + Offset: 0, + Size: 1000, // TODO 支持搜索 + }) + if err != nil { + this.ErrorPage(err) + return + } + recipientMaps := []maps.Map{} + for _, recipient := range recipientsResp.MessageRecipients { + if !recipient.IsOn { + continue + } + if lists.ContainsInt64(recipientIds, recipient.Id) { + continue + } + recipientMaps = append(recipientMaps, maps.Map{ + "id": recipient.Id, + "name": recipient.Admin.Fullname, + "instanceName": recipient.MessageMediaInstance.Name, + }) + } + this.Data["recipients"] = recipientMaps + + // 所有分组 + groupsResp, err := this.RPC().MessageRecipientGroupRPC().FindAllEnabledMessageRecipientGroups(this.AdminContext(), &pb.FindAllEnabledMessageRecipientGroupsRequest{}) + if err != nil { + this.ErrorPage(err) + return + } + groupMaps := []maps.Map{} + for _, group := range groupsResp.MessageRecipientGroups { + if !group.IsOn { + continue + } + if lists.ContainsInt64(groupIds, group.Id) { + continue + } + groupMaps = append(groupMaps, maps.Map{ + "id": group.Id, + "name": group.Name, + }) + } + this.Data["groups"] = groupMaps + + this.Show() +} diff --git a/internal/web/actions/default/clusters/cluster/settings/message/selectedReceivers.go b/internal/web/actions/default/clusters/cluster/settings/message/selectedReceivers.go new file mode 100644 index 00000000..6f14e004 --- /dev/null +++ b/internal/web/actions/default/clusters/cluster/settings/message/selectedReceivers.go @@ -0,0 +1,61 @@ +// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved. + +package message + +import ( + "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils" + "github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb" + "github.com/iwind/TeaGo/maps" +) + +type SelectedReceiversAction struct { + actionutils.ParentAction +} + +func (this *SelectedReceiversAction) Init() { + this.Nav("", "", "") +} + +func (this *SelectedReceiversAction) RunPost(params struct { + ClusterId int64 + NodeId int64 + ServerId int64 +}) { + receiversResp, err := this.RPC().MessageReceiverRPC().FindAllMessageReceivers(this.AdminContext(), &pb.FindAllMessageReceiversRequest{ + NodeClusterId: params.ClusterId, + NodeId: params.NodeId, + ServerId: params.ServerId, + }) + if err != nil { + this.ErrorPage(err) + return + } + receiverMaps := []maps.Map{} + for _, receiver := range receiversResp.MessageReceivers { + id := int64(0) + name := "" + receiverType := "" + subName := "" + if receiver.MessageRecipient != nil { + id = receiver.MessageRecipient.Id + name = receiver.MessageRecipient.Admin.Fullname + subName = receiver.MessageRecipient.MessageMediaInstance.Name + receiverType = "recipient" + } else if receiver.MessageRecipientGroup != nil { + id = receiver.MessageRecipientGroup.Id + name = receiver.MessageRecipientGroup.Name + receiverType = "group" + } else { + continue + } + receiverMaps = append(receiverMaps, maps.Map{ + "id": id, + "name": name, + "subName": subName, + "type": receiverType, + }) + } + this.Data["receivers"] = receiverMaps + + this.Success() +} diff --git a/internal/web/actions/default/clusters/clusterutils/cluster_helper.go b/internal/web/actions/default/clusters/clusterutils/cluster_helper.go index 8452ca5c..085d8a0d 100644 --- a/internal/web/actions/default/clusters/clusterutils/cluster_helper.go +++ b/internal/web/actions/default/clusters/clusterutils/cluster_helper.go @@ -115,6 +115,18 @@ func (this *ClusterHelper) createSettingMenu(cluster *pb.NodeCluster, selectedIt "isActive": selectedItem == "dns", "isOn": cluster.DnsDomainId > 0 || len(cluster.DnsName) > 0, }) + items = append(items, maps.Map{ + "name": "消息通知", + "url": "/clusters/cluster/settings/message?clusterId=" + clusterId, + "isActive": selectedItem == "message", + }) + + items = append(items, maps.Map{ + "name": "-", + "url": "", + "isActive": false, + }) + items = append(items, maps.Map{ "name": "系统服务", "url": "/clusters/cluster/settings/services?clusterId=" + clusterId, diff --git a/web/public/js/components/messages/message-receivers-box.js b/web/public/js/components/messages/message-receivers-box.js new file mode 100644 index 00000000..282a1611 --- /dev/null +++ b/web/public/js/components/messages/message-receivers-box.js @@ -0,0 +1,58 @@ +// 消息接收人设置 +Vue.component("message-receivers-box", { + props: ["v-node-cluster-id"], + mounted: function () { + let that = this + Tea.action("/clusters/cluster/settings/message/selectedReceivers") + .params({ + clusterId: this.clusterId + }) + .post() + .success(function (resp) { + that.receivers = resp.data.receivers + }) + }, + data: function () { + let clusterId = this.vNodeClusterId + if (clusterId == null) { + clusterId = 0 + } + return { + clusterId: clusterId, + receivers: [] + } + }, + methods: { + addReceiver: function () { + let that = this + let recipientIdStrings = [] + let groupIdStrings = [] + this.receivers.forEach(function (v) { + if (v.type == "recipient") { + recipientIdStrings.push(v.id.toString()) + } else if (v.type == "group") { + groupIdStrings.push(v.id.toString()) + } + }) + + teaweb.popup("/clusters/cluster/settings/message/selectReceiverPopup?recipientIds=" + recipientIdStrings.join(",") + "&groupIds=" + groupIdStrings.join(","), { + callback: function (resp) { + that.receivers.push(resp.data) + } + }) + }, + removeReceiver: function (index) { + this.receivers.$remove(index) + } + }, + template: `
` +}) \ No newline at end of file diff --git a/web/public/js/utils.js b/web/public/js/utils.js index 53b37910..d635463c 100644 --- a/web/public/js/utils.js +++ b/web/public/js/utils.js @@ -181,6 +181,11 @@ window.teaweb = { var hash = window.location.hash; return hash != null && hash.startsWith("#popup"); }, + closePopup: function () { + if (this.isPopup()) { + window.parent.Swal.close(); + } + }, Swal: function () { return this.isPopup() ? window.parent.Swal : window.Swal; }, diff --git a/web/views/@default/admins/recipients/instances/index.html b/web/views/@default/admins/recipients/instances/index.html index 709bd323..a7262213 100644 --- a/web/views/@default/admins/recipients/instances/index.html +++ b/web/views/@default/admins/recipients/instances/index.html @@ -10,6 +10,7 @@| 媒介名称 | 媒介类型 | 备注 | 状态 | @@ -17,6 +18,7 @@|
|---|---|---|---|---|
| {{instance.name}} | {{instance.media.name}} |
{{instance.description}}
diff --git a/web/views/@default/admins/recipients/logs/index.html b/web/views/@default/admins/recipients/logs/index.html
index 84568b78..f2f86be9 100644
--- a/web/views/@default/admins/recipients/logs/index.html
+++ b/web/views/@default/admins/recipients/logs/index.html
@@ -5,11 +5,11 @@
-
|