diff options
Diffstat (limited to 'api')
-rw-r--r-- | api/admin.go | 31 | ||||
-rw-r--r-- | api/admin_test.go | 50 |
2 files changed, 79 insertions, 2 deletions
diff --git a/api/admin.go b/api/admin.go index d04991353..feb70aae3 100644 --- a/api/admin.go +++ b/api/admin.go @@ -184,16 +184,18 @@ func getAnalytics(c *Context, w http.ResponseWriter, r *http.Request) { name := params["name"] if name == "standard" { - var rows model.AnalyticsRows = make([]*model.AnalyticsRow, 4) + var rows model.AnalyticsRows = make([]*model.AnalyticsRow, 5) rows[0] = &model.AnalyticsRow{"channel_open_count", 0} rows[1] = &model.AnalyticsRow{"channel_private_count", 0} rows[2] = &model.AnalyticsRow{"post_count", 0} rows[3] = &model.AnalyticsRow{"unique_user_count", 0} + rows[4] = &model.AnalyticsRow{"team_count", 0} openChan := Srv.Store.Channel().AnalyticsTypeCount(teamId, model.CHANNEL_OPEN) privateChan := Srv.Store.Channel().AnalyticsTypeCount(teamId, model.CHANNEL_PRIVATE) postChan := Srv.Store.Post().AnalyticsPostCount(teamId, false, false) userChan := Srv.Store.User().AnalyticsUniqueUserCount(teamId) + teamChan := Srv.Store.Team().AnalyticsTeamCount() if r := <-openChan; r.Err != nil { c.Err = r.Err @@ -223,6 +225,13 @@ func getAnalytics(c *Context, w http.ResponseWriter, r *http.Request) { rows[3].Value = float64(r.Data.(int64)) } + if r := <-teamChan; r.Err != nil { + c.Err = r.Err + return + } else { + rows[4].Value = float64(r.Data.(int64)) + } + w.Write([]byte(rows.ToJson())) } else if name == "post_counts_day" { if r := <-Srv.Store.Post().AnalyticsPostCountsByDay(teamId); r.Err != nil { @@ -239,16 +248,20 @@ func getAnalytics(c *Context, w http.ResponseWriter, r *http.Request) { w.Write([]byte(r.Data.(model.AnalyticsRows).ToJson())) } } else if name == "extra_counts" { - var rows model.AnalyticsRows = make([]*model.AnalyticsRow, 4) + var rows model.AnalyticsRows = make([]*model.AnalyticsRow, 6) rows[0] = &model.AnalyticsRow{"file_post_count", 0} rows[1] = &model.AnalyticsRow{"hashtag_post_count", 0} rows[2] = &model.AnalyticsRow{"incoming_webhook_count", 0} rows[3] = &model.AnalyticsRow{"outgoing_webhook_count", 0} + rows[4] = &model.AnalyticsRow{"command_count", 0} + rows[5] = &model.AnalyticsRow{"session_count", 0} fileChan := Srv.Store.Post().AnalyticsPostCount(teamId, true, false) hashtagChan := Srv.Store.Post().AnalyticsPostCount(teamId, false, true) iHookChan := Srv.Store.Webhook().AnalyticsIncomingCount(teamId) oHookChan := Srv.Store.Webhook().AnalyticsOutgoingCount(teamId) + commandChan := Srv.Store.Command().AnalyticsCommandCount(teamId) + sessionChan := Srv.Store.Session().AnalyticsSessionCount(teamId) if r := <-fileChan; r.Err != nil { c.Err = r.Err @@ -278,6 +291,20 @@ func getAnalytics(c *Context, w http.ResponseWriter, r *http.Request) { rows[3].Value = float64(r.Data.(int64)) } + if r := <-commandChan; r.Err != nil { + c.Err = r.Err + return + } else { + rows[4].Value = float64(r.Data.(int64)) + } + + if r := <-sessionChan; r.Err != nil { + c.Err = r.Err + return + } else { + rows[5].Value = float64(r.Data.(int64)) + } + w.Write([]byte(rows.ToJson())) } else { c.SetInvalidParam("getAnalytics", "name") diff --git a/api/admin_test.go b/api/admin_test.go index 8a9c82b44..bdea0bc5b 100644 --- a/api/admin_test.go +++ b/api/admin_test.go @@ -254,6 +254,16 @@ func TestGetTeamAnalyticsStandard(t *testing.T) { t.Log(rows.ToJson()) t.Fatal() } + + if rows[4].Name != "team_count" { + t.Log(rows.ToJson()) + t.Fatal() + } + + if rows[4].Value == 0 { + t.Log(rows.ToJson()) + t.Fatal() + } } if result, err := Client.GetSystemAnalytics("standard"); err != nil { @@ -300,6 +310,16 @@ func TestGetTeamAnalyticsStandard(t *testing.T) { t.Log(rows.ToJson()) t.Fatal() } + + if rows[4].Name != "team_count" { + t.Log(rows.ToJson()) + t.Fatal() + } + + if rows[4].Value == 0 { + t.Log(rows.ToJson()) + t.Fatal() + } } } @@ -469,6 +489,26 @@ func TestGetTeamAnalyticsExtra(t *testing.T) { t.Log(rows.ToJson()) t.Fatal() } + + if rows[4].Name != "command_count" { + t.Log(rows.ToJson()) + t.Fatal() + } + + if rows[4].Value != 0 { + t.Log(rows.ToJson()) + t.Fatal() + } + + if rows[5].Name != "session_count" { + t.Log(rows.ToJson()) + t.Fatal() + } + + if rows[5].Value == 0 { + t.Log(rows.ToJson()) + t.Fatal() + } } if result, err := Client.GetSystemAnalytics("extra_counts"); err != nil { @@ -500,5 +540,15 @@ func TestGetTeamAnalyticsExtra(t *testing.T) { t.Log(rows.ToJson()) t.Fatal() } + + if rows[4].Name != "command_count" { + t.Log(rows.ToJson()) + t.Fatal() + } + + if rows[5].Name != "session_count" { + t.Log(rows.ToJson()) + t.Fatal() + } } } |