MM-24692: Add a since parameter to getGroups api (#14444)
* add a since parameter to getGroups api * update for lint error * when using since, return deleted groups as well. * update flaky test, groups have same create time Co-authored-by: mattermod <mattermod@users.noreply.github.com>
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
1031e27fd8
Коммит
80c846412d
@@ -8,6 +8,7 @@ import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/mattermost/mattermost-server/v5/audit"
|
||||
@@ -730,6 +731,16 @@ func getGroups(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
opts.NotAssociatedToChannel = channelID
|
||||
}
|
||||
|
||||
sinceString := r.URL.Query().Get("since")
|
||||
if len(sinceString) > 0 {
|
||||
since, parseError := strconv.ParseInt(sinceString, 10, 64)
|
||||
if parseError != nil {
|
||||
c.SetInvalidParam("since")
|
||||
return
|
||||
}
|
||||
opts.Since = since
|
||||
}
|
||||
|
||||
groups, err := c.App.GetGroups(c.Params.Page, c.Params.PerPage, opts)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
|
||||
@@ -851,6 +851,8 @@ func TestGetGroups(t *testing.T) {
|
||||
th := Setup(t).InitBasic()
|
||||
defer th.TearDown()
|
||||
|
||||
// make sure "createdDate" for next group is after one created in InitBasic()
|
||||
time.Sleep(2 * time.Millisecond)
|
||||
id := model.NewId()
|
||||
group, err := th.App.CreateGroup(&model.Group{
|
||||
DisplayName: "dn-foo_" + id,
|
||||
@@ -860,6 +862,7 @@ func TestGetGroups(t *testing.T) {
|
||||
RemoteId: model.NewId(),
|
||||
})
|
||||
assert.Nil(t, err)
|
||||
start := group.UpdateAt - 1
|
||||
|
||||
opts := model.GroupSearchOpts{
|
||||
PageOpts: &model.PageOpts{
|
||||
@@ -911,6 +914,36 @@ func TestGetGroups(t *testing.T) {
|
||||
|
||||
_, response = th.Client.GetGroups(opts)
|
||||
assert.Nil(t, response.Error)
|
||||
|
||||
// test "since", should only return group created in this test, not th.Group
|
||||
opts.Since = start
|
||||
groups, response = th.Client.GetGroups(opts)
|
||||
assert.Nil(t, response.Error)
|
||||
assert.Len(t, groups, 1)
|
||||
// test correct group returned
|
||||
assert.Equal(t, groups[0].Id, group.Id)
|
||||
|
||||
// delete group, should still return
|
||||
th.App.DeleteGroup(group.Id)
|
||||
groups, response = th.Client.GetGroups(opts)
|
||||
assert.Nil(t, response.Error)
|
||||
assert.Len(t, groups, 1)
|
||||
assert.Equal(t, groups[0].Id, group.Id)
|
||||
|
||||
// test with current since value, return none
|
||||
opts.Since = model.GetMillis()
|
||||
groups, response = th.Client.GetGroups(opts)
|
||||
assert.Nil(t, response.Error)
|
||||
assert.Empty(t, groups)
|
||||
|
||||
// make sure delete group is not returned without Since
|
||||
opts.Since = 0
|
||||
groups, response = th.Client.GetGroups(opts)
|
||||
assert.Nil(t, response.Error)
|
||||
//'Normal getGroups should not return delete groups
|
||||
assert.Len(t, groups, 1)
|
||||
// make sure it returned th.Group,not group
|
||||
assert.Equal(t, groups[0].Id, th.Group.Id)
|
||||
}
|
||||
|
||||
func TestGetGroupsByUserId(t *testing.T) {
|
||||
|
||||
Ссылка в новой задаче
Block a user