diff --git a/api4/channel.go b/api4/channel.go index 4b7810daeb..319ba0d73c 100644 --- a/api4/channel.go +++ b/api4/channel.go @@ -687,6 +687,7 @@ func getAllChannels(c *Context, w http.ResponseWriter, r *http.Request) { opts := model.ChannelSearchOpts{ NotAssociatedToGroup: c.Params.NotAssociatedToGroup, ExcludeDefaultChannels: c.Params.ExcludeDefaultChannels, + IncludeDeleted: c.Params.IncludeDeleted, } channels, err := c.App.GetAllChannels(c.Params.Page, c.Params.PerPage, opts) diff --git a/api4/channel_test.go b/api4/channel_test.go index b52a06d13f..98ed91bbce 100644 --- a/api4/channel_test.go +++ b/api4/channel_test.go @@ -919,6 +919,15 @@ func TestGetAllChannels(t *testing.T) { defer th.TearDown() Client := th.Client + var originalConfigVal bool + th.App.UpdateConfig(func(cfg *model.Config) { + originalConfigVal = *cfg.TeamSettings.ExperimentalViewArchivedChannels + *cfg.TeamSettings.ExperimentalViewArchivedChannels = true + }) + defer th.App.UpdateConfig(func(cfg *model.Config) { + *cfg.TeamSettings.ExperimentalViewArchivedChannels = originalConfigVal + }) + th.TestForSystemAdminAndLocal(t, func(t *testing.T, client *model.Client4) { channels, resp := client.GetAllChannels(0, 20, "") CheckNoError(t, resp) @@ -940,6 +949,34 @@ func TestGetAllChannels(t *testing.T) { channels, resp = client.GetAllChannels(10000, 10000, "") CheckNoError(t, resp) require.Empty(t, *channels) + + channels, resp = client.GetAllChannels(0, 10000, "") + require.Nil(t, resp.Error) + beforeCount := len(*channels) + + firstChannel := (*channels)[0].Channel + + ok, resp := client.DeleteChannel(firstChannel.Id) + require.Nil(t, resp.Error) + require.True(t, ok) + + channels, resp = client.GetAllChannels(0, 10000, "") + var ids []string + for _, item := range *channels { + ids = append(ids, item.Channel.Id) + } + require.Nil(t, resp.Error) + require.Len(t, *channels, beforeCount-1) + require.NotContains(t, ids, firstChannel.Id) + + channels, resp = client.GetAllChannelsIncludeDeleted(0, 10000, "") + ids = []string{} + for _, item := range *channels { + ids = append(ids, item.Channel.Id) + } + require.Nil(t, resp.Error) + require.True(t, len(*channels) > beforeCount) + require.Contains(t, ids, firstChannel.Id) }) _, resp := Client.GetAllChannels(0, 20, "") diff --git a/app/channel.go b/app/channel.go index 17d089a945..90f9209cfe 100644 --- a/app/channel.go +++ b/app/channel.go @@ -1570,6 +1570,7 @@ func (a *App) GetChannelsForUser(teamId string, userId string, includeDeleted bo } func (a *App) GetAllChannels(page, perPage int, opts model.ChannelSearchOpts) (*model.ChannelListWithTeamData, *model.AppError) { + opts.IncludeDeleted = *a.Config().TeamSettings.ExperimentalViewArchivedChannels && opts.IncludeDeleted if opts.ExcludeDefaultChannels { opts.ExcludeChannelNames = a.DefaultChannelNames() } diff --git a/model/client4.go b/model/client4.go index 153e00efca..127a227d27 100644 --- a/model/client4.go +++ b/model/client4.go @@ -2201,7 +2201,16 @@ func (c *Client4) RemoveTeamIcon(teamId string) (bool, *Response) { // GetAllChannels get all the channels. Must be a system administrator. func (c *Client4) GetAllChannels(page int, perPage int, etag string) (*ChannelListWithTeamData, *Response) { - query := fmt.Sprintf("?page=%v&per_page=%v", page, perPage) + return c.getAllChannels(page, perPage, etag, false) +} + +// GetAllChannelsIncludeDeleted get all the channels. Must be a system administrator. +func (c *Client4) GetAllChannelsIncludeDeleted(page int, perPage int, etag string) (*ChannelListWithTeamData, *Response) { + return c.getAllChannels(page, perPage, etag, true) +} + +func (c *Client4) getAllChannels(page int, perPage int, etag string, includeDeleted bool) (*ChannelListWithTeamData, *Response) { + query := fmt.Sprintf("?page=%v&per_page=%v&include_deleted=%v", page, perPage, includeDeleted) r, err := c.DoApiGet(c.GetChannelsRoute()+query, etag) if err != nil { return nil, BuildErrorResponse(r, err)