make cli team / channel delete operations also delete webhooks and slash commands (#7028)

Этот коммит содержится в:
Chris
2017-07-31 08:52:45 -07:00
коммит произвёл Harrison Healey
родитель 0f786a42d3
Коммит 72f61ab96a
10 изменённых файлов: 275 добавлений и 4 удалений

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

@@ -134,6 +134,24 @@ func (s SqlCommandStore) Delete(commandId string, time int64) StoreChannel {
return storeChannel
}
func (s SqlCommandStore) PermanentDeleteByTeam(teamId string) StoreChannel {
storeChannel := make(StoreChannel, 1)
go func() {
result := StoreResult{}
_, err := s.GetMaster().Exec("DELETE FROM Commands WHERE TeamId = :TeamId", map[string]interface{}{"TeamId": teamId})
if err != nil {
result.Err = model.NewLocAppError("SqlCommandStore.DeleteByTeam", "store.sql_command.save.delete_perm.app_error", nil, "id="+teamId+", err="+err.Error())
}
storeChannel <- result
close(storeChannel)
}()
return storeChannel
}
func (s SqlCommandStore) PermanentDeleteByUser(userId string) StoreChannel {
storeChannel := make(StoreChannel, 1)

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

@@ -111,6 +111,36 @@ func TestCommandStoreDelete(t *testing.T) {
}
}
func TestCommandStoreDeleteByTeam(t *testing.T) {
Setup()
o1 := &model.Command{}
o1.CreatorId = model.NewId()
o1.Method = model.COMMAND_METHOD_POST
o1.TeamId = model.NewId()
o1.URL = "http://nowhere.com/"
o1.Trigger = "trigger"
o1 = (<-store.Command().Save(o1)).Data.(*model.Command)
if r1 := <-store.Command().Get(o1.Id); r1.Err != nil {
t.Fatal(r1.Err)
} else {
if r1.Data.(*model.Command).CreateAt != o1.CreateAt {
t.Fatal("invalid returned command")
}
}
if r2 := <-store.Command().PermanentDeleteByTeam(o1.TeamId); r2.Err != nil {
t.Fatal(r2.Err)
}
if r3 := (<-store.Command().Get(o1.Id)); r3.Err == nil {
t.Log(r3.Data)
t.Fatal("Missing id should have failed")
}
}
func TestCommandStoreDeleteByUser(t *testing.T) {
Setup()

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

@@ -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)

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

@@ -157,7 +157,29 @@ func TestWebhookStoreDeleteIncoming(t *testing.T) {
t.Fatal(r2.Err)
}
ClearWebhookCaches()
if r3 := (<-store.Webhook().GetIncoming(o1.Id, true)); r3.Err == nil {
t.Log(r3.Data)
t.Fatal("Missing id should have failed")
}
}
func TestWebhookStoreDeleteIncomingByChannel(t *testing.T) {
Setup()
o1 := buildIncomingWebhook()
o1 = (<-store.Webhook().SaveIncoming(o1)).Data.(*model.IncomingWebhook)
if r1 := <-store.Webhook().GetIncoming(o1.Id, true); r1.Err != nil {
t.Fatal(r1.Err)
} else {
if r1.Data.(*model.IncomingWebhook).CreateAt != o1.CreateAt {
t.Fatal("invalid returned webhook")
}
}
if r2 := <-store.Webhook().PermanentDeleteIncomingByChannel(o1.ChannelId); r2.Err != nil {
t.Fatal(r2.Err)
}
if r3 := (<-store.Webhook().GetIncoming(o1.Id, true)); r3.Err == nil {
t.Log(r3.Data)
@@ -183,8 +205,6 @@ func TestWebhookStoreDeleteIncomingByUser(t *testing.T) {
t.Fatal(r2.Err)
}
ClearWebhookCaches()
if r3 := (<-store.Webhook().GetIncoming(o1.Id, true)); r3.Err == nil {
t.Log(r3.Data)
t.Fatal("Missing id should have failed")
@@ -380,6 +400,35 @@ func TestWebhookStoreDeleteOutgoing(t *testing.T) {
}
}
func TestWebhookStoreDeleteOutgoingByChannel(t *testing.T) {
Setup()
o1 := &model.OutgoingWebhook{}
o1.ChannelId = model.NewId()
o1.CreatorId = model.NewId()
o1.TeamId = model.NewId()
o1.CallbackURLs = []string{"http://nowhere.com/"}
o1 = (<-store.Webhook().SaveOutgoing(o1)).Data.(*model.OutgoingWebhook)
if r1 := <-store.Webhook().GetOutgoing(o1.Id); r1.Err != nil {
t.Fatal(r1.Err)
} else {
if r1.Data.(*model.OutgoingWebhook).CreateAt != o1.CreateAt {
t.Fatal("invalid returned webhook")
}
}
if r2 := <-store.Webhook().PermanentDeleteOutgoingByChannel(o1.ChannelId); r2.Err != nil {
t.Fatal(r2.Err)
}
if r3 := (<-store.Webhook().GetOutgoing(o1.Id)); r3.Err == nil {
t.Log(r3.Data)
t.Fatal("Missing id should have failed")
}
}
func TestWebhookStoreDeleteOutgoingByUser(t *testing.T) {
Setup()

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

@@ -296,6 +296,7 @@ type WebhookStore interface {
UpdateIncoming(webhook *model.IncomingWebhook) StoreChannel
GetIncomingByChannel(channelId string) StoreChannel
DeleteIncoming(webhookId string, time int64) StoreChannel
PermanentDeleteIncomingByChannel(channelId string) StoreChannel
PermanentDeleteIncomingByUser(userId string) StoreChannel
SaveOutgoing(webhook *model.OutgoingWebhook) StoreChannel
@@ -304,6 +305,7 @@ type WebhookStore interface {
GetOutgoingByChannel(channelId string, offset, limit int) StoreChannel
GetOutgoingByTeam(teamId string, offset, limit int) StoreChannel
DeleteOutgoing(webhookId string, time int64) StoreChannel
PermanentDeleteOutgoingByChannel(channelId string) StoreChannel
PermanentDeleteOutgoingByUser(userId string) StoreChannel
UpdateOutgoing(hook *model.OutgoingWebhook) StoreChannel
@@ -317,6 +319,7 @@ type CommandStore interface {
Get(id string) StoreChannel
GetByTeam(teamId string) StoreChannel
Delete(commandId string, time int64) StoreChannel
PermanentDeleteByTeam(teamId string) StoreChannel
PermanentDeleteByUser(userId string) StoreChannel
Update(hook *model.Command) StoreChannel
AnalyticsCommandCount(teamId string) StoreChannel