MM-41569: Prevent compliance directory to be changed on cloud instances (#20198)

https://mattermost.atlassian.net/browse/MM-41659

```release-note
NONE
```
Этот коммит содержится в:
Agniva De Sarker
2022-05-13 14:14:26 +05:30
коммит произвёл GitHub
родитель bcd65c513b
Коммит 6e574aefd0
2 изменённых файлов: 30 добавлений и 0 удалений

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

@@ -152,6 +152,16 @@ func updateConfig(c *Context, w http.ResponseWriter, r *http.Request) {
*cfg.PluginSettings.MarketplaceURL = *appCfg.PluginSettings.MarketplaceURL
}
// There are some settings that cannot be changed in a cloud env
if c.App.Channels().License() != nil && *c.App.Channels().License().Features.Cloud {
// Both of them cannot be nil since cfg.SetDefaults is called earlier for cfg,
// and appCfg is the existing earlier config and if it's nil, server sets a default value.
if *appCfg.ComplianceSettings.Directory != *cfg.ComplianceSettings.Directory {
c.Err = model.NewAppError("updateConfig", "api.config.update_config.not_allowed_security.app_error", map[string]interface{}{"Name": "ComplianceSettings.Directory"}, "", http.StatusForbidden)
return
}
}
c.App.HandleMessageExportConfig(cfg, appCfg)
if err := cfg.IsValid(); err != nil {
@@ -276,6 +286,14 @@ func patchConfig(c *Context, w http.ResponseWriter, r *http.Request) {
}
}
// There are some settings that cannot be changed in a cloud env
if c.App.Channels().License() != nil && *c.App.Channels().License().Features.Cloud {
if cfg.ComplianceSettings.Directory != nil && *appCfg.ComplianceSettings.Directory != *cfg.ComplianceSettings.Directory {
c.Err = model.NewAppError("patchConfig", "api.config.update_config.not_allowed_security.app_error", map[string]interface{}{"Name": "ComplianceSettings.Directory"}, "", http.StatusForbidden)
return
}
}
if cfg.MessageExportSettings.EnableExport != nil {
c.App.HandleMessageExportConfig(cfg, appCfg)
}