MM-13893: refactor config (#10230)
* refactor utils/config* to config/ * pull validateLdapFilter into app * clean up Config/GetConfig/GetSanitizedConfig usage Eliminate app.GetConfig() in favour of just using app.Config() directly, but expose app.GetSanitizedConfig() for when the old behaviour was required. * web: isolate config setup * TestInvitePeopleProvider: make config explicit * regenerateClientConfig: avoid racey map access * integrate watch flag into app.ConfigFile option * make app.Option return an error * release.mk: only cp static files from config/ * release.mk: fix cp static files from config/ * api4: TestPlugin cleanup * s/c/cfg/ for clarity * fix merge conflict * testlib: allow customization of testlib driver name
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
aca8914e35
Коммит
3a71709103
@@ -79,7 +79,7 @@ func setupTestHelper(enterprise bool, updateConfig func(*model.Config)) *TestHel
|
||||
panic(err)
|
||||
}
|
||||
|
||||
options := []app.Option{app.ConfigFile(tempConfig.Name()), app.DisableConfigWatch}
|
||||
options := []app.Option{app.ConfigFile(tempConfig.Name(), false)}
|
||||
options = append(options, app.StoreOverride(testStore))
|
||||
|
||||
s, err := app.NewServer(options...)
|
||||
|
||||
@@ -20,19 +20,9 @@ func TestPlugin(t *testing.T) {
|
||||
th := Setup().InitBasic()
|
||||
defer th.TearDown()
|
||||
|
||||
enablePlugins := *th.App.Config().PluginSettings.Enable
|
||||
enableUploadPlugins := *th.App.Config().PluginSettings.EnableUploads
|
||||
statesJson, _ := json.Marshal(th.App.Config().PluginSettings.PluginStates)
|
||||
states := map[string]*model.PluginState{}
|
||||
json.Unmarshal(statesJson, &states)
|
||||
defer func() {
|
||||
th.App.UpdateConfig(func(cfg *model.Config) {
|
||||
*cfg.PluginSettings.Enable = enablePlugins
|
||||
*cfg.PluginSettings.EnableUploads = enableUploadPlugins
|
||||
cfg.PluginSettings.PluginStates = states
|
||||
})
|
||||
th.App.SaveConfig(th.App.Config(), false)
|
||||
}()
|
||||
th.App.UpdateConfig(func(cfg *model.Config) {
|
||||
*cfg.PluginSettings.Enable = true
|
||||
*cfg.PluginSettings.EnableUploads = true
|
||||
|
||||
@@ -741,7 +741,7 @@ func TestPinPost(t *testing.T) {
|
||||
CheckForbiddenStatus(t, resp)
|
||||
|
||||
t.Run("unable-to-pin-post-in-read-only-town-square", func(t *testing.T) {
|
||||
townSquareIsReadOnly := *th.App.GetConfig().TeamSettings.ExperimentalTownSquareIsReadOnly
|
||||
townSquareIsReadOnly := *th.App.Config().TeamSettings.ExperimentalTownSquareIsReadOnly
|
||||
th.App.SetLicense(model.NewTestLicense())
|
||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.TeamSettings.ExperimentalTownSquareIsReadOnly = true })
|
||||
|
||||
|
||||
@@ -103,7 +103,7 @@ func getConfig(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
cfg := c.App.GetConfig()
|
||||
cfg := c.App.GetSanitizedConfig()
|
||||
|
||||
w.Header().Set("Cache-Control", "no-cache, no-store, must-revalidate")
|
||||
w.Write([]byte(cfg.ToJson()))
|
||||
@@ -134,12 +134,12 @@ func updateConfig(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
// Do not allow plugin uploads to be toggled through the API
|
||||
cfg.PluginSettings.EnableUploads = c.App.GetConfig().PluginSettings.EnableUploads
|
||||
cfg.PluginSettings.EnableUploads = c.App.Config().PluginSettings.EnableUploads
|
||||
|
||||
// If the Message Export feature has been toggled in the System Console, rewrite the ExportFromTimestamp field to an
|
||||
// appropriate value. The rewriting occurs here to ensure it doesn't affect values written to the config file
|
||||
// directly and not through the System Console UI.
|
||||
if *cfg.MessageExportSettings.EnableExport != *c.App.GetConfig().MessageExportSettings.EnableExport {
|
||||
if *cfg.MessageExportSettings.EnableExport != *c.App.Config().MessageExportSettings.EnableExport {
|
||||
if *cfg.MessageExportSettings.EnableExport && *cfg.MessageExportSettings.ExportFromTimestamp == int64(0) {
|
||||
// When the feature is toggled on, use the current timestamp as the start time for future exports.
|
||||
cfg.MessageExportSettings.ExportFromTimestamp = model.NewInt64(model.GetMillis())
|
||||
@@ -158,7 +158,7 @@ func updateConfig(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
c.LogAudit("updateConfig")
|
||||
|
||||
cfg = c.App.GetConfig()
|
||||
cfg = c.App.GetSanitizedConfig()
|
||||
|
||||
w.Header().Set("Cache-Control", "no-cache, no-store, must-revalidate")
|
||||
w.Write([]byte(cfg.ToJson()))
|
||||
@@ -477,8 +477,7 @@ func getRedirectLocation(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
m := make(map[string]string)
|
||||
m["location"] = ""
|
||||
|
||||
cfg := c.App.GetConfig()
|
||||
if !*cfg.ServiceSettings.EnableLinkPreviews {
|
||||
if !*c.App.Config().ServiceSettings.EnableLinkPreviews {
|
||||
w.Write([]byte(model.MapToJson(m)))
|
||||
return
|
||||
}
|
||||
|
||||
@@ -131,19 +131,19 @@ func TestUpdateConfig(t *testing.T) {
|
||||
require.Equal(t, SiteName, cfg.TeamSettings.SiteName, "It should update the SiteName")
|
||||
|
||||
t.Run("Should not be able to modify PluginSettings.EnableUploads", func(t *testing.T) {
|
||||
oldEnableUploads := *th.App.GetConfig().PluginSettings.EnableUploads
|
||||
oldEnableUploads := *th.App.Config().PluginSettings.EnableUploads
|
||||
*cfg.PluginSettings.EnableUploads = !oldEnableUploads
|
||||
|
||||
cfg, resp = th.SystemAdminClient.UpdateConfig(cfg)
|
||||
CheckNoError(t, resp)
|
||||
assert.Equal(t, oldEnableUploads, *cfg.PluginSettings.EnableUploads)
|
||||
assert.Equal(t, oldEnableUploads, *th.App.GetConfig().PluginSettings.EnableUploads)
|
||||
assert.Equal(t, oldEnableUploads, *th.App.Config().PluginSettings.EnableUploads)
|
||||
|
||||
cfg.PluginSettings.EnableUploads = nil
|
||||
cfg, resp = th.SystemAdminClient.UpdateConfig(cfg)
|
||||
CheckNoError(t, resp)
|
||||
assert.Equal(t, oldEnableUploads, *cfg.PluginSettings.EnableUploads)
|
||||
assert.Equal(t, oldEnableUploads, *th.App.GetConfig().PluginSettings.EnableUploads)
|
||||
assert.Equal(t, oldEnableUploads, *th.App.Config().PluginSettings.EnableUploads)
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -856,7 +856,7 @@ func updateUserActive(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
// if EnableUserDeactivation flag is disabled the user cannot deactivate himself.
|
||||
if isSelfDeactive && !*c.App.GetConfig().TeamSettings.EnableUserDeactivation {
|
||||
if isSelfDeactive && !*c.App.Config().TeamSettings.EnableUserDeactivation {
|
||||
c.Err = model.NewAppError("updateUserActive", "api.user.update_active.not_enable.app_error", nil, "userId="+c.Params.UserId, http.StatusUnauthorized)
|
||||
return
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user