Skip to content

Commit

Permalink
fix: fix IsShared implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
songquanpeng committed May 6, 2023
1 parent 3e51538 commit 581d9d6
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 5 deletions.
4 changes: 3 additions & 1 deletion channel/token-store.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ func TokenStoreAddChannel(channel *model.Channel) {
}
item := channel2item(channel)
if item != nil {
// Do not check IsShared here, cause its useless
TokenStoreAddItem(item)
}
}
Expand All @@ -161,7 +162,7 @@ func TokenStoreRemoveChannel(channel *model.Channel) {
return
}
item := channel2item(channel)
if item != nil {
if item != nil && !item.IsShared() {
TokenStoreRemoveItem(item)
}
}
Expand All @@ -170,6 +171,7 @@ func TokenStoreUpdateChannel(newChannel *model.Channel, oldChannel *model.Channe
if oldChannel.Type != model.TypeWeChatTestAccount && oldChannel.Type != model.TypeWeChatCorpAccount {
return
}
// Why so complicated? Because the given channel maybe incomplete.
if oldChannel.Type == model.TypeWeChatTestAccount {
// Only keep changed parts
if newChannel.AppId == oldChannel.AppId {
Expand Down
5 changes: 3 additions & 2 deletions channel/wechat-corp-account.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@ func (i *WeChatCorpAccountTokenStoreItem) Key() string {

func (i *WeChatCorpAccountTokenStoreItem) IsShared() bool {
appId := fmt.Sprintf("%s|%s", i.CorpId, i.AgentId)
return model.DB.Where("type = ? and app_id = ? and secret = ?",
model.TypeWeChatCorpAccount, appId, i.AgentSecret).Find(&model.Channel{}).RowsAffected != 1
var count int64 = 0
model.DB.Model(&model.Channel{}).Where("type = ? and app_id = ? and secret = ?", model.TypeWeChatCorpAccount, appId, i.AgentSecret).Count(&count)
return count > 1
}

func (i *WeChatCorpAccountTokenStoreItem) IsFilled() bool {
Expand Down
5 changes: 3 additions & 2 deletions channel/wechat-test-account.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ func (i *WeChatTestAccountTokenStoreItem) Key() string {
}

func (i *WeChatTestAccountTokenStoreItem) IsShared() bool {
return model.DB.Where("type = ? and app_id = ? and secret = ?",
model.TypeWeChatTestAccount, i.AppID, i.AppSecret).Find(&model.Channel{}).RowsAffected != 1
var count int64 = 0
model.DB.Model(&model.Channel{}).Where("type = ? and app_id = ? and secret = ?", model.TypeWeChatTestAccount, i.AppID, i.AppSecret).Count(&count)
return count > 1
}

func (i *WeChatTestAccountTokenStoreItem) IsFilled() bool {
Expand Down
1 change: 1 addition & 0 deletions controller/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -604,6 +604,7 @@ func ManageUser(c *gin.Context) {
})
return
}
channel.TokenStoreRemoveUser(&user)
case "promote":
if myRole != common.RoleRootUser {
c.JSON(http.StatusOK, gin.H{
Expand Down

0 comments on commit 581d9d6

Please sign in to comment.