MM-16499: Adds ability to retrieve channels with total count f… (#11375)
* MM-16499: Adds ability to retrieve channels with total count for pagination. * MM-16499: Switches to custom package name for squirrel.
Этот коммит содержится в:
коммит произвёл
Eli Yukelzon
родитель
3993cac4ed
Коммит
d1b1b319cf
@@ -534,7 +534,23 @@ func getAllChannels(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
w.Write([]byte(channels.ToJson()))
|
||||
var payload []byte
|
||||
if c.Params.IncludeTotalCount {
|
||||
totalCount, err := c.App.GetAllChannelsCount(opts)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
}
|
||||
cwc := &model.ChannelsWithCount{
|
||||
Channels: channels,
|
||||
TotalCount: totalCount,
|
||||
}
|
||||
payload = cwc.ToJson()
|
||||
} else {
|
||||
payload = []byte(channels.ToJson())
|
||||
}
|
||||
|
||||
w.Write(payload)
|
||||
}
|
||||
|
||||
func getPublicChannelsForTeam(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
@@ -832,6 +832,37 @@ func TestGetAllChannels(t *testing.T) {
|
||||
CheckForbiddenStatus(t, resp)
|
||||
}
|
||||
|
||||
func TestGetAllChannelsWithCount(t *testing.T) {
|
||||
th := Setup().InitBasic()
|
||||
defer th.TearDown()
|
||||
Client := th.Client
|
||||
|
||||
channels, total, resp := th.SystemAdminClient.GetAllChannelsWithCount(0, 20, "")
|
||||
CheckNoError(t, resp)
|
||||
|
||||
// At least, all the not-deleted channels created during the InitBasic
|
||||
require.True(t, len(*channels) >= 3)
|
||||
for _, c := range *channels {
|
||||
require.NotEqual(t, c.TeamId, "")
|
||||
}
|
||||
require.Equal(t, int64(5), total)
|
||||
|
||||
channels, _, resp = th.SystemAdminClient.GetAllChannelsWithCount(0, 10, "")
|
||||
CheckNoError(t, resp)
|
||||
require.True(t, len(*channels) >= 3)
|
||||
|
||||
channels, _, resp = th.SystemAdminClient.GetAllChannelsWithCount(1, 1, "")
|
||||
CheckNoError(t, resp)
|
||||
require.Len(t, *channels, 1)
|
||||
|
||||
channels, _, resp = th.SystemAdminClient.GetAllChannelsWithCount(10000, 10000, "")
|
||||
CheckNoError(t, resp)
|
||||
require.Len(t, *channels, 0)
|
||||
|
||||
_, _, resp = Client.GetAllChannelsWithCount(0, 20, "")
|
||||
CheckForbiddenStatus(t, resp)
|
||||
}
|
||||
|
||||
func TestSearchChannels(t *testing.T) {
|
||||
th := Setup().InitBasic()
|
||||
defer th.TearDown()
|
||||
|
||||
Ссылка в новой задаче
Block a user