##// END OF EJS Templates
fixed ldap settings
marcink -
r1144:cf5761b3 default
parent child Browse files
Show More
@@ -1,102 +1,105 b''
1 # -*- coding: utf-8 -*-
1 # -*- coding: utf-8 -*-
2 """
2 """
3 rhodecode.model.settings
3 rhodecode.model.settings
4 ~~~~~~~~~~~~~~~~~~~~~~~~
4 ~~~~~~~~~~~~~~~~~~~~~~~~
5
5
6 Settings model for RhodeCode
6 Settings model for RhodeCode
7
7
8 :created on Nov 17, 2010
8 :created on Nov 17, 2010
9 :author: marcink
9 :author: marcink
10 :copyright: (C) 2009-2011 Marcin Kuzminski <marcin@python-works.com>
10 :copyright: (C) 2009-2011 Marcin Kuzminski <marcin@python-works.com>
11 :license: GPLv3, see COPYING for more details.
11 :license: GPLv3, see COPYING for more details.
12 """
12 """
13 # This program is free software; you can redistribute it and/or
13 # This program is free software; you can redistribute it and/or
14 # modify it under the terms of the GNU General Public License
14 # modify it under the terms of the GNU General Public License
15 # as published by the Free Software Foundation; version 2
15 # as published by the Free Software Foundation; version 2
16 # of the License or (at your opinion) any later version of the license.
16 # of the License or (at your opinion) any later version of the license.
17 #
17 #
18 # This program is distributed in the hope that it will be useful,
18 # This program is distributed in the hope that it will be useful,
19 # but WITHOUT ANY WARRANTY; without even the implied warranty of
19 # but WITHOUT ANY WARRANTY; without even the implied warranty of
20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 # GNU General Public License for more details.
21 # GNU General Public License for more details.
22 #
22 #
23 # You should have received a copy of the GNU General Public License
23 # You should have received a copy of the GNU General Public License
24 # along with this program; if not, write to the Free Software
24 # along with this program; if not, write to the Free Software
25 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
25 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
26 # MA 02110-1301, USA.
26 # MA 02110-1301, USA.
27
27
28 import logging
28 import logging
29
29
30 from rhodecode.model import BaseModel
30 from rhodecode.model import BaseModel
31 from rhodecode.model.caching_query import FromCache
31 from rhodecode.model.caching_query import FromCache
32 from rhodecode.model.db import RhodeCodeSettings
32 from rhodecode.model.db import RhodeCodeSettings
33
33
34 log = logging.getLogger(__name__)
34 log = logging.getLogger(__name__)
35
35
36 class SettingsModel(BaseModel):
36 class SettingsModel(BaseModel):
37 """
37 """
38 Settings model
38 Settings model
39 """
39 """
40
40
41 def get(self, settings_key, cache=False):
41 def get(self, settings_key, cache=False):
42 r = self.sa.query(RhodeCodeSettings)\
42 r = self.sa.query(RhodeCodeSettings)\
43 .filter(RhodeCodeSettings.app_settings_name == settings_key).scalar()
43 .filter(RhodeCodeSettings.app_settings_name == settings_key).scalar()
44 if cache:
44 if cache:
45 r = r.options(FromCache("sql_cache_short",
45 r = r.options(FromCache("sql_cache_short",
46 "get_setting_%s" % settings_key))
46 "get_setting_%s" % settings_key))
47 return r
47 return r
48
48
49 def get_app_settings(self, cache=False):
49 def get_app_settings(self, cache=False):
50 """Get's config from database, each config key is prefixed with
50 """Get's config from database, each config key is prefixed with
51 'rhodecode_' prefix, than global pylons config is updated with such
51 'rhodecode_' prefix, than global pylons config is updated with such
52 keys
52 keys
53 """
53 """
54
54
55 ret = self.sa.query(RhodeCodeSettings)
55 ret = self.sa.query(RhodeCodeSettings)
56
56
57 if cache:
57 if cache:
58 ret = ret.options(FromCache("sql_cache_short", "get_hg_settings"))
58 ret = ret.options(FromCache("sql_cache_short", "get_hg_settings"))
59
59
60 if not ret:
60 if not ret:
61 raise Exception('Could not get application settings !')
61 raise Exception('Could not get application settings !')
62 settings = {}
62 settings = {}
63 for each in ret:
63 for each in ret:
64 settings['rhodecode_' + each.app_settings_name] = each.app_settings_value
64 settings['rhodecode_' + each.app_settings_name] = each.app_settings_value
65
65
66 return settings
66 return settings
67
67
68 def get_ldap_settings(self):
68 def get_ldap_settings(self):
69 """
69 """
70 Returns ldap settings from database
70 Returns ldap settings from database
71 :returns:
71 :returns:
72 ldap_active
72 ldap_active
73 ldap_host
73 ldap_host
74 ldap_port
74 ldap_port
75 ldap_ldaps
75 ldap_ldaps
76 ldap_tls_reqcert
76 ldap_tls_reqcert
77 ldap_dn_user
77 ldap_dn_user
78 ldap_dn_pass
78 ldap_dn_pass
79 ldap_base_dn
79 ldap_base_dn
80 ldap_filter
80 ldap_filter
81 ldap_search_scope
81 ldap_search_scope
82 ldap_attr_login
82 ldap_attr_login
83 ldap_attr_firstname
83 ldap_attr_firstname
84 ldap_attr_lastname
84 ldap_attr_lastname
85 ldap_attr_email
85 ldap_attr_email
86 """
86 """
87 # ldap_search_scope
87 # ldap_search_scope
88
88
89 r = self.sa.query(RhodeCodeSettings)\
89 r = self.sa.query(RhodeCodeSettings)\
90 .filter(RhodeCodeSettings.app_settings_name\
90 .filter(RhodeCodeSettings.app_settings_name\
91 .startswith('ldap_'))\
91 .startswith('ldap_'))\
92 .all()
92 .all()
93
93
94 fd = {}
94 fd = {}
95
95
96 for row in r:
96 for row in r:
97 v = row.app_settings_value
97 v = row.app_settings_value
98 if v in ['0', '1']:
98 if v in ['true', 'yes', 'on', 'y', 't', '1']:
99 v = v == '1'
99 v = True
100 elif v in ['false', 'no', 'off', 'n', 'f', '0']:
101 v = False
102
100 fd.update({row.app_settings_name:v})
103 fd.update({row.app_settings_name:v})
101
104
102 return fd
105 return fd
General Comments 0
You need to be logged in to leave comments. Login now