[PLT-7231/PLT-7306] Fix GitLab SSO failure with non-English locale and make config locales more forgiving (#7125)
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
2ab2baba58
Коммит
9f3713aa98
@@ -343,7 +343,12 @@ func LoadConfig(fileName string) {
|
||||
}
|
||||
|
||||
if err := ValidateLocales(&config); err != nil {
|
||||
panic(T(err.Id))
|
||||
cfgMutex.Unlock()
|
||||
if err := SaveConfig(CfgFileName, &config); err != nil {
|
||||
err.Translate(T)
|
||||
l4g.Warn(err.Error())
|
||||
}
|
||||
cfgMutex.Lock()
|
||||
}
|
||||
|
||||
if err := ValidateLdapFilter(&config); err != nil {
|
||||
@@ -562,26 +567,44 @@ func ValidateLdapFilter(cfg *model.Config) *model.AppError {
|
||||
}
|
||||
|
||||
func ValidateLocales(cfg *model.Config) *model.AppError {
|
||||
var err *model.AppError
|
||||
locales := GetSupportedLocales()
|
||||
if _, ok := locales[*cfg.LocalizationSettings.DefaultServerLocale]; !ok {
|
||||
return model.NewLocAppError("ValidateLocales", "utils.config.supported_server_locale.app_error", nil, "")
|
||||
*cfg.LocalizationSettings.DefaultServerLocale = model.DEFAULT_LOCALE
|
||||
err = model.NewLocAppError("ValidateLocales", "utils.config.supported_server_locale.app_error", nil, "")
|
||||
}
|
||||
|
||||
if _, ok := locales[*cfg.LocalizationSettings.DefaultClientLocale]; !ok {
|
||||
return model.NewLocAppError("ValidateLocales", "utils.config.supported_client_locale.app_error", nil, "")
|
||||
*cfg.LocalizationSettings.DefaultClientLocale = model.DEFAULT_LOCALE
|
||||
err = model.NewLocAppError("ValidateLocales", "utils.config.supported_client_locale.app_error", nil, "")
|
||||
}
|
||||
|
||||
if len(*cfg.LocalizationSettings.AvailableLocales) > 0 {
|
||||
isDefaultClientLocaleInAvailableLocales := false
|
||||
for _, word := range strings.Split(*cfg.LocalizationSettings.AvailableLocales, ",") {
|
||||
if _, ok := locales[word]; !ok {
|
||||
*cfg.LocalizationSettings.AvailableLocales = ""
|
||||
isDefaultClientLocaleInAvailableLocales = true
|
||||
err = model.NewLocAppError("ValidateLocales", "utils.config.supported_available_locales.app_error", nil, "")
|
||||
break
|
||||
}
|
||||
|
||||
if word == *cfg.LocalizationSettings.DefaultClientLocale {
|
||||
return nil
|
||||
isDefaultClientLocaleInAvailableLocales = true
|
||||
}
|
||||
}
|
||||
|
||||
return model.NewLocAppError("ValidateLocales", "utils.config.validate_locale.app_error", nil, "")
|
||||
availableLocales := *cfg.LocalizationSettings.AvailableLocales
|
||||
|
||||
if !isDefaultClientLocaleInAvailableLocales {
|
||||
availableLocales += "," + *cfg.LocalizationSettings.DefaultClientLocale
|
||||
err = model.NewLocAppError("ValidateLocales", "utils.config.add_client_locale.app_error", nil, "")
|
||||
}
|
||||
|
||||
*cfg.LocalizationSettings.AvailableLocales = strings.Join(RemoveDuplicatesFromStringArray(strings.Split(availableLocales, ",")), ",")
|
||||
}
|
||||
|
||||
return nil
|
||||
return err
|
||||
}
|
||||
|
||||
func Desanitize(cfg *model.Config) {
|
||||
|
||||
Ссылка в новой задаче
Block a user