From ec91ca46ff772de745c839bd4e7037d5424e5fc4 Mon Sep 17 00:00:00 2001 From: Agniva De Sarker Date: Wed, 6 Apr 2022 08:30:16 +0530 Subject: [PATCH] MM-42813: Fallback to default config if nil is passed (#19920) https://mattermost.atlassian.net/browse/MM-42813 ```release-note NONE ``` Co-authored-by: Mattermod --- api4/system.go | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/api4/system.go b/api4/system.go index d1d2d0aade..52178519e0 100644 --- a/api4/system.go +++ b/api4/system.go @@ -196,11 +196,9 @@ func getSystemPing(c *Context, w http.ResponseWriter, r *http.Request) { } func testEmail(c *Context, w http.ResponseWriter, r *http.Request) { - var cfg *model.Config - jsonErr := json.NewDecoder(r.Body).Decode(&cfg) - if jsonErr != nil { - c.Err = model.NewAppError("testEmail", "api.unmarshal_error", nil, jsonErr.Error(), http.StatusBadRequest) - return + cfg := model.ConfigFromJSON(r.Body) + if cfg == nil { + cfg = c.App.Config() } if checkHasNilFields(&cfg.EmailSettings) { @@ -454,11 +452,9 @@ func getSupportedTimezones(c *Context, w http.ResponseWriter, r *http.Request) { } func testS3(c *Context, w http.ResponseWriter, r *http.Request) { - var cfg *model.Config - jsonErr := json.NewDecoder(r.Body).Decode(&cfg) - if jsonErr != nil { - c.Err = model.NewAppError("testS3", "api.unmarshal_error", nil, jsonErr.Error(), http.StatusBadRequest) - return + cfg := model.ConfigFromJSON(r.Body) + if cfg == nil { + cfg = c.App.Config() } if checkHasNilFields(&cfg.FileSettings) {