diff --git a/rhodecode/lib/__init__.py b/rhodecode/lib/__init__.py --- a/rhodecode/lib/__init__.py +++ b/rhodecode/lib/__init__.py @@ -26,7 +26,16 @@ # MA 02110-1301, USA. def str2bool(v): - return v.lower() in ["yes", "true", "t", "1"] if v else None + if isinstance(v, (str, unicode)): + obj = v.strip().lower() + if obj in ['true', 'yes', 'on', 'y', 't', '1']: + return True + elif obj in ['false', 'no', 'off', 'n', 'f', '0']: + return False + else: + if not safe: + raise ValueError("String is not true/false: %r" % obj) + return bool(obj) def generate_api_key(username, salt=None): from tempfile import _RandomNameSequence diff --git a/rhodecode/lib/auth.py b/rhodecode/lib/auth.py --- a/rhodecode/lib/auth.py +++ b/rhodecode/lib/auth.py @@ -43,7 +43,7 @@ if __platform__ == 'Windows': if __platform__ in ('Linux', 'Darwin'): import bcrypt - +from rhodecode.lib import str2bool from rhodecode.lib.exceptions import LdapPasswordError, LdapUsernameError from rhodecode.lib.utils import get_repo_slug from rhodecode.lib.auth_ldap import AuthLdap @@ -179,7 +179,7 @@ def authenticate(username, password): #====================================================================== # FALLBACK TO LDAP AUTH IF ENABLE #====================================================================== - if ldap_settings.get('ldap_active', False): + if str2bool(ldap_settings.get('ldap_active')): log.debug("Authenticating user using ldap") kwargs = { 'server':ldap_settings.get('ldap_host', ''), @@ -187,7 +187,7 @@ def authenticate(username, password): 'port':ldap_settings.get('ldap_port'), 'bind_dn':ldap_settings.get('ldap_dn_user'), 'bind_pass':ldap_settings.get('ldap_dn_pass'), - 'use_ldaps':ldap_settings.get('ldap_ldaps'), + 'use_ldaps':str2bool(ldap_settings.get('ldap_ldaps')), 'tls_reqcert':ldap_settings.get('ldap_tls_reqcert'), 'ldap_filter':ldap_settings.get('ldap_filter'), 'search_scope':ldap_settings.get('ldap_search_scope'), diff --git a/rhodecode/model/settings.py b/rhodecode/model/settings.py --- a/rhodecode/model/settings.py +++ b/rhodecode/model/settings.py @@ -95,8 +95,11 @@ class SettingsModel(BaseModel): for row in r: v = row.app_settings_value - if v in ['0', '1']: - v = v == '1' + if v in ['true', 'yes', 'on', 'y', 't', '1']: + v = True + elif v in ['false', 'no', 'off', 'n', 'f', '0']: + v = False + fd.update({row.app_settings_name:v}) return fd