Add API Endpoint for deleted Channels (#5889)
Этот коммит содержится в:
коммит произвёл
Joram Wilander
родитель
530814b8c9
Коммит
5efcd2d9d3
@@ -812,6 +812,31 @@ func (s SqlChannelStore) GetDeletedByName(teamId string, name string) StoreChann
|
||||
return storeChannel
|
||||
}
|
||||
|
||||
func (s SqlChannelStore) GetDeleted(teamId string, offset int, limit int) StoreChannel {
|
||||
storeChannel := make(StoreChannel, 1)
|
||||
|
||||
go func() {
|
||||
result := StoreResult{}
|
||||
|
||||
channels := &model.ChannelList{}
|
||||
|
||||
if _, err := s.GetReplica().Select(channels, "SELECT * FROM Channels WHERE (TeamId = :TeamId OR TeamId = '') AND DeleteAt != 0 ORDER BY DisplayName LIMIT :Limit OFFSET :Offset", map[string]interface{}{"TeamId": teamId, "Limit": limit, "Offset": offset}); err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
result.Err = model.NewLocAppError("SqlChannelStore.GetDeleted", "store.sql_channel.get_deleted.missing.app_error", nil, "teamId="+teamId+", "+err.Error())
|
||||
} else {
|
||||
result.Err = model.NewLocAppError("SqlChannelStore.GetDeleted", "store.sql_channel.get_deleted.existing.app_error", nil, "teamId="+teamId+", "+err.Error())
|
||||
}
|
||||
} else {
|
||||
result.Data = channels
|
||||
}
|
||||
|
||||
storeChannel <- result
|
||||
close(storeChannel)
|
||||
}()
|
||||
|
||||
return storeChannel
|
||||
}
|
||||
|
||||
func (s SqlChannelStore) SaveMember(member *model.ChannelMember) StoreChannel {
|
||||
storeChannel := make(StoreChannel, 1)
|
||||
|
||||
|
||||
@@ -512,6 +512,88 @@ func TestChannelStoreGetDeletedByName(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestChannelStoreGetDeleted(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
|
||||
o1.DeleteAt = model.GetMillis()
|
||||
Must(store.Channel().Save(&o1))
|
||||
|
||||
cresult := <-store.Channel().GetDeleted(o1.TeamId, 0, 100)
|
||||
if cresult.Err != nil {
|
||||
t.Fatal(cresult.Err)
|
||||
}
|
||||
list := cresult.Data.(*model.ChannelList)
|
||||
|
||||
if len(*list) != 1 {
|
||||
t.Fatal("wrong list")
|
||||
}
|
||||
|
||||
if (*list)[0].Name != o1.Name {
|
||||
t.Fatal("missing channel")
|
||||
}
|
||||
|
||||
o2 := model.Channel{}
|
||||
o2.TeamId = o1.TeamId
|
||||
o2.DisplayName = "Channel2"
|
||||
o2.Name = "a" + model.NewId() + "b"
|
||||
o2.Type = model.CHANNEL_OPEN
|
||||
Must(store.Channel().Save(&o2))
|
||||
|
||||
cresult = <-store.Channel().GetDeleted(o1.TeamId, 0, 100)
|
||||
if cresult.Err != nil {
|
||||
t.Fatal(cresult.Err)
|
||||
}
|
||||
list = cresult.Data.(*model.ChannelList)
|
||||
|
||||
if len(*list) != 1 {
|
||||
t.Fatal("wrong list")
|
||||
}
|
||||
|
||||
o3 := model.Channel{}
|
||||
o3.TeamId = o1.TeamId
|
||||
o3.DisplayName = "Channel3"
|
||||
o3.Name = "a" + model.NewId() + "b"
|
||||
o3.Type = model.CHANNEL_OPEN
|
||||
o3.DeleteAt = model.GetMillis()
|
||||
Must(store.Channel().Save(&o3))
|
||||
|
||||
cresult = <-store.Channel().GetDeleted(o1.TeamId, 0, 100)
|
||||
if cresult.Err != nil {
|
||||
t.Fatal(cresult.Err)
|
||||
}
|
||||
list = cresult.Data.(*model.ChannelList)
|
||||
|
||||
if len(*list) != 2 {
|
||||
t.Fatal("wrong list length")
|
||||
}
|
||||
|
||||
cresult = <-store.Channel().GetDeleted(o1.TeamId, 0, 1)
|
||||
if cresult.Err != nil {
|
||||
t.Fatal(cresult.Err)
|
||||
}
|
||||
list = cresult.Data.(*model.ChannelList)
|
||||
|
||||
if len(*list) != 1 {
|
||||
t.Fatal("wrong list length")
|
||||
}
|
||||
|
||||
cresult = <-store.Channel().GetDeleted(o1.TeamId, 1, 1)
|
||||
if cresult.Err != nil {
|
||||
t.Fatal(cresult.Err)
|
||||
}
|
||||
list = cresult.Data.(*model.ChannelList)
|
||||
|
||||
if len(*list) != 1 {
|
||||
t.Fatal("wrong list length")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func TestChannelMemberStore(t *testing.T) {
|
||||
Setup()
|
||||
|
||||
|
||||
@@ -103,6 +103,7 @@ type ChannelStore interface {
|
||||
GetByName(team_id string, name string, allowFromCache bool) StoreChannel
|
||||
GetByNameIncludeDeleted(team_id string, name string, allowFromCache bool) StoreChannel
|
||||
GetDeletedByName(team_id string, name string) StoreChannel
|
||||
GetDeleted(team_id string, offset int, limit int) StoreChannel
|
||||
GetChannels(teamId string, userId string) StoreChannel
|
||||
GetMoreChannels(teamId string, userId string, offset int, limit int) StoreChannel
|
||||
GetPublicChannelsForTeam(teamId string, offset int, limit int) StoreChannel
|
||||
|
||||
Ссылка в новой задаче
Block a user