MM-25261: Add 'include_deleted' parameter to get all channels API req… (#14721)

* MM-25261: Add 'include_deleted' parameter to get all channels API request.

* MM-25261: Adds test for deleted channels.

* MM-25261: Switches to single liner.

* MM-25261: Adhere to beta config setting for viewing archived channels.

* MM-25261: Test fix.

Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
Этот коммит содержится в:
Martin Kraft
2020-06-19 16:53:37 -04:00
коммит произвёл GitHub
родитель d391fd6231
Коммит 6158e91308
4 изменённых файлов: 49 добавлений и 1 удалений

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

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

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

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

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

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

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

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