From 72f61ab96aabf65c162c8d94b5b843b5108ee1a9 Mon Sep 17 00:00:00 2001 From: Chris Date: Mon, 31 Jul 2017 08:52:45 -0700 Subject: make cli team / channel delete operations also delete webhooks and slash commands (#7028) --- store/sql_webhook_store.go | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) (limited to 'store/sql_webhook_store.go') diff --git a/store/sql_webhook_store.go b/store/sql_webhook_store.go index d59d7e03a..56c1b1643 100644 --- a/store/sql_webhook_store.go +++ b/store/sql_webhook_store.go @@ -186,6 +186,8 @@ func (s SqlWebhookStore) DeleteIncoming(webhookId string, time int64) StoreChann result.Err = model.NewLocAppError("SqlWebhookStore.DeleteIncoming", "store.sql_webhooks.delete_incoming.app_error", nil, "id="+webhookId+", err="+err.Error()) } + s.InvalidateWebhookCache(webhookId) + storeChannel <- result close(storeChannel) }() @@ -204,6 +206,28 @@ func (s SqlWebhookStore) PermanentDeleteIncomingByUser(userId string) StoreChann result.Err = model.NewLocAppError("SqlWebhookStore.DeleteIncomingByUser", "store.sql_webhooks.permanent_delete_incoming_by_user.app_error", nil, "id="+userId+", err="+err.Error()) } + ClearWebhookCaches() + + storeChannel <- result + close(storeChannel) + }() + + return storeChannel +} + +func (s SqlWebhookStore) PermanentDeleteIncomingByChannel(channelId string) StoreChannel { + storeChannel := make(StoreChannel, 1) + + go func() { + result := StoreResult{} + + _, err := s.GetMaster().Exec("DELETE FROM IncomingWebhooks WHERE ChannelId = :ChannelId", map[string]interface{}{"ChannelId": channelId}) + if err != nil { + result.Err = model.NewLocAppError("SqlWebhookStore.DeleteIncomingByChannel", "store.sql_webhooks.permanent_delete_incoming_by_channel.app_error", nil, "id="+channelId+", err="+err.Error()) + } + + ClearWebhookCaches() + storeChannel <- result close(storeChannel) }() @@ -442,6 +466,26 @@ func (s SqlWebhookStore) PermanentDeleteOutgoingByUser(userId string) StoreChann return storeChannel } +func (s SqlWebhookStore) PermanentDeleteOutgoingByChannel(channelId string) StoreChannel { + storeChannel := make(StoreChannel, 1) + + go func() { + result := StoreResult{} + + _, err := s.GetMaster().Exec("DELETE FROM OutgoingWebhooks WHERE ChannelId = :ChannelId", map[string]interface{}{"ChannelId": channelId}) + if err != nil { + result.Err = model.NewLocAppError("SqlWebhookStore.DeleteOutgoingByChannel", "store.sql_webhooks.permanent_delete_outgoing_by_channel.app_error", nil, "id="+channelId+", err="+err.Error()) + } + + ClearWebhookCaches() + + storeChannel <- result + close(storeChannel) + }() + + return storeChannel +} + func (s SqlWebhookStore) UpdateOutgoing(hook *model.OutgoingWebhook) StoreChannel { storeChannel := make(StoreChannel, 1) -- cgit v1.2.3-1-g7c22