diff options
-rw-r--r-- | api4/system.go | 13 | ||||
-rw-r--r-- | api4/system_test.go | 21 | ||||
-rw-r--r-- | model/client4.go | 10 |
3 files changed, 44 insertions, 0 deletions
diff --git a/api4/system.go b/api4/system.go index 04275f57f..32c010d82 100644 --- a/api4/system.go +++ b/api4/system.go @@ -17,6 +17,7 @@ func InitSystem() { BaseRoutes.System.Handle("/ping", ApiHandler(getSystemPing)).Methods("GET") BaseRoutes.ApiRoot.Handle("/config", ApiSessionRequired(getConfig)).Methods("GET") + BaseRoutes.ApiRoot.Handle("/config/reload", ApiSessionRequired(configReload)).Methods("POST") BaseRoutes.ApiRoot.Handle("/email/test", ApiSessionRequired(testEmail)).Methods("POST") BaseRoutes.ApiRoot.Handle("/database/recycle", ApiSessionRequired(databaseRecycle)).Methods("POST") } @@ -53,6 +54,18 @@ func getConfig(c *Context, w http.ResponseWriter, r *http.Request) { w.Write([]byte(cfg.ToJson())) } +func configReload(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.ReloadConfig() + + w.Header().Set("Cache-Control", "no-cache, no-store, must-revalidate") + ReturnStatusOK(w) +} + func databaseRecycle(c *Context, w http.ResponseWriter, r *http.Request) { if !app.SessionHasPermissionTo(c.Session, model.PERMISSION_MANAGE_SYSTEM) { diff --git a/api4/system_test.go b/api4/system_test.go index 36ae347dd..cb6ca7b81 100644 --- a/api4/system_test.go +++ b/api4/system_test.go @@ -66,6 +66,27 @@ func TestGetConfig(t *testing.T) { } } +func TestReloadConfig(t *testing.T) { + th := Setup().InitBasic().InitSystemAdmin() + defer TearDown() + Client := th.Client + + flag, resp := Client.ReloadConfig() + CheckForbiddenStatus(t, resp) + if flag == true { + t.Fatal("should not Reload the config due no permission.") + } + + flag, resp = th.SystemAdminClient.ReloadConfig() + CheckNoError(t, resp) + if flag == false { + t.Fatal("should Reload the config") + } + + utils.Cfg.TeamSettings.MaxUsersPerTeam = 50 + *utils.Cfg.TeamSettings.EnableOpenServer = true +} + func TestEmailTest(t *testing.T) { th := Setup().InitBasic().InitSystemAdmin() defer TearDown() diff --git a/model/client4.go b/model/client4.go index e9644ada0..799fec802 100644 --- a/model/client4.go +++ b/model/client4.go @@ -1131,6 +1131,16 @@ func (c *Client4) GetConfig() (*Config, *Response) { } } +// ReloadConfig will reload the server configuration. +func (c *Client4) ReloadConfig() (bool, *Response) { + if r, err := c.DoApiPost(c.GetConfigRoute()+"/reload", ""); err != nil { + return false, &Response{StatusCode: r.StatusCode, Error: err} + } else { + defer closeBody(r) + return CheckStatusOK(r), BuildResponse(r) + } +} + func (c *Client4) DatabaseRecycle() (bool, *Response) { if r, err := c.DoApiPost(c.GetDatabaseRoute()+"/recycle", ""); err != nil { return false, &Response{StatusCode: r.StatusCode, Error: err} |