MM-9804: emit defaults for all enterprise config (#8490)
* MM-9804: emit defaults for all enterprise config This prevents the client from having to write inverted checks if a certain value defaults as `'true'` instead of `'false'`. * move EnableMobileFile(Upload|Download) to a defaulted enterprise configuration
Этот коммит содержится в:
коммит произвёл
Christopher Speller
родитель
74e703f58d
Коммит
6036ddad85
@@ -408,8 +408,6 @@ func GenerateClientConfig(c *model.Config, diagnosticId string, license *model.L
|
||||
props["SupportEmail"] = *c.SupportSettings.SupportEmail
|
||||
|
||||
props["EnableFileAttachments"] = strconv.FormatBool(*c.FileSettings.EnableFileAttachments)
|
||||
props["EnableMobileFileUpload"] = strconv.FormatBool(*c.FileSettings.EnableMobileUpload)
|
||||
props["EnableMobileFileDownload"] = strconv.FormatBool(*c.FileSettings.EnableMobileDownload)
|
||||
props["EnablePublicLink"] = strconv.FormatBool(c.FileSettings.EnablePublicLink)
|
||||
|
||||
props["WebsocketPort"] = fmt.Sprintf("%v", *c.ServiceSettings.WebsocketPort)
|
||||
@@ -443,8 +441,55 @@ func GenerateClientConfig(c *model.Config, diagnosticId string, license *model.L
|
||||
hasImageProxy := c.ServiceSettings.ImageProxyType != nil && *c.ServiceSettings.ImageProxyType != "" && c.ServiceSettings.ImageProxyURL != nil && *c.ServiceSettings.ImageProxyURL != ""
|
||||
props["HasImageProxy"] = strconv.FormatBool(hasImageProxy)
|
||||
|
||||
// Set default values for all options that require a license.
|
||||
props["ExperimentalTownSquareIsReadOnly"] = "false"
|
||||
props["ExperimentalEnableAuthenticationTransfer"] = "true"
|
||||
props["EnableCustomBrand"] = "false"
|
||||
props["CustomBrandText"] = ""
|
||||
props["CustomDescriptionText"] = ""
|
||||
props["EnableLdap"] = "false"
|
||||
props["LdapLoginFieldName"] = ""
|
||||
props["LdapNicknameAttributeSet"] = "false"
|
||||
props["LdapFirstNameAttributeSet"] = "false"
|
||||
props["LdapLastNameAttributeSet"] = "false"
|
||||
props["LdapLoginButtonColor"] = ""
|
||||
props["LdapLoginButtonBorderColor"] = ""
|
||||
props["LdapLoginButtonTextColor"] = ""
|
||||
props["EnableMultifactorAuthentication"] = "false"
|
||||
props["EnforceMultifactorAuthentication"] = "false"
|
||||
props["EnableCompliance"] = "false"
|
||||
props["EnableMobileFileDownload"] = "true"
|
||||
props["EnableMobileFileUpload"] = "true"
|
||||
props["EnableSaml"] = "false"
|
||||
props["SamlLoginButtonText"] = ""
|
||||
props["SamlFirstNameAttributeSet"] = "false"
|
||||
props["SamlLastNameAttributeSet"] = "false"
|
||||
props["SamlNicknameAttributeSet"] = "false"
|
||||
props["SamlLoginButtonColor"] = ""
|
||||
props["SamlLoginButtonBorderColor"] = ""
|
||||
props["SamlLoginButtonTextColor"] = ""
|
||||
props["EnableCluster"] = "false"
|
||||
props["EnableMetrics"] = "false"
|
||||
props["EnableSignUpWithGoogle"] = "false"
|
||||
props["EnableSignUpWithOffice365"] = "false"
|
||||
props["PasswordMinimumLength"] = "0"
|
||||
props["PasswordRequireLowercase"] = "false"
|
||||
props["PasswordRequireUppercase"] = "false"
|
||||
props["PasswordRequireNumber"] = "false"
|
||||
props["PasswordRequireSymbol"] = "false"
|
||||
props["EnableBanner"] = "false"
|
||||
props["BannerText"] = ""
|
||||
props["BannerColor"] = ""
|
||||
props["BannerTextColor"] = ""
|
||||
props["AllowBannerDismissal"] = "false"
|
||||
props["EnableThemeSelection"] = "true"
|
||||
props["DefaultTheme"] = ""
|
||||
props["AllowCustomThemes"] = "true"
|
||||
props["AllowedThemes"] = ""
|
||||
props["DataRetentionEnableMessageDeletion"] = "false"
|
||||
props["DataRetentionMessageRetentionDays"] = "0"
|
||||
props["DataRetentionEnableFileDeletion"] = "false"
|
||||
props["DataRetentionFileRetentionDays"] = "0"
|
||||
|
||||
if license != nil {
|
||||
props["ExperimentalTownSquareIsReadOnly"] = strconv.FormatBool(*c.TeamSettings.ExperimentalTownSquareIsReadOnly)
|
||||
@@ -474,6 +519,8 @@ func GenerateClientConfig(c *model.Config, diagnosticId string, license *model.L
|
||||
|
||||
if *license.Features.Compliance {
|
||||
props["EnableCompliance"] = strconv.FormatBool(*c.ComplianceSettings.Enable)
|
||||
props["EnableMobileFileDownload"] = strconv.FormatBool(*c.FileSettings.EnableMobileDownload)
|
||||
props["EnableMobileFileUpload"] = strconv.FormatBool(*c.FileSettings.EnableMobileUpload)
|
||||
}
|
||||
|
||||
if *license.Features.SAML {
|
||||
|
||||
@@ -12,6 +12,8 @@ import (
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/mattermost/mattermost-server/model"
|
||||
)
|
||||
|
||||
func TestConfig(t *testing.T) {
|
||||
@@ -202,14 +204,97 @@ func TestValidateLocales(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGetClientConfig(t *testing.T) {
|
||||
TranslationsPreInit()
|
||||
cfg, _, err := LoadConfig("config.json")
|
||||
require.Nil(t, err)
|
||||
|
||||
configMap := GenerateClientConfig(cfg, "", nil)
|
||||
if configMap["EmailNotificationContentsType"] != *cfg.EmailSettings.EmailNotificationContentsType {
|
||||
t.Fatal("EmailSettings.EmailNotificationContentsType not exposed to client config")
|
||||
t.Parallel()
|
||||
testCases := []struct {
|
||||
description string
|
||||
config *model.Config
|
||||
diagnosticId string
|
||||
license *model.License
|
||||
expectedFields map[string]string
|
||||
}{
|
||||
{
|
||||
"unlicensed",
|
||||
&model.Config{
|
||||
EmailSettings: model.EmailSettings{
|
||||
EmailNotificationContentsType: sToP(model.EMAIL_NOTIFICATION_CONTENTS_FULL),
|
||||
},
|
||||
ThemeSettings: model.ThemeSettings{
|
||||
// Ignored, since not licensed.
|
||||
AllowCustomThemes: bToP(false),
|
||||
},
|
||||
},
|
||||
"",
|
||||
nil,
|
||||
map[string]string{
|
||||
"DiagnosticId": "",
|
||||
"EmailNotificationContentsType": "full",
|
||||
"AllowCustomThemes": "true",
|
||||
},
|
||||
},
|
||||
{
|
||||
"licensed, but not for theme management",
|
||||
&model.Config{
|
||||
EmailSettings: model.EmailSettings{
|
||||
EmailNotificationContentsType: sToP(model.EMAIL_NOTIFICATION_CONTENTS_FULL),
|
||||
},
|
||||
ThemeSettings: model.ThemeSettings{
|
||||
// Ignored, since not licensed.
|
||||
AllowCustomThemes: bToP(false),
|
||||
},
|
||||
},
|
||||
"tag1",
|
||||
&model.License{
|
||||
Features: &model.Features{
|
||||
ThemeManagement: bToP(false),
|
||||
},
|
||||
},
|
||||
map[string]string{
|
||||
"DiagnosticId": "tag1",
|
||||
"EmailNotificationContentsType": "full",
|
||||
"AllowCustomThemes": "true",
|
||||
},
|
||||
},
|
||||
{
|
||||
"licensed for theme management",
|
||||
&model.Config{
|
||||
EmailSettings: model.EmailSettings{
|
||||
EmailNotificationContentsType: sToP(model.EMAIL_NOTIFICATION_CONTENTS_FULL),
|
||||
},
|
||||
ThemeSettings: model.ThemeSettings{
|
||||
AllowCustomThemes: bToP(false),
|
||||
},
|
||||
},
|
||||
"tag2",
|
||||
&model.License{
|
||||
Features: &model.Features{
|
||||
ThemeManagement: bToP(true),
|
||||
},
|
||||
},
|
||||
map[string]string{
|
||||
"DiagnosticId": "tag2",
|
||||
"EmailNotificationContentsType": "full",
|
||||
"AllowCustomThemes": "false",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, testCase := range testCases {
|
||||
testCase := testCase
|
||||
t.Run(testCase.description, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
testCase.config.SetDefaults()
|
||||
if testCase.license != nil {
|
||||
testCase.license.Features.SetDefaults()
|
||||
}
|
||||
|
||||
configMap := GenerateClientConfig(testCase.config, testCase.diagnosticId, testCase.license)
|
||||
for expectedField, expectedValue := range testCase.expectedFields {
|
||||
assert.Equal(t, expectedValue, configMap[expectedField])
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func TestReadConfig(t *testing.T) {
|
||||
@@ -222,3 +307,11 @@ func TestReadConfig(t *testing.T) {
|
||||
|
||||
assert.Equal(t, "http://foo.bar", *config.ServiceSettings.SiteURL)
|
||||
}
|
||||
|
||||
func sToP(s string) *string {
|
||||
return &s
|
||||
}
|
||||
|
||||
func bToP(b bool) *bool {
|
||||
return &b
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user