diff --git a/internal/web/actions/default/clusters/cluster/settings/message/index.go b/internal/web/actions/default/clusters/cluster/settings/message/index.go deleted file mode 100644 index 054744ac..00000000 --- a/internal/web/actions/default/clusters/cluster/settings/message/index.go +++ /dev/null @@ -1,75 +0,0 @@ -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 deleted file mode 100644 index 43c2a70a..00000000 --- a/internal/web/actions/default/clusters/cluster/settings/message/selectReceiverPopup.go +++ /dev/null @@ -1,77 +0,0 @@ -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 deleted file mode 100644 index b975b58f..00000000 --- a/internal/web/actions/default/clusters/cluster/settings/message/selectedReceivers.go +++ /dev/null @@ -1,61 +0,0 @@ -// 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().FindAllEnabledMessageReceivers(this.AdminContext(), &pb.FindAllEnabledMessageReceiversRequest{ - 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() -}