From 27d2c1f6febdc6b80f60837086ebe0c08f975147 Mon Sep 17 00:00:00 2001 From: Carlos Tadeu Panato Junior Date: Mon, 13 Mar 2017 16:47:33 +0100 Subject: Add implementation for POST /database/recycle apiV4 - Recycle database connection (#5717) --- api4/system.go | 13 +++++++++++++ api4/system_test.go | 13 +++++++++++++ 2 files changed, 26 insertions(+) (limited to 'api4') 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) + +} -- cgit v1.2.3-1-g7c22