Add updateConfig endpoint for apiV4 (#5706)

Этот коммит содержится в:
Carlos Tadeu Panato Junior
2017-03-20 13:37:34 +01:00
коммит произвёл George Goldberg
родитель 9b10f3ef54
Коммит ac8282cda1
5 изменённых файлов: 82 добавлений и 2 удалений

Просмотреть файл

@@ -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) {

Просмотреть файл

@@ -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()