annotate rhodecode/model/settings.py @ 751:ff881ec6a140 beta

bugfix default permissions settings did not read overwrite setting
author Marcin Kuzminski <marcin@python-works.com>
date Wed, 24 Nov 2010 04:04:13 +0100
parents 9e9f1b919c0c
children 89b9037d68b7
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
704
26237de9b613 Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1 #!/usr/bin/env python
26237de9b613 Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2 # encoding: utf-8
26237de9b613 Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
3 # Model for RhodeCode settings
26237de9b613 Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
4 # Copyright (C) 2009-2010 Marcin Kuzminski <marcin@python-works.com>
26237de9b613 Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
5 #
26237de9b613 Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
6 # 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
7 # 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
8 # 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
9 # 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
10 #
26237de9b613 Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
11 # 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
12 # 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
13 # 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
14 # GNU General Public License for more details.
26237de9b613 Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
15 #
26237de9b613 Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
16 # 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
17 # 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
18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
26237de9b613 Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
19 # MA 02110-1301, USA.
26237de9b613 Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
20 """
26237de9b613 Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
21 Created on Nov 17, 2010
26237de9b613 Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
22 Model for RhodeCode
26237de9b613 Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
23 @author: marcink
26237de9b613 Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
24 """
26237de9b613 Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
25 from rhodecode.lib import helpers as h
26237de9b613 Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
26 from rhodecode.model import meta
26237de9b613 Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
27 from rhodecode.model.caching_query import FromCache
26237de9b613 Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
28 from rhodecode.model.db import RhodeCodeSettings
26237de9b613 Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
29 from sqlalchemy.orm import joinedload
26237de9b613 Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
30 from sqlalchemy.orm.session import make_transient
26237de9b613 Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
31 import logging
26237de9b613 Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
32
26237de9b613 Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
33 log = logging.getLogger(__name__)
26237de9b613 Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
34
26237de9b613 Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
35 class SettingsModel(object):
26237de9b613 Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
36 """
26237de9b613 Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
37 Settings model
26237de9b613 Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
38 """
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 def __init__(self):
26237de9b613 Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
41 self.sa = meta.Session()
26237de9b613 Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
42
26237de9b613 Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
43
26237de9b613 Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
44 def get(self, settings_key, cache=False):
26237de9b613 Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
45 r = self.sa.query(RhodeCodeSettings)\
26237de9b613 Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
46 .filter(RhodeCodeSettings.app_settings_name == settings_key).scalar()
26237de9b613 Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
47 if cache:
26237de9b613 Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
48 r = r.options(FromCache("sql_cache_short",
26237de9b613 Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
49 "get_setting_%s" % settings_key))
26237de9b613 Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
50 return r
26237de9b613 Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
51
26237de9b613 Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
52
26237de9b613 Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
53 def get_ldap_settings(self):
705
9e9f1b919c0c implements #60, ldap configuration and authentication.
Marcin Kuzminski <marcin@python-works.com>
parents: 704
diff changeset
54 """
9e9f1b919c0c implements #60, ldap configuration and authentication.
Marcin Kuzminski <marcin@python-works.com>
parents: 704
diff changeset
55 Returns ldap settings from database
9e9f1b919c0c implements #60, ldap configuration and authentication.
Marcin Kuzminski <marcin@python-works.com>
parents: 704
diff changeset
56 :returns:
9e9f1b919c0c implements #60, ldap configuration and authentication.
Marcin Kuzminski <marcin@python-works.com>
parents: 704
diff changeset
57 ldap_active
9e9f1b919c0c implements #60, ldap configuration and authentication.
Marcin Kuzminski <marcin@python-works.com>
parents: 704
diff changeset
58 ldap_host
9e9f1b919c0c implements #60, ldap configuration and authentication.
Marcin Kuzminski <marcin@python-works.com>
parents: 704
diff changeset
59 ldap_port
9e9f1b919c0c implements #60, ldap configuration and authentication.
Marcin Kuzminski <marcin@python-works.com>
parents: 704
diff changeset
60 ldap_ldaps
9e9f1b919c0c implements #60, ldap configuration and authentication.
Marcin Kuzminski <marcin@python-works.com>
parents: 704
diff changeset
61 ldap_dn_user
9e9f1b919c0c implements #60, ldap configuration and authentication.
Marcin Kuzminski <marcin@python-works.com>
parents: 704
diff changeset
62 ldap_dn_pass
9e9f1b919c0c implements #60, ldap configuration and authentication.
Marcin Kuzminski <marcin@python-works.com>
parents: 704
diff changeset
63 ldap_base_dn
9e9f1b919c0c implements #60, ldap configuration and authentication.
Marcin Kuzminski <marcin@python-works.com>
parents: 704
diff changeset
64 """
704
26237de9b613 Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
65
26237de9b613 Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
66 r = self.sa.query(RhodeCodeSettings)\
26237de9b613 Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
67 .filter(RhodeCodeSettings.app_settings_name\
26237de9b613 Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
68 .startswith('ldap_'))\
26237de9b613 Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
69 .all()
26237de9b613 Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
70
26237de9b613 Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
71 fd = {}
26237de9b613 Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
72
26237de9b613 Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
73 for row in r:
26237de9b613 Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
74 v = row.app_settings_value
26237de9b613 Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
75 if v in ['0', '1']:
26237de9b613 Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
76 v = v == '1'
26237de9b613 Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
77 fd.update({row.app_settings_name:v})
26237de9b613 Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
78
26237de9b613 Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
79 return fd