[MM-13694] Sets a default value for SiteName if empty (#10406)
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
1e462da2d4
Коммит
04467b8dc9
@@ -4398,6 +4398,10 @@
|
||||
"id": "model.config.is_valid.sitename_length.app_error",
|
||||
"translation": "Site name must be less than or equal to {{.MaxLength}} characters."
|
||||
},
|
||||
{
|
||||
"id": "model.config.is_valid.sitename_empty.app_error",
|
||||
"translation": "Site name cannot be empty."
|
||||
},
|
||||
{
|
||||
"id": "model.config.is_valid.sql_conn_max_lifetime_milliseconds.app_error",
|
||||
"translation": "Invalid connection maximum lifetime for SQL settings. Must be a non-negative number."
|
||||
|
||||
@@ -1394,7 +1394,7 @@ type TeamSettings struct {
|
||||
|
||||
func (s *TeamSettings) SetDefaults() {
|
||||
|
||||
if s.SiteName == nil {
|
||||
if s.SiteName == nil || *s.SiteName == "" {
|
||||
s.SiteName = NewString(TEAM_SETTINGS_DEFAULT_SITE_NAME)
|
||||
}
|
||||
|
||||
@@ -2395,6 +2395,10 @@ func (ts *TeamSettings) isValid() *AppError {
|
||||
return NewAppError("Config.IsValid", "model.config.is_valid.teammate_name_display.app_error", nil, "", http.StatusBadRequest)
|
||||
}
|
||||
|
||||
if len(*ts.SiteName) == 0 {
|
||||
return NewAppError("Config.IsValid", "model.config.is_valid.sitename_empty.app_error", nil, "", http.StatusBadRequest)
|
||||
}
|
||||
|
||||
if len(*ts.SiteName) > SITENAME_MAX_LENGTH {
|
||||
return NewAppError("Config.IsValid", "model.config.is_valid.sitename_length.app_error", map[string]interface{}{"MaxLength": SITENAME_MAX_LENGTH}, "", http.StatusBadRequest)
|
||||
}
|
||||
|
||||
@@ -55,6 +55,19 @@ func TestConfigDefaults(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
func TestConfigEmptySiteName(t *testing.T) {
|
||||
c1 := Config{
|
||||
TeamSettings: TeamSettings{
|
||||
SiteName: NewString(""),
|
||||
},
|
||||
}
|
||||
c1.SetDefaults()
|
||||
|
||||
if *c1.TeamSettings.SiteName != TEAM_SETTINGS_DEFAULT_SITE_NAME {
|
||||
t.Fatal("TeamSettings.SiteName should default to " + TEAM_SETTINGS_DEFAULT_SITE_NAME)
|
||||
}
|
||||
}
|
||||
|
||||
func TestConfigDefaultFileSettingsDirectory(t *testing.T) {
|
||||
c1 := Config{}
|
||||
c1.SetDefaults()
|
||||
@@ -114,6 +127,18 @@ func TestConfigDefaultServiceSettingsExperimentalGroupUnreadChannels(t *testing.
|
||||
}
|
||||
}
|
||||
|
||||
func TestTeamSettingsIsValidSiteNameEmpty(t *testing.T) {
|
||||
c1 := Config{}
|
||||
c1.SetDefaults()
|
||||
c1.TeamSettings.SiteName = NewString("")
|
||||
|
||||
// should fail fast because ts.SiteName is not set
|
||||
err := c1.TeamSettings.isValid()
|
||||
if err == nil {
|
||||
t.Fatal("TeamSettings validation should fail with an empty SiteName")
|
||||
}
|
||||
}
|
||||
|
||||
func TestMessageExportSettingsIsValidEnableExportNotSet(t *testing.T) {
|
||||
fs := &FileSettings{}
|
||||
mes := &MessageExportSettings{}
|
||||
|
||||
Ссылка в новой задаче
Block a user