summaryrefslogtreecommitdiffstats
path: root/api4
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
parent9b10f3ef5450886bc2eb47fc58b649ff67109b1d (diff)
downloadchat-ac8282cda1455802f52ebe6687eeeef6c950bf49.tar.gz
chat-ac8282cda1455802f52ebe6687eeeef6c950bf49.tar.bz2
chat-ac8282cda1455802f52ebe6687eeeef6c950bf49.zip
Add updateConfig endpoint for apiV4 (#5706)
Diffstat (limited to 'api4')
-rw-r--r--api4/system.go27
-rw-r--r--api4/system_test.go42
2 files changed, 69 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) {
diff --git a/api4/system_test.go b/api4/system_test.go
index 80b4996ca..658bb5881 100644
--- a/api4/system_test.go
+++ b/api4/system_test.go
@@ -5,6 +5,7 @@ import (
"testing"
l4g "github.com/alecthomas/log4go"
+ "github.com/mattermost/platform/app"
"github.com/mattermost/platform/model"
"github.com/mattermost/platform/utils"
)
@@ -88,6 +89,47 @@ func TestReloadConfig(t *testing.T) {
*utils.Cfg.TeamSettings.EnableOpenServer = true
}
+func TestUpdateConfig(t *testing.T) {
+ th := Setup().InitBasic().InitSystemAdmin()
+ defer TearDown()
+ Client := th.Client
+
+ cfg := app.GetConfig()
+
+ _, resp := Client.UpdateConfig(cfg)
+ CheckForbiddenStatus(t, resp)
+
+ SiteName := utils.Cfg.TeamSettings.SiteName
+
+ cfg.TeamSettings.SiteName = "MyFancyName"
+ cfg, resp = th.SystemAdminClient.UpdateConfig(cfg)
+ CheckNoError(t, resp)
+
+ if len(cfg.TeamSettings.SiteName) == 0 {
+ t.Fatal()
+ } else {
+ if cfg.TeamSettings.SiteName != "MyFancyName" {
+ t.Log("It should update the SiteName")
+ t.Fatal()
+ }
+ }
+
+ //Revert the change
+ cfg.TeamSettings.SiteName = SiteName
+ cfg, resp = th.SystemAdminClient.UpdateConfig(cfg)
+ CheckNoError(t, resp)
+
+ if len(cfg.TeamSettings.SiteName) == 0 {
+ t.Fatal()
+ } else {
+ if cfg.TeamSettings.SiteName != SiteName {
+ t.Log("It should update the SiteName")
+ t.Fatal()
+ }
+ }
+
+}
+
func TestEmailTest(t *testing.T) {
th := Setup().InitBasic().InitSystemAdmin()
defer TearDown()