diff options
Diffstat (limited to 'api4')
-rw-r--r-- | api4/params.go | 17 | ||||
-rw-r--r-- | api4/plugin_test.go | 2 | ||||
-rw-r--r-- | api4/reaction_test.go | 15 | ||||
-rw-r--r-- | api4/system.go | 2 | ||||
-rw-r--r-- | api4/system_test.go | 16 | ||||
-rw-r--r-- | api4/user.go | 12 | ||||
-rw-r--r-- | api4/user_test.go | 11 |
7 files changed, 49 insertions, 26 deletions
diff --git a/api4/params.go b/api4/params.go index 1f0fe8e63..64ee43771 100644 --- a/api4/params.go +++ b/api4/params.go @@ -11,9 +11,11 @@ import ( ) const ( - PAGE_DEFAULT = 0 - PER_PAGE_DEFAULT = 60 - PER_PAGE_MAXIMUM = 200 + PAGE_DEFAULT = 0 + PER_PAGE_DEFAULT = 60 + PER_PAGE_MAXIMUM = 200 + LOGS_PER_PAGE_DEFAULT = 10000 + LOGS_PER_PAGE_MAXIMUM = 10000 ) type ApiParams struct { @@ -43,6 +45,7 @@ type ApiParams struct { ActionId string Page int PerPage int + LogsPerPage int Permanent bool } @@ -165,5 +168,13 @@ func ApiParamsFromRequest(r *http.Request) *ApiParams { params.PerPage = val } + if val, err := strconv.Atoi(r.URL.Query().Get("logs_per_page")); err != nil || val < 0 { + params.LogsPerPage = LOGS_PER_PAGE_DEFAULT + } else if val > LOGS_PER_PAGE_MAXIMUM { + params.LogsPerPage = LOGS_PER_PAGE_MAXIMUM + } else { + params.LogsPerPage = val + } + return params } diff --git a/api4/plugin_test.go b/api4/plugin_test.go index 82e11f775..e385b5c8c 100644 --- a/api4/plugin_test.go +++ b/api4/plugin_test.go @@ -46,7 +46,7 @@ func TestPlugin(t *testing.T) { *cfg.PluginSettings.EnableUploads = true }) - th.App.InitPlugins(pluginDir, webappDir) + th.App.InitPlugins(pluginDir, webappDir, nil) defer func() { th.App.ShutDownPlugins() th.App.PluginEnv = nil diff --git a/api4/reaction_test.go b/api4/reaction_test.go index b64d42ce3..93cd754c9 100644 --- a/api4/reaction_test.go +++ b/api4/reaction_test.go @@ -7,7 +7,7 @@ import ( "strings" "testing" - "reflect" + "github.com/stretchr/testify/assert" "github.com/mattermost/mattermost-server/model" ) @@ -180,20 +180,15 @@ func TestGetReactions(t *testing.T) { rr, resp := Client.GetReactions(postId) CheckNoError(t, resp) - if len(rr) != 5 { - t.Fatal("reactions should returned correct length") - } - - if !reflect.DeepEqual(rr, reactions) { - t.Fatal("reactions should have matched") + assert.Len(t, rr, 5) + for _, r := range reactions { + assert.Contains(t, reactions, r) } rr, resp = Client.GetReactions("junk") CheckBadRequestStatus(t, resp) - if len(rr) != 0 { - t.Fatal("reactions should return empty") - } + assert.Empty(t, rr) _, resp = Client.GetReactions(GenerateTestId()) CheckForbiddenStatus(t, resp) diff --git a/api4/system.go b/api4/system.go index 7bc846766..93e9ddcd2 100644 --- a/api4/system.go +++ b/api4/system.go @@ -187,7 +187,7 @@ func getLogs(c *Context, w http.ResponseWriter, r *http.Request) { return } - lines, err := c.App.GetLogs(c.Params.Page, c.Params.PerPage) + lines, err := c.App.GetLogs(c.Params.Page, c.Params.LogsPerPage) if err != nil { c.Err = err return diff --git a/api4/system_test.go b/api4/system_test.go index 3afcf633c..1b2bb5d99 100644 --- a/api4/system_test.go +++ b/api4/system_test.go @@ -308,18 +308,18 @@ func TestGetLogs(t *testing.T) { logs, resp := th.SystemAdminClient.GetLogs(0, 10) CheckNoError(t, resp) - // if len(logs) != 10 { - // t.Log(len(logs)) - // t.Fatal("wrong length") - // } + if len(logs) != 10 { + t.Log(len(logs)) + t.Fatal("wrong length") + } logs, resp = th.SystemAdminClient.GetLogs(1, 10) CheckNoError(t, resp) - // if len(logs) != 10 { - // t.Log(len(logs)) - // t.Fatal("wrong length") - // } + if len(logs) != 10 { + t.Log(len(logs)) + t.Fatal("wrong length") + } logs, resp = th.SystemAdminClient.GetLogs(-1, -1) CheckNoError(t, resp) diff --git a/api4/user.go b/api4/user.go index 16b7f79a9..4f4185958 100644 --- a/api4/user.go +++ b/api4/user.go @@ -683,10 +683,18 @@ func updateUserActive(c *Context, w http.ResponseWriter, r *http.Request) { return } - if ruser, err := c.App.UpdateNonSSOUserActive(c.Params.UserId, active); err != nil { + var user *model.User + var err *model.AppError + + if user, err = c.App.GetUser(c.Params.UserId); err != nil { + c.Err = err + return + } + + if _, err := c.App.UpdateActive(user, active); err != nil { c.Err = err } else { - c.LogAuditWithUserId(ruser.Id, fmt.Sprintf("active=%v", active)) + c.LogAuditWithUserId(user.Id, fmt.Sprintf("active=%v", active)) ReturnStatusOK(w) } } diff --git a/api4/user_test.go b/api4/user_test.go index 9c554da54..e3f1935b4 100644 --- a/api4/user_test.go +++ b/api4/user_test.go @@ -1163,6 +1163,13 @@ func TestUpdateUserActive(t *testing.T) { _, resp = SystemAdminClient.UpdateUserActive(user.Id, false) CheckNoError(t, resp) + + authData := model.NewId() + result := <-th.App.Srv.Store.User().UpdateAuthData(user.Id, "random", &authData, "", true) + require.Nil(t, result.Err) + + _, resp = SystemAdminClient.UpdateUserActive(user.Id, false) + CheckNoError(t, resp) } func TestGetUsers(t *testing.T) { @@ -2123,7 +2130,9 @@ func TestSwitchAccount(t *testing.T) { defer func() { utils.SetIsLicensed(isLicensed) utils.SetLicense(license) - th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.ExperimentalEnableAuthenticationTransfer = enableAuthenticationTransfer }) + th.App.UpdateConfig(func(cfg *model.Config) { + *cfg.ServiceSettings.ExperimentalEnableAuthenticationTransfer = enableAuthenticationTransfer + }) }() utils.SetIsLicensed(true) utils.SetLicense(&model.License{Features: &model.Features{}}) |