(c *Context, w http.ResponseWriter, r *http.Request)
| 97 | } |
| 98 | |
| 99 | func localPatchConfig(c *Context, w http.ResponseWriter, r *http.Request) { |
| 100 | var cfg *model.Config |
| 101 | err := json.NewDecoder(r.Body).Decode(&cfg) |
| 102 | if err != nil || cfg == nil { |
| 103 | c.SetInvalidParamWithErr("config", err) |
| 104 | return |
| 105 | } |
| 106 | |
| 107 | auditRec := c.MakeAuditRecord(model.AuditEventLocalPatchConfig, model.AuditStatusFail) |
| 108 | defer c.LogAuditRec(auditRec) |
| 109 | |
| 110 | appCfg := c.App.Config() |
| 111 | filterFn := func(structField reflect.StructField, base, patch reflect.Value) bool { |
| 112 | return true |
| 113 | } |
| 114 | |
| 115 | if cfg.MessageExportSettings.EnableExport != nil { |
| 116 | c.App.HandleMessageExportConfig(cfg, appCfg) |
| 117 | } |
| 118 | |
| 119 | // Treating an empty plugins map as nil preserves the existing configs. |
| 120 | if len(cfg.PluginSettings.Plugins) == 0 { |
| 121 | cfg.PluginSettings.Plugins = nil |
| 122 | } |
| 123 | |
| 124 | updatedCfg, mergeErr := config.Merge(appCfg, cfg, &utils.MergeConfig{ |
| 125 | StructFieldFilter: filterFn, |
| 126 | }) |
| 127 | |
| 128 | if mergeErr != nil { |
| 129 | c.Err = model.NewAppError("patchConfig", "api.config.update_config.restricted_merge.app_error", nil, "", http.StatusInternalServerError).Wrap(mergeErr) |
| 130 | return |
| 131 | } |
| 132 | |
| 133 | appErr := updatedCfg.IsValid() |
| 134 | if appErr != nil { |
| 135 | c.Err = appErr |
| 136 | return |
| 137 | } |
| 138 | |
| 139 | oldCfg, newCfg, appErr := c.App.SaveConfig(updatedCfg, true) |
| 140 | if appErr != nil { |
| 141 | c.Err = appErr |
| 142 | return |
| 143 | } |
| 144 | |
| 145 | diffs, err := config.Diff(oldCfg, newCfg) |
| 146 | if err != nil { |
| 147 | c.Err = model.NewAppError("patchConfig", "api.config.patch_config.diff.app_error", nil, "", http.StatusInternalServerError).Wrap(err) |
| 148 | return |
| 149 | } |
| 150 | auditRec.AddEventPriorState(&diffs) |
| 151 | |
| 152 | auditRec.Success() |
| 153 | |
| 154 | w.Header().Set("Cache-Control", "no-cache, no-store, must-revalidate") |
| 155 | if err := json.NewEncoder(w).Encode(c.App.GetSanitizedConfig()); err != nil { |
| 156 | c.Logger.Warn("Error while writing response", mlog.Err(err)) |
nothing calls this directly
no test coverage detected
searching dependent graphs…