From ddfa6e2436d62ad022206859729d943a66f4427f Mon Sep 17 00:00:00 2001 From: Claudio Costa Date: Wed, 25 Aug 2021 20:29:41 +0200 Subject: [PATCH] [MM-38082] Add local-mode handler for config reload endpoint (#18252) * Add local-mode handler for config reload endpoint * Remove redundant method --- api4/config.go | 7 +++++-- api4/config_local.go | 1 + api4/config_test.go | 6 +++--- i18n/en.json | 4 ++++ 4 files changed, 13 insertions(+), 5 deletions(-) diff --git a/api4/config.go b/api4/config.go index cfa66ad61f..bfaa13865b 100644 --- a/api4/config.go +++ b/api4/config.go @@ -86,12 +86,15 @@ func configReload(c *Context, w http.ResponseWriter, r *http.Request) { return } - if *c.App.Config().ExperimentalSettings.RestrictSystemAdmin { + if !c.AppContext.Session().IsUnrestricted() && *c.App.Config().ExperimentalSettings.RestrictSystemAdmin { c.Err = model.NewAppError("configReload", "api.restricted_system_admin", nil, "", http.StatusBadRequest) return } - c.App.ReloadConfig() + if err := c.App.ReloadConfig(); err != nil { + c.Err = model.NewAppError("configReload", "api.config.reload_config.app_error", nil, err.Error(), http.StatusInternalServerError) + return + } auditRec.Success() diff --git a/api4/config_local.go b/api4/config_local.go index ffb539b710..6c82b78340 100644 --- a/api4/config_local.go +++ b/api4/config_local.go @@ -19,6 +19,7 @@ func (api *API) InitConfigLocal() { api.BaseRoutes.APIRoot.Handle("/config", api.APILocal(localGetConfig)).Methods("GET") api.BaseRoutes.APIRoot.Handle("/config", api.APILocal(localUpdateConfig)).Methods("PUT") api.BaseRoutes.APIRoot.Handle("/config/patch", api.APILocal(localPatchConfig)).Methods("PUT") + api.BaseRoutes.APIRoot.Handle("/config/reload", api.APILocal(configReload)).Methods("POST") api.BaseRoutes.APIRoot.Handle("/config/migrate", api.APILocal(migrateConfig)).Methods("POST") } diff --git a/api4/config_test.go b/api4/config_test.go index 3baaef649d..953c6b63e3 100644 --- a/api4/config_test.go +++ b/api4/config_test.go @@ -126,10 +126,10 @@ func TestReloadConfig(t *testing.T) { CheckForbiddenStatus(t, resp) }) - t.Run("as system admin", func(t *testing.T) { - _, err := th.SystemAdminClient.ReloadConfig() + th.TestForSystemAdminAndLocal(t, func(t *testing.T, client *model.Client4) { + _, err := client.ReloadConfig() require.NoError(t, err) - }) + }, "as system admin and local mode") t.Run("as restricted system admin", func(t *testing.T) { th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ExperimentalSettings.RestrictSystemAdmin = true }) diff --git a/i18n/en.json b/i18n/en.json index 8c3fe054ca..47ccd74c6d 100644 --- a/i18n/en.json +++ b/i18n/en.json @@ -1462,6 +1462,10 @@ "id": "api.config.patch_config.restricted_merge.app_error", "translation": "Failed to merge given config." }, + { + "id": "api.config.reload_config.app_error", + "translation": "Failed to reload config." + }, { "id": "api.config.update_config.clear_siteurl.app_error", "translation": "Site URL cannot be cleared."