mirror of
https://github.com/songquanpeng/message-pusher.git
synced 2025-09-27 04:26:31 +08:00
fix: fix IsShared implementation
This commit is contained in:
@@ -152,6 +152,7 @@ func TokenStoreAddChannel(channel *model.Channel) {
|
|||||||
}
|
}
|
||||||
item := channel2item(channel)
|
item := channel2item(channel)
|
||||||
if item != nil {
|
if item != nil {
|
||||||
|
// Do not check IsShared here, cause its useless
|
||||||
TokenStoreAddItem(item)
|
TokenStoreAddItem(item)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -161,7 +162,7 @@ func TokenStoreRemoveChannel(channel *model.Channel) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
item := channel2item(channel)
|
item := channel2item(channel)
|
||||||
if item != nil {
|
if item != nil && !item.IsShared() {
|
||||||
TokenStoreRemoveItem(item)
|
TokenStoreRemoveItem(item)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -170,6 +171,7 @@ func TokenStoreUpdateChannel(newChannel *model.Channel, oldChannel *model.Channe
|
|||||||
if oldChannel.Type != model.TypeWeChatTestAccount && oldChannel.Type != model.TypeWeChatCorpAccount {
|
if oldChannel.Type != model.TypeWeChatTestAccount && oldChannel.Type != model.TypeWeChatCorpAccount {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
// Why so complicated? Because the given channel maybe incomplete.
|
||||||
if oldChannel.Type == model.TypeWeChatTestAccount {
|
if oldChannel.Type == model.TypeWeChatTestAccount {
|
||||||
// Only keep changed parts
|
// Only keep changed parts
|
||||||
if newChannel.AppId == oldChannel.AppId {
|
if newChannel.AppId == oldChannel.AppId {
|
||||||
|
@@ -32,8 +32,9 @@ func (i *WeChatCorpAccountTokenStoreItem) Key() string {
|
|||||||
|
|
||||||
func (i *WeChatCorpAccountTokenStoreItem) IsShared() bool {
|
func (i *WeChatCorpAccountTokenStoreItem) IsShared() bool {
|
||||||
appId := fmt.Sprintf("%s|%s", i.CorpId, i.AgentId)
|
appId := fmt.Sprintf("%s|%s", i.CorpId, i.AgentId)
|
||||||
return model.DB.Where("type = ? and app_id = ? and secret = ?",
|
var count int64 = 0
|
||||||
model.TypeWeChatCorpAccount, appId, i.AgentSecret).Find(&model.Channel{}).RowsAffected != 1
|
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 {
|
func (i *WeChatCorpAccountTokenStoreItem) IsFilled() bool {
|
||||||
|
@@ -29,8 +29,9 @@ func (i *WeChatTestAccountTokenStoreItem) Key() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (i *WeChatTestAccountTokenStoreItem) IsShared() bool {
|
func (i *WeChatTestAccountTokenStoreItem) IsShared() bool {
|
||||||
return model.DB.Where("type = ? and app_id = ? and secret = ?",
|
var count int64 = 0
|
||||||
model.TypeWeChatTestAccount, i.AppID, i.AppSecret).Find(&model.Channel{}).RowsAffected != 1
|
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 {
|
func (i *WeChatTestAccountTokenStoreItem) IsFilled() bool {
|
||||||
|
@@ -604,6 +604,7 @@ func ManageUser(c *gin.Context) {
|
|||||||
})
|
})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
channel.TokenStoreRemoveUser(&user)
|
||||||
case "promote":
|
case "promote":
|
||||||
if myRole != common.RoleRootUser {
|
if myRole != common.RoleRootUser {
|
||||||
c.JSON(http.StatusOK, gin.H{
|
c.JSON(http.StatusOK, gin.H{
|
||||||
|
Reference in New Issue
Block a user