annotate rhodecode/model/settings.py @ 1015:65129c332d37 beta

#56 added ajax removal of users groups, fixed permission edition templates by regular non admin users found bugfixes in forms for users groups
author Marcin Kuzminski <marcin@python-works.com>
date Wed, 09 Feb 2011 17:41:27 +0100
parents 551c7d5ae89d
children 1aa1655bf019
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1012
551c7d5ae89d #56 added users/groups autocomplete for repository editing.
Marcin Kuzminski <marcin@python-works.com>
parents: 991
diff changeset
1 # -*- coding: utf-8 -*-
551c7d5ae89d #56 added users/groups autocomplete for repository editing.
Marcin Kuzminski <marcin@python-works.com>
parents: 991
diff changeset
2 """
551c7d5ae89d #56 added users/groups autocomplete for repository editing.
Marcin Kuzminski <marcin@python-works.com>
parents: 991
diff changeset
3 rhodecode.model.settings
551c7d5ae89d #56 added users/groups autocomplete for repository editing.
Marcin Kuzminski <marcin@python-works.com>
parents: 991
diff changeset
4 ~~~~~~~~~~~~~~~~~~~~~~~~
551c7d5ae89d #56 added users/groups autocomplete for repository editing.
Marcin Kuzminski <marcin@python-works.com>
parents: 991
diff changeset
5
551c7d5ae89d #56 added users/groups autocomplete for repository editing.
Marcin Kuzminski <marcin@python-works.com>
parents: 991
diff changeset
6 Settings model for RhodeCode
551c7d5ae89d #56 added users/groups autocomplete for repository editing.
Marcin Kuzminski <marcin@python-works.com>
parents: 991
diff changeset
7
551c7d5ae89d #56 added users/groups autocomplete for repository editing.
Marcin Kuzminski <marcin@python-works.com>
parents: 991
diff changeset
8 :created on Nov 17, 2010
551c7d5ae89d #56 added users/groups autocomplete for repository editing.
Marcin Kuzminski <marcin@python-works.com>
parents: 991
diff changeset
9 :author: marcink
551c7d5ae89d #56 added users/groups autocomplete for repository editing.
Marcin Kuzminski <marcin@python-works.com>
parents: 991
diff changeset
10 :copyright: (C) 2009-2011 Marcin Kuzminski <marcin@python-works.com>
551c7d5ae89d #56 added users/groups autocomplete for repository editing.
Marcin Kuzminski <marcin@python-works.com>
parents: 991
diff changeset
11 :license: GPLv3, see COPYING for more details.
551c7d5ae89d #56 added users/groups autocomplete for repository editing.
Marcin Kuzminski <marcin@python-works.com>
parents: 991
diff changeset
12 """
704
26237de9b613 Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
13 # This program is free software; you can redistribute it and/or
26237de9b613 Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
14 # modify it under the terms of the GNU General Public License
26237de9b613 Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
15 # as published by the Free Software Foundation; version 2
26237de9b613 Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
16 # of the License or (at your opinion) any later version of the license.
26237de9b613 Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
17 #
26237de9b613 Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
18 # This program is distributed in the hope that it will be useful,
26237de9b613 Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
19 # but WITHOUT ANY WARRANTY; without even the implied warranty of
26237de9b613 Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26237de9b613 Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
21 # GNU General Public License for more details.
26237de9b613 Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
22 #
26237de9b613 Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
23 # You should have received a copy of the GNU General Public License
26237de9b613 Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
24 # along with this program; if not, write to the Free Software
26237de9b613 Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
25 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
26237de9b613 Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
26 # MA 02110-1301, USA.
752
89b9037d68b7 fixed Example celery config to ampq,
Marcin Kuzminski <marcin@python-works.com>
parents: 705
diff changeset
27
1012
551c7d5ae89d #56 added users/groups autocomplete for repository editing.
Marcin Kuzminski <marcin@python-works.com>
parents: 991
diff changeset
28 import logging
551c7d5ae89d #56 added users/groups autocomplete for repository editing.
Marcin Kuzminski <marcin@python-works.com>
parents: 991
diff changeset
29
752
89b9037d68b7 fixed Example celery config to ampq,
Marcin Kuzminski <marcin@python-works.com>
parents: 705
diff changeset
30 from rhodecode.model import BaseModel
704
26237de9b613 Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
31 from rhodecode.model.caching_query import FromCache
26237de9b613 Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
32 from rhodecode.model.db import RhodeCodeSettings
26237de9b613 Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
33
26237de9b613 Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
34 log = logging.getLogger(__name__)
26237de9b613 Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
35
752
89b9037d68b7 fixed Example celery config to ampq,
Marcin Kuzminski <marcin@python-works.com>
parents: 705
diff changeset
36 class SettingsModel(BaseModel):
704
26237de9b613 Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
37 """
26237de9b613 Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
38 Settings model
26237de9b613 Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
39 """
26237de9b613 Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
40
26237de9b613 Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
41 def get(self, settings_key, cache=False):
26237de9b613 Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
42 r = self.sa.query(RhodeCodeSettings)\
26237de9b613 Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
43 .filter(RhodeCodeSettings.app_settings_name == settings_key).scalar()
26237de9b613 Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
44 if cache:
26237de9b613 Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
45 r = r.options(FromCache("sql_cache_short",
26237de9b613 Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
46 "get_setting_%s" % settings_key))
26237de9b613 Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
47 return r
26237de9b613 Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
48
892
9adc0c1d9a87 Added optional cache into get_application settings
Marcin Kuzminski <marcin@python-works.com>
parents: 890
diff changeset
49 def get_app_settings(self, cache=False):
890
042d38683d42 implemented #89 google analytics code
Marcin Kuzminski <marcin@python-works.com>
parents: 756
diff changeset
50 """Get's config from database, each config key is prefixed with
042d38683d42 implemented #89 google analytics code
Marcin Kuzminski <marcin@python-works.com>
parents: 756
diff changeset
51 'rhodecode_' prefix, than global pylons config is updated with such
042d38683d42 implemented #89 google analytics code
Marcin Kuzminski <marcin@python-works.com>
parents: 756
diff changeset
52 keys
042d38683d42 implemented #89 google analytics code
Marcin Kuzminski <marcin@python-works.com>
parents: 756
diff changeset
53 """
042d38683d42 implemented #89 google analytics code
Marcin Kuzminski <marcin@python-works.com>
parents: 756
diff changeset
54
892
9adc0c1d9a87 Added optional cache into get_application settings
Marcin Kuzminski <marcin@python-works.com>
parents: 890
diff changeset
55 ret = self.sa.query(RhodeCodeSettings)
9adc0c1d9a87 Added optional cache into get_application settings
Marcin Kuzminski <marcin@python-works.com>
parents: 890
diff changeset
56
9adc0c1d9a87 Added optional cache into get_application settings
Marcin Kuzminski <marcin@python-works.com>
parents: 890
diff changeset
57 if cache:
9adc0c1d9a87 Added optional cache into get_application settings
Marcin Kuzminski <marcin@python-works.com>
parents: 890
diff changeset
58 ret = ret.options(FromCache("sql_cache_short", "get_hg_settings"))
756
01be209b9828 project refactoring, cleaned up lib.utils from rarly used functions, and place them
Marcin Kuzminski <marcin@python-works.com>
parents: 752
diff changeset
59
01be209b9828 project refactoring, cleaned up lib.utils from rarly used functions, and place them
Marcin Kuzminski <marcin@python-works.com>
parents: 752
diff changeset
60 if not ret:
01be209b9828 project refactoring, cleaned up lib.utils from rarly used functions, and place them
Marcin Kuzminski <marcin@python-works.com>
parents: 752
diff changeset
61 raise Exception('Could not get application settings !')
01be209b9828 project refactoring, cleaned up lib.utils from rarly used functions, and place them
Marcin Kuzminski <marcin@python-works.com>
parents: 752
diff changeset
62 settings = {}
01be209b9828 project refactoring, cleaned up lib.utils from rarly used functions, and place them
Marcin Kuzminski <marcin@python-works.com>
parents: 752
diff changeset
63 for each in ret:
01be209b9828 project refactoring, cleaned up lib.utils from rarly used functions, and place them
Marcin Kuzminski <marcin@python-works.com>
parents: 752
diff changeset
64 settings['rhodecode_' + each.app_settings_name] = each.app_settings_value
01be209b9828 project refactoring, cleaned up lib.utils from rarly used functions, and place them
Marcin Kuzminski <marcin@python-works.com>
parents: 752
diff changeset
65
01be209b9828 project refactoring, cleaned up lib.utils from rarly used functions, and place them
Marcin Kuzminski <marcin@python-works.com>
parents: 752
diff changeset
66 return settings
704
26237de9b613 Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
67
26237de9b613 Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
68 def get_ldap_settings(self):
705
9e9f1b919c0c implements #60, ldap configuration and authentication.
Marcin Kuzminski <marcin@python-works.com>
parents: 704
diff changeset
69 """
9e9f1b919c0c implements #60, ldap configuration and authentication.
Marcin Kuzminski <marcin@python-works.com>
parents: 704
diff changeset
70 Returns ldap settings from database
9e9f1b919c0c implements #60, ldap configuration and authentication.
Marcin Kuzminski <marcin@python-works.com>
parents: 704
diff changeset
71 :returns:
9e9f1b919c0c implements #60, ldap configuration and authentication.
Marcin Kuzminski <marcin@python-works.com>
parents: 704
diff changeset
72 ldap_active
9e9f1b919c0c implements #60, ldap configuration and authentication.
Marcin Kuzminski <marcin@python-works.com>
parents: 704
diff changeset
73 ldap_host
9e9f1b919c0c implements #60, ldap configuration and authentication.
Marcin Kuzminski <marcin@python-works.com>
parents: 704
diff changeset
74 ldap_port
9e9f1b919c0c implements #60, ldap configuration and authentication.
Marcin Kuzminski <marcin@python-works.com>
parents: 704
diff changeset
75 ldap_ldaps
991
b232a36cc51f Improve LDAP authentication
Thayne Harbaugh <thayne@fusionio.com>
parents: 902
diff changeset
76 ldap_tls_reqcert
705
9e9f1b919c0c implements #60, ldap configuration and authentication.
Marcin Kuzminski <marcin@python-works.com>
parents: 704
diff changeset
77 ldap_dn_user
9e9f1b919c0c implements #60, ldap configuration and authentication.
Marcin Kuzminski <marcin@python-works.com>
parents: 704
diff changeset
78 ldap_dn_pass
9e9f1b919c0c implements #60, ldap configuration and authentication.
Marcin Kuzminski <marcin@python-works.com>
parents: 704
diff changeset
79 ldap_base_dn
991
b232a36cc51f Improve LDAP authentication
Thayne Harbaugh <thayne@fusionio.com>
parents: 902
diff changeset
80 ldap_filter
b232a36cc51f Improve LDAP authentication
Thayne Harbaugh <thayne@fusionio.com>
parents: 902
diff changeset
81 ldap_search_scope
b232a36cc51f Improve LDAP authentication
Thayne Harbaugh <thayne@fusionio.com>
parents: 902
diff changeset
82 ldap_attr_login
b232a36cc51f Improve LDAP authentication
Thayne Harbaugh <thayne@fusionio.com>
parents: 902
diff changeset
83 ldap_attr_firstname
b232a36cc51f Improve LDAP authentication
Thayne Harbaugh <thayne@fusionio.com>
parents: 902
diff changeset
84 ldap_attr_lastname
b232a36cc51f Improve LDAP authentication
Thayne Harbaugh <thayne@fusionio.com>
parents: 902
diff changeset
85 ldap_attr_email
705
9e9f1b919c0c implements #60, ldap configuration and authentication.
Marcin Kuzminski <marcin@python-works.com>
parents: 704
diff changeset
86 """
991
b232a36cc51f Improve LDAP authentication
Thayne Harbaugh <thayne@fusionio.com>
parents: 902
diff changeset
87 # ldap_search_scope
704
26237de9b613 Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
88
26237de9b613 Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
89 r = self.sa.query(RhodeCodeSettings)\
26237de9b613 Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
90 .filter(RhodeCodeSettings.app_settings_name\
26237de9b613 Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
91 .startswith('ldap_'))\
26237de9b613 Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
92 .all()
26237de9b613 Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
93
26237de9b613 Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
94 fd = {}
26237de9b613 Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
95
26237de9b613 Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
96 for row in r:
26237de9b613 Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
97 v = row.app_settings_value
26237de9b613 Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
98 if v in ['0', '1']:
26237de9b613 Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
99 v = v == '1'
26237de9b613 Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
100 fd.update({row.app_settings_name:v})
26237de9b613 Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
101
26237de9b613 Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
102 return fd