diff options
author | JoramWilander <jwawilander@gmail.com> | 2016-02-02 16:49:27 -0500 |
---|---|---|
committer | JoramWilander <jwawilander@gmail.com> | 2016-02-02 16:49:27 -0500 |
commit | d153d661db7d4349d69824d318aa9ad571970606 (patch) | |
tree | 002c035bbd99d8e2be4a7c7ebb18b413de55ad6e /api | |
parent | f28486c4553f7f4bccf7bf69153c2f12699705f9 (diff) | |
download | chat-d153d661db7d4349d69824d318aa9ad571970606.tar.gz chat-d153d661db7d4349d69824d318aa9ad571970606.tar.bz2 chat-d153d661db7d4349d69824d318aa9ad571970606.zip |
Add basic server audit tab to system console for EE
Diffstat (limited to 'api')
-rw-r--r-- | api/admin.go | 29 | ||||
-rw-r--r-- | api/admin_test.go | 30 |
2 files changed, 58 insertions, 1 deletions
diff --git a/api/admin.go b/api/admin.go index 0ea6341e2..cc0de4429 100644 --- a/api/admin.go +++ b/api/admin.go @@ -1,4 +1,4 @@ -// Copyright (c) 2015 Mattermost, Inc. All Rights Reserved. +// Copyright (c) 2016 Mattermost, Inc. All Rights Reserved. // See License.txt for license information. package api @@ -21,6 +21,7 @@ func InitAdmin(r *mux.Router) { sr := r.PathPrefix("/admin").Subrouter() sr.Handle("/logs", ApiUserRequired(getLogs)).Methods("GET") + sr.Handle("/audits", ApiUserRequired(getAllAudits)).Methods("GET") sr.Handle("/config", ApiUserRequired(getConfig)).Methods("GET") sr.Handle("/save_config", ApiUserRequired(saveConfig)).Methods("POST") sr.Handle("/test_email", ApiUserRequired(testEmail)).Methods("POST") @@ -58,6 +59,32 @@ func getLogs(c *Context, w http.ResponseWriter, r *http.Request) { w.Write([]byte(model.ArrayToJson(lines))) } +func getAllAudits(c *Context, w http.ResponseWriter, r *http.Request) { + + if !c.HasSystemAdminPermissions("getAllAudits") { + return + } + + if result := <-Srv.Store.Audit().Get("", 200); result.Err != nil { + c.Err = result.Err + return + } else { + audits := result.Data.(model.Audits) + etag := audits.Etag() + + if HandleEtag(etag, w, r) { + return + } + + if len(etag) > 0 { + w.Header().Set(model.HEADER_ETAG_SERVER, etag) + } + + w.Write([]byte(audits.ToJson())) + return + } +} + func getClientConfig(c *Context, w http.ResponseWriter, r *http.Request) { w.Write([]byte(model.MapToJson(utils.ClientCfg))) } diff --git a/api/admin_test.go b/api/admin_test.go index 2552e642c..8abc60f7e 100644 --- a/api/admin_test.go +++ b/api/admin_test.go @@ -41,6 +41,36 @@ func TestGetLogs(t *testing.T) { } } +func TestGetAllAudits(t *testing.T) { + Setup() + + team := &model.Team{DisplayName: "Name", Name: "z-z-" + model.NewId() + "a", Email: "test@nowhere.com", Type: model.TEAM_OPEN} + team = Client.Must(Client.CreateTeam(team)).Data.(*model.Team) + + user := &model.User{TeamId: team.Id, Email: model.NewId() + "success+test@simulator.amazonses.com", Nickname: "Corey Hulen", Password: "pwd"} + user = Client.Must(Client.CreateUser(user, "")).Data.(*model.User) + store.Must(Srv.Store.User().VerifyEmail(user.Id)) + + Client.LoginByEmail(team.Name, user.Email, "pwd") + + if _, err := Client.GetAllAudits(); err == nil { + t.Fatal("Shouldn't have permissions") + } + + c := &Context{} + c.RequestId = model.NewId() + c.IpAddress = "cmd_line" + UpdateRoles(c, user, model.ROLE_SYSTEM_ADMIN) + + Client.LoginByEmail(team.Name, user.Email, "pwd") + + if audits, err := Client.GetAllAudits(); err != nil { + t.Fatal(err) + } else if len(audits.Data.(model.Audits)) <= 0 { + t.Fatal() + } +} + func TestGetClientProperties(t *testing.T) { Setup() |