From 0a20e8d3269515e2d44a0bcad0a2408f62245814 Mon Sep 17 00:00:00 2001 From: Robin Naundorf Date: Mon, 15 May 2017 22:12:30 +0200 Subject: PLT-6019: Add APIv4 Endpoint for restoring Channels (#6263) --- store/sql_channel_store.go | 4 ++++ store/sql_channel_store_test.go | 28 ++++++++++++++++++++++++++++ store/store.go | 1 + 3 files changed, 33 insertions(+) (limited to 'store') diff --git a/store/sql_channel_store.go b/store/sql_channel_store.go index f3619c03a..c9b6d89b8 100644 --- a/store/sql_channel_store.go +++ b/store/sql_channel_store.go @@ -440,6 +440,10 @@ func (s SqlChannelStore) Delete(channelId string, time int64) StoreChannel { return s.SetDeleteAt(channelId, time, time) } +func (s SqlChannelStore) Restore(channelId string, time int64) StoreChannel { + return s.SetDeleteAt(channelId, 0, time) +} + func (s SqlChannelStore) SetDeleteAt(channelId string, deleteAt int64, updateAt int64) StoreChannel { storeChannel := make(StoreChannel, 1) diff --git a/store/sql_channel_store_test.go b/store/sql_channel_store_test.go index 55a263037..fc98f3f4e 100644 --- a/store/sql_channel_store_test.go +++ b/store/sql_channel_store_test.go @@ -364,6 +364,34 @@ func TestChannelStoreGetForPost(t *testing.T) { } } +func TestSqlChannelStoreRestore(t *testing.T) { + Setup() + + o1 := model.Channel{} + o1.TeamId = model.NewId() + o1.DisplayName = "Channel1" + o1.Name = "a" + model.NewId() + "b" + o1.Type = model.CHANNEL_OPEN + Must(store.Channel().Save(&o1)) + + if r := <-store.Channel().Delete(o1.Id, model.GetMillis()); r.Err != nil { + t.Fatal(r.Err) + } + + if r := <-store.Channel().Get(o1.Id, false); r.Data.(*model.Channel).DeleteAt == 0 { + t.Fatal("should have been deleted") + } + + if r := <-store.Channel().Restore(o1.Id, model.GetMillis()); r.Err != nil { + t.Fatal(r.Err) + } + + if r := <-store.Channel().Get(o1.Id, false); r.Data.(*model.Channel).DeleteAt != 0 { + t.Fatal("should have been restored") + } + +} + func TestChannelStoreDelete(t *testing.T) { Setup() diff --git a/store/store.go b/store/store.go index bb1b8f197..9916bfcd7 100644 --- a/store/store.go +++ b/store/store.go @@ -97,6 +97,7 @@ type ChannelStore interface { InvalidateChannelByName(teamId, name string) GetFromMaster(id string) StoreChannel Delete(channelId string, time int64) StoreChannel + Restore(channelId string, time int64) StoreChannel SetDeleteAt(channelId string, deleteAt int64, updateAt int64) StoreChannel PermanentDeleteByTeam(teamId string) StoreChannel PermanentDelete(channelId string) StoreChannel -- cgit v1.2.3-1-g7c22