summaryrefslogtreecommitdiffstats
path: root/utils
diff options
context:
space:
mode:
authorenahum <nahumhbl@gmail.com>2017-02-28 06:07:02 -0300
committerGeorge Goldberg <george@gberg.me>2017-02-28 09:07:02 +0000
commit758402311a97a053a5276049db6dce4f8f8dcfbc (patch)
tree4bfdf995e3f2085969ba219fe90f2dcce4c900d4 /utils
parent45edfbe719b87bc6207f88350ff501eff142b28c (diff)
downloadchat-758402311a97a053a5276049db6dce4f8f8dcfbc.tar.gz
chat-758402311a97a053a5276049db6dce4f8f8dcfbc.tar.bz2
chat-758402311a97a053a5276049db6dce4f8f8dcfbc.zip
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
Diffstat (limited to 'utils')
-rw-r--r--utils/config.go27
-rw-r--r--utils/i18n.go4
2 files changed, 31 insertions, 0 deletions
diff --git a/utils/config.go b/utils/config.go
index 0908f2297..fd1597132 100644
--- a/utils/config.go
+++ b/utils/config.go
@@ -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
diff --git a/utils/i18n.go b/utils/i18n.go
index 8366ae75d..5a0bb197f 100644
--- a/utils/i18n.go
+++ b/utils/i18n.go
@@ -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 {