Delete webhooks when the associated channel gets deleted

Этот коммит содержится в:
JoramWilander
2015-10-22 14:27:47 -04:00
родитель 46f448899b
Коммит a431ba2c22
3 изменённых файлов: 49 добавлений и 0 удалений

Просмотреть файл

@@ -503,6 +503,8 @@ func deleteChannel(c *Context, w http.ResponseWriter, r *http.Request) {
sc := Srv.Store.Channel().Get(id)
scm := Srv.Store.Channel().GetMember(id, c.Session.UserId)
uc := Srv.Store.User().Get(c.Session.UserId)
ihc := Srv.Store.Webhook().GetIncomingByChannel(id)
ohc := Srv.Store.Webhook().GetOutgoingByChannel(id)
if cresult := <-sc; cresult.Err != nil {
c.Err = cresult.Err
@@ -513,10 +515,18 @@ func deleteChannel(c *Context, w http.ResponseWriter, r *http.Request) {
} else if scmresult := <-scm; scmresult.Err != nil {
c.Err = scmresult.Err
return
} else if ihcresult := <-ihc; ihcresult.Err != nil {
c.Err = ihcresult.Err
return
} else if ohcresult := <-ohc; ohcresult.Err != nil {
c.Err = ohcresult.Err
return
} else {
channel := cresult.Data.(*model.Channel)
user := uresult.Data.(*model.User)
channelMember := scmresult.Data.(model.ChannelMember)
incomingHooks := ihcresult.Data.([]*model.IncomingWebhook)
outgoingHooks := ohcresult.Data.([]*model.OutgoingWebhook)
if !c.HasPermissionsToTeam(channel.TeamId, "deleteChannel") {
return
@@ -540,6 +550,23 @@ func deleteChannel(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
now := model.GetMillis()
for _, hook := range incomingHooks {
go func() {
if result := <-Srv.Store.Webhook().DeleteIncoming(hook.Id, now); result.Err != nil {
l4g.Error("Encountered error deleting incoming webhook, id=" + hook.Id)
}
}()
}
for _, hook := range outgoingHooks {
go func() {
if result := <-Srv.Store.Webhook().DeleteOutgoing(hook.Id, now); result.Err != nil {
l4g.Error("Encountered error deleting outgoing webhook, id=" + hook.Id)
}
}()
}
if dresult := <-Srv.Store.Channel().Delete(channel.Id, model.GetMillis()); dresult.Err != nil {
c.Err = dresult.Err
return

Просмотреть файл

@@ -137,6 +137,27 @@ func (s SqlWebhookStore) GetIncomingByUser(userId string) StoreChannel {
return storeChannel
}
func (s SqlWebhookStore) GetIncomingByChannel(channelId string) StoreChannel {
storeChannel := make(StoreChannel)
go func() {
result := StoreResult{}
var webhooks []*model.IncomingWebhook
if _, err := s.GetReplica().Select(&webhooks, "SELECT * FROM IncomingWebhooks WHERE ChannelId = :ChannelId AND DeleteAt = 0", map[string]interface{}{"ChannelId": channelId}); err != nil {
result.Err = model.NewAppError("SqlWebhookStore.GetIncomingByChannel", "We couldn't get the webhooks", "channelId="+channelId+", err="+err.Error())
}
result.Data = webhooks
storeChannel <- result
close(storeChannel)
}()
return storeChannel
}
func (s SqlWebhookStore) SaveOutgoing(webhook *model.OutgoingWebhook) StoreChannel {
storeChannel := make(StoreChannel)

Просмотреть файл

@@ -149,6 +149,7 @@ type WebhookStore interface {
SaveIncoming(webhook *model.IncomingWebhook) StoreChannel
GetIncoming(id string) StoreChannel
GetIncomingByUser(userId string) StoreChannel
GetIncomingByChannel(channelId string) StoreChannel
DeleteIncoming(webhookId string, time int64) StoreChannel
SaveOutgoing(webhook *model.OutgoingWebhook) StoreChannel
GetOutgoing(id string) StoreChannel