diff options
author | Carlos Tadeu Panato Junior <ctadeu@gmail.com> | 2017-03-20 13:37:34 +0100 |
---|---|---|
committer | George Goldberg <george@gberg.me> | 2017-03-20 12:37:34 +0000 |
commit | ac8282cda1455802f52ebe6687eeeef6c950bf49 (patch) | |
tree | a0eb38c5de6c6605399f91bf35b0fc5434bd4911 /api4/system.go | |
parent | 9b10f3ef5450886bc2eb47fc58b649ff67109b1d (diff) | |
download | chat-ac8282cda1455802f52ebe6687eeeef6c950bf49.tar.gz chat-ac8282cda1455802f52ebe6687eeeef6c950bf49.tar.bz2 chat-ac8282cda1455802f52ebe6687eeeef6c950bf49.zip |
Add updateConfig endpoint for apiV4 (#5706)
Diffstat (limited to 'api4/system.go')
-rw-r--r-- | api4/system.go | 27 |
1 files changed, 27 insertions, 0 deletions
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) { |