summaryrefslogtreecommitdiffstats
path: root/api4/system.go
diff options
context:
space:
mode:
authorCarlos Tadeu Panato Junior <ctadeu@gmail.com>2017-03-20 13:37:34 +0100
committerGeorge Goldberg <george@gberg.me>2017-03-20 12:37:34 +0000
commitac8282cda1455802f52ebe6687eeeef6c950bf49 (patch)
treea0eb38c5de6c6605399f91bf35b0fc5434bd4911 /api4/system.go
parent9b10f3ef5450886bc2eb47fc58b649ff67109b1d (diff)
downloadchat-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.go27
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) {