PLT-5548 Prevent server start if defaultLocate is not available (#5532)
* PLT-5548 Prevent server start if defaultLocate is not available * Add validation for supported locales
Этот коммит содержится в:
коммит произвёл
George Goldberg
родитель
45edfbe719
Коммит
758402311a
12
i18n/en.json
12
i18n/en.json
@@ -5619,6 +5619,18 @@
|
||||
"id": "utils.config.save_config.saving.app_error",
|
||||
"translation": "An error occurred while saving the file to {{.Filename}}"
|
||||
},
|
||||
{
|
||||
"id": "utils.config.supported_client_locale.app_error",
|
||||
"translation": "Unable to load mattermost configuration file: DefaultClientLocale must be one of the supported locales"
|
||||
},
|
||||
{
|
||||
"id": "utils.config.supported_server_locale.app_error",
|
||||
"translation": "Unable to load mattermost configuration file: DefaultServerLocale must be one of the supported locales"
|
||||
},
|
||||
{
|
||||
"id": "utils.config.validate_locale.app_error",
|
||||
"translation": "Unable to load mattermost configuration file: AvailableLocales must include DefaultClientLocale"
|
||||
},
|
||||
{
|
||||
"id": "utils.diagnostic.analytics_not_found.app_error",
|
||||
"translation": "Analytics not initialized"
|
||||
|
||||
@@ -196,6 +196,10 @@ func LoadConfig(fileName string) {
|
||||
}
|
||||
}
|
||||
|
||||
if err := ValidateLocales(&config); err != nil {
|
||||
panic(T(err.Id))
|
||||
}
|
||||
|
||||
if err := ValidateLdapFilter(&config); err != nil {
|
||||
panic(T(err.Id))
|
||||
}
|
||||
@@ -387,6 +391,29 @@ func ValidateLdapFilter(cfg *model.Config) *model.AppError {
|
||||
return nil
|
||||
}
|
||||
|
||||
func ValidateLocales(cfg *model.Config) *model.AppError {
|
||||
locales := GetSupportedLocales()
|
||||
if _, ok := locales[*cfg.LocalizationSettings.DefaultServerLocale]; !ok {
|
||||
return 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, "")
|
||||
}
|
||||
|
||||
if len(*cfg.LocalizationSettings.AvailableLocales) > 0 {
|
||||
for _, word := range strings.Split(*cfg.LocalizationSettings.AvailableLocales, ",") {
|
||||
if word == *cfg.LocalizationSettings.DefaultClientLocale {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
return model.NewLocAppError("ValidateLocales", "utils.config.validate_locale.app_error", nil, "")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func Desanitize(cfg *model.Config) {
|
||||
if cfg.LdapSettings.BindPassword != nil && *cfg.LdapSettings.BindPassword == model.FAKE_SETTING {
|
||||
*cfg.LdapSettings.BindPassword = *Cfg.LdapSettings.BindPassword
|
||||
|
||||
@@ -94,6 +94,10 @@ func GetTranslationsAndLocale(w http.ResponseWriter, r *http.Request) (i18n.Tran
|
||||
return translations, model.DEFAULT_LOCALE
|
||||
}
|
||||
|
||||
func GetSupportedLocales() map[string]string {
|
||||
return locales
|
||||
}
|
||||
|
||||
func TfuncWithFallback(pref string) i18n.TranslateFunc {
|
||||
t, _ := i18n.Tfunc(pref)
|
||||
return func(translationID string, args ...interface{}) string {
|
||||
|
||||
Ссылка в новой задаче
Block a user