From ac8282cda1455802f52ebe6687eeeef6c950bf49 Mon Sep 17 00:00:00 2001 From: Carlos Tadeu Panato Junior Date: Mon, 20 Mar 2017 13:37:34 +0100 Subject: Add updateConfig endpoint for apiV4 (#5706) --- api4/system.go | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'api4/system.go') diff --git a/api4/system.go b/api4/system.go index f12d802ef..5058b0e2f 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("/config/reload", ApiSessionRequired(configReload)).Methods("POST") + BaseRoutes.ApiRoot.Handle("/config", ApiSessionRequired(updateConfig)).Methods("PUT") BaseRoutes.ApiRoot.Handle("/email/test", ApiSessionRequired(testEmail)).Methods("POST") BaseRoutes.ApiRoot.Handle("/database/recycle", ApiSessionRequired(databaseRecycle)).Methods("POST") BaseRoutes.ApiRoot.Handle("/caches/invalidate", ApiSessionRequired(invalidateCaches)).Methods("POST") @@ -69,6 +70,32 @@ func configReload(c *Context, w http.ResponseWriter, r *http.Request) { ReturnStatusOK(w) } +func updateConfig(c *Context, w http.ResponseWriter, r *http.Request) { + cfg := model.ConfigFromJson(r.Body) + if cfg == nil { + c.SetInvalidParam("config") + return + } + + if !app.SessionHasPermissionTo(c.Session, model.PERMISSION_MANAGE_SYSTEM) { + c.SetPermissionError(model.PERMISSION_MANAGE_SYSTEM) + return + } + + err := app.SaveConfig(cfg) + if err != nil { + c.Err = err + return + } + + c.LogAudit("updateConfig") + + cfg = app.GetConfig() + + 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) { -- cgit v1.2.3-1-g7c22