Skip to content

Commit

Permalink
fix failed to get notify detail due to msp_env scope type
Browse files Browse the repository at this point in the history
  • Loading branch information
chengjoey committed Mar 5, 2024
1 parent 5bd7dfa commit 44fbe5c
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
13 changes: 13 additions & 0 deletions apistructs/notify_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"crypto/hmac"
"crypto/sha256"
"encoding/base64"
"encoding/json"
"fmt"
"net/url"
"time"
Expand Down Expand Up @@ -132,6 +133,18 @@ type NotifyGroupDetail struct {
DingdingList []Target `json:"dingdingList"`
DingdingWorkNoticeList []Target `json:"dingdingWorknoticeList"`
WebHookList []string `json:"webhookList"`
Label string `json:"-"`
}

func (n *NotifyGroupDetail) GetScopeDetail() (scopeID, scopeType string) {
label := make(map[string]string)
err := json.Unmarshal([]byte(n.Label), &label)
if err != nil {
return
}
scopeID = label[MSPMemberScopeId]
scopeType = label[MSPMemberScope]
return
}

// CreateNotifyGroupRequest 创建通知组请求
Expand Down
1 change: 1 addition & 0 deletions internal/core/legacy/services/notify/notify_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ func (o *NotifyGroup) GetDetail(id int64, orgID int64) (*apistructs.NotifyGroupD
result.Targets = group.Targets
result.DingdingList = uniqueTargetList(result.DingdingList)
result.DingdingWorkNoticeList = uniqueTargetList(result.DingdingWorkNoticeList)
result.Label = group.Label
return result, nil
}

Expand Down
6 changes: 5 additions & 1 deletion internal/core/messenger/notifygroup/group.service.go
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,11 @@ func (n *notifyGroupService) GetNotifyGroupDetail(ctx context.Context, request *
return nil, errors.NewInternalServerError(err)
}
userIdStr := apis.GetUserID(ctx)
err = n.checkNotifyPermission(ctx, userIdStr, notifyGroup.ScopeType, notifyGroup.ScopeID, apistructs.GetAction)
scopeType, scopeID := notifyGroup.ScopeType, notifyGroup.ScopeID
if scopeType == apistructs.MSPScope {
scopeID, scopeType = notifyGroup.GetScopeDetail()
}
err = n.checkNotifyPermission(ctx, userIdStr, scopeType, scopeID, apistructs.GetAction)
if err != nil {
return nil, errors.NewPermissionError(apistructs.NotifyResource, apistructs.GetAction, err.Error())
}
Expand Down

0 comments on commit 44fbe5c

Please sign in to comment.