From a431ba2c22918412d90d00c37fb89f6841f47eb8 Mon Sep 17 00:00:00 2001 From: JoramWilander Date: Thu, 22 Oct 2015 14:27:47 -0400 Subject: Delete webhooks when the associated channel gets deleted --- store/sql_webhook_store.go | 21 +++++++++++++++++++++ store/store.go | 1 + 2 files changed, 22 insertions(+) (limited to 'store') diff --git a/store/sql_webhook_store.go b/store/sql_webhook_store.go index 1910984f0..c758e2339 100644 --- a/store/sql_webhook_store.go +++ b/store/sql_webhook_store.go @@ -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) diff --git a/store/store.go b/store/store.go index 27731cee1..7259556e7 100644 --- a/store/store.go +++ b/store/store.go @@ -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 -- cgit v1.2.3-1-g7c22