diff options
author | Joram Wilander <jwawilander@gmail.com> | 2017-06-19 16:35:53 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-06-19 16:35:53 -0400 |
commit | 5627f3fd1d315e1574a444daba36aee592f1c7b5 (patch) | |
tree | ecb255b95ed8cb9fd73e7984b8fc08c987da11ef /api4 | |
parent | ef9326bcbb461b4f3265f75a9f738e67e58b88d1 (diff) | |
download | chat-5627f3fd1d315e1574a444daba36aee592f1c7b5.tar.gz chat-5627f3fd1d315e1574a444daba36aee592f1c7b5.tar.bz2 chat-5627f3fd1d315e1574a444daba36aee592f1c7b5.zip |
Add GET /analytics/old endpoint for v4 (#6666)
Diffstat (limited to 'api4')
-rw-r--r-- | api4/system.go | 29 | ||||
-rw-r--r-- | api4/system_test.go | 42 |
2 files changed, 71 insertions, 0 deletions
diff --git a/api4/system.go b/api4/system.go index 92674419f..ff3aab0d0 100644 --- a/api4/system.go +++ b/api4/system.go @@ -37,6 +37,8 @@ func InitSystem() { BaseRoutes.ApiRoot.Handle("/logs", ApiSessionRequired(getLogs)).Methods("GET") BaseRoutes.ApiRoot.Handle("/logs", ApiSessionRequired(postLog)).Methods("POST") + + BaseRoutes.ApiRoot.Handle("/analytics/old", ApiSessionRequired(getAnalytics)).Methods("GET") } func getSystemPing(c *Context, w http.ResponseWriter, r *http.Request) { @@ -336,3 +338,30 @@ func removeLicense(c *Context, w http.ResponseWriter, r *http.Request) { c.LogAudit("success") ReturnStatusOK(w) } + +func getAnalytics(c *Context, w http.ResponseWriter, r *http.Request) { + name := r.URL.Query().Get("name") + teamId := r.URL.Query().Get("team_id") + + if name == "" { + name = "standard" + } + + if !app.SessionHasPermissionTo(c.Session, model.PERMISSION_MANAGE_SYSTEM) { + c.SetPermissionError(model.PERMISSION_MANAGE_SYSTEM) + return + } + + rows, err := app.GetAnalytics(name, teamId) + if err != nil { + c.Err = err + return + } + + if rows == nil { + c.SetInvalidParam("name") + return + } + + w.Write([]byte(rows.ToJson())) +} diff --git a/api4/system_test.go b/api4/system_test.go index 57cc10343..435501e72 100644 --- a/api4/system_test.go +++ b/api4/system_test.go @@ -392,3 +392,45 @@ func TestRemoveLicenseFile(t *testing.T) { t.Fatal("should pass") } } + +func TestGetAnalyticsOld(t *testing.T) { + th := Setup().InitBasic().InitSystemAdmin() + defer TearDown() + Client := th.Client + + rows, resp := Client.GetAnalyticsOld("", "") + CheckForbiddenStatus(t, resp) + if rows != nil { + t.Fatal("should be nil") + } + + rows, resp = th.SystemAdminClient.GetAnalyticsOld("", "") + CheckNoError(t, resp) + + found := false + for _, row := range rows { + if row.Name == "unique_user_count" { + found = true + } + } + + if !found { + t.Fatal("should return unique user count") + } + + _, resp = th.SystemAdminClient.GetAnalyticsOld("post_counts_day", "") + CheckNoError(t, resp) + + _, resp = th.SystemAdminClient.GetAnalyticsOld("user_counts_with_posts_day", "") + CheckNoError(t, resp) + + _, resp = th.SystemAdminClient.GetAnalyticsOld("extra_counts", "") + CheckNoError(t, resp) + + _, resp = th.SystemAdminClient.GetAnalyticsOld("", th.BasicTeam.Id) + CheckNoError(t, resp) + + Client.Logout() + _, resp = Client.GetAnalyticsOld("", th.BasicTeam.Id) + CheckUnauthorizedStatus(t, resp) +} |