diff options
author | Carlos Tadeu Panato Junior <ctadeu@gmail.com> | 2017-03-13 16:47:33 +0100 |
---|---|---|
committer | George Goldberg <george@gberg.me> | 2017-03-13 15:47:33 +0000 |
commit | 27d2c1f6febdc6b80f60837086ebe0c08f975147 (patch) | |
tree | cb2b6ace91234817721170c8d3b9a0ffceeacfed | |
parent | 38958d9ac4f415d9ae99dfcdb53bfdc355d96764 (diff) | |
download | chat-27d2c1f6febdc6b80f60837086ebe0c08f975147.tar.gz chat-27d2c1f6febdc6b80f60837086ebe0c08f975147.tar.bz2 chat-27d2c1f6febdc6b80f60837086ebe0c08f975147.zip |
Add implementation for POST /database/recycle apiV4 - Recycle database connection (#5717)
-rw-r--r-- | api4/system.go | 13 | ||||
-rw-r--r-- | api4/system_test.go | 13 | ||||
-rw-r--r-- | model/client4.go | 13 |
3 files changed, 39 insertions, 0 deletions
diff --git a/api4/system.go b/api4/system.go index f7a3918a5..04275f57f 100644 --- a/api4/system.go +++ b/api4/system.go @@ -18,6 +18,7 @@ func InitSystem() { BaseRoutes.System.Handle("/ping", ApiHandler(getSystemPing)).Methods("GET") BaseRoutes.ApiRoot.Handle("/config", ApiSessionRequired(getConfig)).Methods("GET") BaseRoutes.ApiRoot.Handle("/email/test", ApiSessionRequired(testEmail)).Methods("POST") + BaseRoutes.ApiRoot.Handle("/database/recycle", ApiSessionRequired(databaseRecycle)).Methods("POST") } func getSystemPing(c *Context, w http.ResponseWriter, r *http.Request) { @@ -51,3 +52,15 @@ func getConfig(c *Context, w http.ResponseWriter, r *http.Request) { w.Header().Set("Cache-Control", "no-cache, no-store, must-revalidate") w.Write([]byte(cfg.ToJson())) } + +func databaseRecycle(c *Context, w http.ResponseWriter, r *http.Request) { + + if !app.SessionHasPermissionTo(c.Session, model.PERMISSION_MANAGE_SYSTEM) { + c.SetPermissionError(model.PERMISSION_MANAGE_SYSTEM) + return + } + + app.RecycleDatabaseConnection() + + ReturnStatusOK(w) +} diff --git a/api4/system_test.go b/api4/system_test.go index ae133183b..36ae347dd 100644 --- a/api4/system_test.go +++ b/api4/system_test.go @@ -94,3 +94,16 @@ func TestEmailTest(t *testing.T) { CheckErrorMessage(t, resp, "api.admin.test_email.missing_server") CheckInternalErrorStatus(t, resp) } + +func TestDatabaseRecycle(t *testing.T) { + th := Setup().InitBasic().InitSystemAdmin() + defer TearDown() + Client := th.Client + + _, resp := Client.DatabaseRecycle() + CheckForbiddenStatus(t, resp) + + _, resp = th.SystemAdminClient.DatabaseRecycle() + CheckNoError(t, resp) + +} diff --git a/model/client4.go b/model/client4.go index b6c2daf0f..4c46d6d57 100644 --- a/model/client4.go +++ b/model/client4.go @@ -150,6 +150,10 @@ func (c *Client4) GetTestEmailRoute() string { return fmt.Sprintf("/email/test") } +func (c *Client4) GetDatabaseRoute() string { + return fmt.Sprintf("/database") +} + func (c *Client4) GetIncomingWebhooksRoute() string { return fmt.Sprintf("/hooks/incoming") } @@ -1088,6 +1092,15 @@ func (c *Client4) GetConfig() (*Config, *Response) { } } +func (c *Client4) DatabaseRecycle() (bool, *Response) { + if r, err := c.DoApiPost(c.GetDatabaseRoute()+"/recycle", ""); err != nil { + return false, &Response{StatusCode: r.StatusCode, Error: err} + } else { + defer closeBody(r) + return CheckStatusOK(r), BuildResponse(r) + } +} + // Webhooks Section // CreateIncomingWebhook creates an incoming webhook for a channel. |