##// END OF EJS Templates
Added settings model, and Exceptions lib....
marcink -
r704:26237de9 beta
parent child Browse files
Show More
@@ -0,0 +1,29 b''
1 #!/usr/bin/env python
2 # encoding: utf-8
3 # Custom Exceptions modules
4 # Copyright (C) 2009-2010 Marcin Kuzminski <marcin@python-works.com>
5 #
6 # This program is free software; you can redistribute it and/or
7 # modify it under the terms of the GNU General Public License
8 # as published by the Free Software Foundation; version 2
9 # of the License or (at your opinion) any later version of the license.
10 #
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19 # MA 02110-1301, USA.
20 """
21 Created on Nov 17, 2010
22 Custom Exceptions modules
23 @author: marcink
24 """
25
26 class UsernameError(Exception):pass
27 class PasswordError(Exception):pass
28 class ConnectionError(Exception):pass
29 class LdapImportError(Exception):pass
@@ -0,0 +1,68 b''
1 #!/usr/bin/env python
2 # encoding: utf-8
3 # Model for RhodeCode settings
4 # Copyright (C) 2009-2010 Marcin Kuzminski <marcin@python-works.com>
5 #
6 # This program is free software; you can redistribute it and/or
7 # modify it under the terms of the GNU General Public License
8 # as published by the Free Software Foundation; version 2
9 # of the License or (at your opinion) any later version of the license.
10 #
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19 # MA 02110-1301, USA.
20 """
21 Created on Nov 17, 2010
22 Model for RhodeCode
23 @author: marcink
24 """
25 from rhodecode.lib import helpers as h
26 from rhodecode.model import meta
27 from rhodecode.model.caching_query import FromCache
28 from rhodecode.model.db import RhodeCodeSettings
29 from sqlalchemy.orm import joinedload
30 from sqlalchemy.orm.session import make_transient
31 import logging
32
33 log = logging.getLogger(__name__)
34
35 class SettingsModel(object):
36 """
37 Settings model
38 """
39
40 def __init__(self):
41 self.sa = meta.Session()
42
43
44 def get(self, settings_key, cache=False):
45 r = self.sa.query(RhodeCodeSettings)\
46 .filter(RhodeCodeSettings.app_settings_name == settings_key).scalar()
47 if cache:
48 r = r.options(FromCache("sql_cache_short",
49 "get_setting_%s" % settings_key))
50 return r
51
52
53 def get_ldap_settings(self):
54
55 r = self.sa.query(RhodeCodeSettings)\
56 .filter(RhodeCodeSettings.app_settings_name\
57 .startswith('ldap_'))\
58 .all()
59
60 fd = {}
61
62 for row in r:
63 v = row.app_settings_value
64 if v in ['0', '1']:
65 v = v == '1'
66 fd.update({row.app_settings_name:v})
67
68 return fd
@@ -1,300 +1,303 b''
1 #!/usr/bin/env python
1 #!/usr/bin/env python
2 # encoding: utf-8
2 # encoding: utf-8
3 # database management for RhodeCode
3 # database management for RhodeCode
4 # Copyright (C) 2009-2010 Marcin Kuzminski <marcin@python-works.com>
4 # Copyright (C) 2009-2010 Marcin Kuzminski <marcin@python-works.com>
5 #
5 #
6 # This program is free software; you can redistribute it and/or
6 # This program is free software; you can redistribute it and/or
7 # modify it under the terms of the GNU General Public License
7 # modify it under the terms of the GNU General Public License
8 # as published by the Free Software Foundation; version 2
8 # as published by the Free Software Foundation; version 2
9 # of the License or (at your opinion) any later version of the license.
9 # of the License or (at your opinion) any later version of the license.
10 #
10 #
11 # This program is distributed in the hope that it will be useful,
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
14 # GNU General Public License for more details.
15 #
15 #
16 # You should have received a copy of the GNU General Public License
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19 # MA 02110-1301, USA.
19 # MA 02110-1301, USA.
20
20
21 """
21 """
22 Created on April 10, 2010
22 Created on April 10, 2010
23 database management and creation for RhodeCode
23 database management and creation for RhodeCode
24 @author: marcink
24 @author: marcink
25 """
25 """
26
26
27 from os.path import dirname as dn, join as jn
27 from os.path import dirname as dn, join as jn
28 import os
28 import os
29 import sys
29 import sys
30 import uuid
30 import uuid
31
31
32 from rhodecode.lib.auth import get_crypt_password
32 from rhodecode.lib.auth import get_crypt_password
33 from rhodecode.lib.utils import ask_ok
33 from rhodecode.lib.utils import ask_ok
34 from rhodecode.model import init_model
34 from rhodecode.model import init_model
35 from rhodecode.model.db import User, Permission, RhodeCodeUi, RhodeCodeSettings, \
35 from rhodecode.model.db import User, Permission, RhodeCodeUi, RhodeCodeSettings, \
36 UserToPerm
36 UserToPerm
37 from rhodecode.model import meta
37 from rhodecode.model import meta
38 from sqlalchemy.engine import create_engine
38 from sqlalchemy.engine import create_engine
39 import logging
39 import logging
40
40
41 log = logging.getLogger(__name__)
41 log = logging.getLogger(__name__)
42
42
43 class DbManage(object):
43 class DbManage(object):
44 def __init__(self, log_sql, dbname, root, tests=False):
44 def __init__(self, log_sql, dbname, root, tests=False):
45 self.dbname = dbname
45 self.dbname = dbname
46 self.tests = tests
46 self.tests = tests
47 self.root = root
47 self.root = root
48 dburi = 'sqlite:////%s' % jn(self.root, self.dbname)
48 dburi = 'sqlite:////%s' % jn(self.root, self.dbname)
49 engine = create_engine(dburi, echo=log_sql)
49 engine = create_engine(dburi, echo=log_sql)
50 init_model(engine)
50 init_model(engine)
51 self.sa = meta.Session()
51 self.sa = meta.Session()
52 self.db_exists = False
52 self.db_exists = False
53
53
54 def check_for_db(self, override):
54 def check_for_db(self, override):
55 db_path = jn(self.root, self.dbname)
55 db_path = jn(self.root, self.dbname)
56 log.info('checking for existing db in %s', db_path)
56 log.info('checking for existing db in %s', db_path)
57 if os.path.isfile(db_path):
57 if os.path.isfile(db_path):
58 self.db_exists = True
58 self.db_exists = True
59 if not override:
59 if not override:
60 raise Exception('database already exists')
60 raise Exception('database already exists')
61
61
62 def create_tables(self, override=False):
62 def create_tables(self, override=False):
63 """
63 """
64 Create a auth database
64 Create a auth database
65 """
65 """
66 self.check_for_db(override)
66 self.check_for_db(override)
67 if self.db_exists:
67 if self.db_exists:
68 log.info("database exist and it's going to be destroyed")
68 log.info("database exist and it's going to be destroyed")
69 if self.tests:
69 if self.tests:
70 destroy = True
70 destroy = True
71 else:
71 else:
72 destroy = ask_ok('Are you sure to destroy old database ? [y/n]')
72 destroy = ask_ok('Are you sure to destroy old database ? [y/n]')
73 if not destroy:
73 if not destroy:
74 sys.exit()
74 sys.exit()
75 if self.db_exists and destroy:
75 if self.db_exists and destroy:
76 os.remove(jn(self.root, self.dbname))
76 os.remove(jn(self.root, self.dbname))
77 checkfirst = not override
77 checkfirst = not override
78 meta.Base.metadata.create_all(checkfirst=checkfirst)
78 meta.Base.metadata.create_all(checkfirst=checkfirst)
79 log.info('Created tables for %s', self.dbname)
79 log.info('Created tables for %s', self.dbname)
80
80
81 def admin_prompt(self, second=False):
81 def admin_prompt(self, second=False):
82 if not self.tests:
82 if not self.tests:
83 import getpass
83 import getpass
84
84
85
85
86 def get_password():
86 def get_password():
87 password = getpass.getpass('Specify admin password (min 6 chars):')
87 password = getpass.getpass('Specify admin password (min 6 chars):')
88 confirm = getpass.getpass('Confirm password:')
88 confirm = getpass.getpass('Confirm password:')
89
89
90 if password != confirm:
90 if password != confirm:
91 log.error('passwords mismatch')
91 log.error('passwords mismatch')
92 return False
92 return False
93 if len(password) < 6:
93 if len(password) < 6:
94 log.error('password is to short use at least 6 characters')
94 log.error('password is to short use at least 6 characters')
95 return False
95 return False
96
96
97 return password
97 return password
98
98
99 username = raw_input('Specify admin username:')
99 username = raw_input('Specify admin username:')
100
100
101 password = get_password()
101 password = get_password()
102 if not password:
102 if not password:
103 #second try
103 #second try
104 password = get_password()
104 password = get_password()
105 if not password:
105 if not password:
106 sys.exit()
106 sys.exit()
107
107
108 email = raw_input('Specify admin email:')
108 email = raw_input('Specify admin email:')
109 self.create_user(username, password, email, True)
109 self.create_user(username, password, email, True)
110 else:
110 else:
111 log.info('creating admin and regular test users')
111 log.info('creating admin and regular test users')
112 self.create_user('test_admin', 'test12', 'test_admin@mail.com', True)
112 self.create_user('test_admin', 'test12', 'test_admin@mail.com', True)
113 self.create_user('test_regular', 'test12', 'test_regular@mail.com', False)
113 self.create_user('test_regular', 'test12', 'test_regular@mail.com', False)
114 self.create_user('test_regular2', 'test12', 'test_regular2@mail.com', False)
114 self.create_user('test_regular2', 'test12', 'test_regular2@mail.com', False)
115
115
116
116
117
117
118 def config_prompt(self, test_repo_path=''):
118 def config_prompt(self, test_repo_path=''):
119 log.info('Setting up repositories config')
119 log.info('Setting up repositories config')
120
120
121 if not self.tests and not test_repo_path:
121 if not self.tests and not test_repo_path:
122 path = raw_input('Specify valid full path to your repositories'
122 path = raw_input('Specify valid full path to your repositories'
123 ' you can change this later in application settings:')
123 ' you can change this later in application settings:')
124 else:
124 else:
125 path = test_repo_path
125 path = test_repo_path
126
126
127 if not os.path.isdir(path):
127 if not os.path.isdir(path):
128 log.error('You entered wrong path: %s', path)
128 log.error('You entered wrong path: %s', path)
129 sys.exit()
129 sys.exit()
130
130
131 hooks1 = RhodeCodeUi()
131 hooks1 = RhodeCodeUi()
132 hooks1.ui_section = 'hooks'
132 hooks1.ui_section = 'hooks'
133 hooks1.ui_key = 'changegroup.update'
133 hooks1.ui_key = 'changegroup.update'
134 hooks1.ui_value = 'hg update >&2'
134 hooks1.ui_value = 'hg update >&2'
135 hooks1.ui_active = False
135 hooks1.ui_active = False
136
136
137 hooks2 = RhodeCodeUi()
137 hooks2 = RhodeCodeUi()
138 hooks2.ui_section = 'hooks'
138 hooks2.ui_section = 'hooks'
139 hooks2.ui_key = 'changegroup.repo_size'
139 hooks2.ui_key = 'changegroup.repo_size'
140 hooks2.ui_value = 'python:rhodecode.lib.hooks.repo_size'
140 hooks2.ui_value = 'python:rhodecode.lib.hooks.repo_size'
141
141
142 hooks3 = RhodeCodeUi()
142 hooks3 = RhodeCodeUi()
143 hooks3.ui_section = 'hooks'
143 hooks3.ui_section = 'hooks'
144 hooks3.ui_key = 'pretxnchangegroup.push_logger'
144 hooks3.ui_key = 'pretxnchangegroup.push_logger'
145 hooks3.ui_value = 'python:rhodecode.lib.hooks.log_push_action'
145 hooks3.ui_value = 'python:rhodecode.lib.hooks.log_push_action'
146
146
147 hooks4 = RhodeCodeUi()
147 hooks4 = RhodeCodeUi()
148 hooks4.ui_section = 'hooks'
148 hooks4.ui_section = 'hooks'
149 hooks4.ui_key = 'preoutgoing.pull_logger'
149 hooks4.ui_key = 'preoutgoing.pull_logger'
150 hooks4.ui_value = 'python:rhodecode.lib.hooks.log_pull_action'
150 hooks4.ui_value = 'python:rhodecode.lib.hooks.log_pull_action'
151
151
152
152
153 web1 = RhodeCodeUi()
153 web1 = RhodeCodeUi()
154 web1.ui_section = 'web'
154 web1.ui_section = 'web'
155 web1.ui_key = 'push_ssl'
155 web1.ui_key = 'push_ssl'
156 web1.ui_value = 'false'
156 web1.ui_value = 'false'
157
157
158 web2 = RhodeCodeUi()
158 web2 = RhodeCodeUi()
159 web2.ui_section = 'web'
159 web2.ui_section = 'web'
160 web2.ui_key = 'allow_archive'
160 web2.ui_key = 'allow_archive'
161 web2.ui_value = 'gz zip bz2'
161 web2.ui_value = 'gz zip bz2'
162
162
163 web3 = RhodeCodeUi()
163 web3 = RhodeCodeUi()
164 web3.ui_section = 'web'
164 web3.ui_section = 'web'
165 web3.ui_key = 'allow_push'
165 web3.ui_key = 'allow_push'
166 web3.ui_value = '*'
166 web3.ui_value = '*'
167
167
168 web4 = RhodeCodeUi()
168 web4 = RhodeCodeUi()
169 web4.ui_section = 'web'
169 web4.ui_section = 'web'
170 web4.ui_key = 'baseurl'
170 web4.ui_key = 'baseurl'
171 web4.ui_value = '/'
171 web4.ui_value = '/'
172
172
173 paths = RhodeCodeUi()
173 paths = RhodeCodeUi()
174 paths.ui_section = 'paths'
174 paths.ui_section = 'paths'
175 paths.ui_key = '/'
175 paths.ui_key = '/'
176 paths.ui_value = path
176 paths.ui_value = path
177
177
178
178
179 hgsettings1 = RhodeCodeSettings()
179 hgsettings1 = RhodeCodeSettings('realm', 'RhodeCode authentication')
180 hgsettings2 = RhodeCodeSettings('title', 'RhodeCode')
180
181
181 hgsettings1.app_settings_name = 'realm'
182 hgsettings1.app_settings_value = 'RhodeCode authentication'
183
184 hgsettings2 = RhodeCodeSettings()
185 hgsettings2.app_settings_name = 'title'
186 hgsettings2.app_settings_value = 'RhodeCode'
187
182
188 try:
183 try:
184
185
189 self.sa.add(hooks1)
186 self.sa.add(hooks1)
190 self.sa.add(hooks2)
187 self.sa.add(hooks2)
191 self.sa.add(hooks3)
188 self.sa.add(hooks3)
192 self.sa.add(hooks4)
189 self.sa.add(hooks4)
193 self.sa.add(web1)
190 self.sa.add(web1)
194 self.sa.add(web2)
191 self.sa.add(web2)
195 self.sa.add(web3)
192 self.sa.add(web3)
196 self.sa.add(web4)
193 self.sa.add(web4)
197 self.sa.add(paths)
194 self.sa.add(paths)
198 self.sa.add(hgsettings1)
195 self.sa.add(hgsettings1)
199 self.sa.add(hgsettings2)
196 self.sa.add(hgsettings2)
197 for k in ['ldap_active', 'ldap_host', 'ldap_port', 'ldap_ldaps',
198 'ldap_dn_user', 'ldap_dn_pass', 'ldap_base_dn']:
199
200 setting = RhodeCodeSettings(k, '')
201 self.sa.add(setting)
202
200 self.sa.commit()
203 self.sa.commit()
201 except:
204 except:
202 self.sa.rollback()
205 self.sa.rollback()
203 raise
206 raise
204 log.info('created ui config')
207 log.info('created ui config')
205
208
206 def create_user(self, username, password, email='', admin=False):
209 def create_user(self, username, password, email='', admin=False):
207 log.info('creating administrator user %s', username)
210 log.info('creating administrator user %s', username)
208 new_user = User()
211 new_user = User()
209 new_user.username = username
212 new_user.username = username
210 new_user.password = get_crypt_password(password)
213 new_user.password = get_crypt_password(password)
211 new_user.name = 'RhodeCode'
214 new_user.name = 'RhodeCode'
212 new_user.lastname = 'Admin'
215 new_user.lastname = 'Admin'
213 new_user.email = email
216 new_user.email = email
214 new_user.admin = admin
217 new_user.admin = admin
215 new_user.active = True
218 new_user.active = True
216
219
217 try:
220 try:
218 self.sa.add(new_user)
221 self.sa.add(new_user)
219 self.sa.commit()
222 self.sa.commit()
220 except:
223 except:
221 self.sa.rollback()
224 self.sa.rollback()
222 raise
225 raise
223
226
224 def create_default_user(self):
227 def create_default_user(self):
225 log.info('creating default user')
228 log.info('creating default user')
226 #create default user for handling default permissions.
229 #create default user for handling default permissions.
227 def_user = User()
230 def_user = User()
228 def_user.username = 'default'
231 def_user.username = 'default'
229 def_user.password = get_crypt_password(str(uuid.uuid1())[:8])
232 def_user.password = get_crypt_password(str(uuid.uuid1())[:8])
230 def_user.name = 'Anonymous'
233 def_user.name = 'Anonymous'
231 def_user.lastname = 'User'
234 def_user.lastname = 'User'
232 def_user.email = 'anonymous@rhodecode.org'
235 def_user.email = 'anonymous@rhodecode.org'
233 def_user.admin = False
236 def_user.admin = False
234 def_user.active = False
237 def_user.active = False
235 try:
238 try:
236 self.sa.add(def_user)
239 self.sa.add(def_user)
237 self.sa.commit()
240 self.sa.commit()
238 except:
241 except:
239 self.sa.rollback()
242 self.sa.rollback()
240 raise
243 raise
241
244
242 def create_permissions(self):
245 def create_permissions(self):
243 #module.(access|create|change|delete)_[name]
246 #module.(access|create|change|delete)_[name]
244 #module.(read|write|owner)
247 #module.(read|write|owner)
245 perms = [('repository.none', 'Repository no access'),
248 perms = [('repository.none', 'Repository no access'),
246 ('repository.read', 'Repository read access'),
249 ('repository.read', 'Repository read access'),
247 ('repository.write', 'Repository write access'),
250 ('repository.write', 'Repository write access'),
248 ('repository.admin', 'Repository admin access'),
251 ('repository.admin', 'Repository admin access'),
249 ('hg.admin', 'Hg Administrator'),
252 ('hg.admin', 'Hg Administrator'),
250 ('hg.create.repository', 'Repository create'),
253 ('hg.create.repository', 'Repository create'),
251 ('hg.create.none', 'Repository creation disabled'),
254 ('hg.create.none', 'Repository creation disabled'),
252 ('hg.register.none', 'Register disabled'),
255 ('hg.register.none', 'Register disabled'),
253 ('hg.register.manual_activate', 'Register new user with rhodecode without manual activation'),
256 ('hg.register.manual_activate', 'Register new user with rhodecode without manual activation'),
254 ('hg.register.auto_activate', 'Register new user with rhodecode without auto activation'),
257 ('hg.register.auto_activate', 'Register new user with rhodecode without auto activation'),
255 ]
258 ]
256
259
257 for p in perms:
260 for p in perms:
258 new_perm = Permission()
261 new_perm = Permission()
259 new_perm.permission_name = p[0]
262 new_perm.permission_name = p[0]
260 new_perm.permission_longname = p[1]
263 new_perm.permission_longname = p[1]
261 try:
264 try:
262 self.sa.add(new_perm)
265 self.sa.add(new_perm)
263 self.sa.commit()
266 self.sa.commit()
264 except:
267 except:
265 self.sa.rollback()
268 self.sa.rollback()
266 raise
269 raise
267
270
268 def populate_default_permissions(self):
271 def populate_default_permissions(self):
269 log.info('creating default user permissions')
272 log.info('creating default user permissions')
270
273
271 default_user = self.sa.query(User)\
274 default_user = self.sa.query(User)\
272 .filter(User.username == 'default').scalar()
275 .filter(User.username == 'default').scalar()
273
276
274 reg_perm = UserToPerm()
277 reg_perm = UserToPerm()
275 reg_perm.user = default_user
278 reg_perm.user = default_user
276 reg_perm.permission = self.sa.query(Permission)\
279 reg_perm.permission = self.sa.query(Permission)\
277 .filter(Permission.permission_name == 'hg.register.manual_activate')\
280 .filter(Permission.permission_name == 'hg.register.manual_activate')\
278 .scalar()
281 .scalar()
279
282
280 create_repo_perm = UserToPerm()
283 create_repo_perm = UserToPerm()
281 create_repo_perm.user = default_user
284 create_repo_perm.user = default_user
282 create_repo_perm.permission = self.sa.query(Permission)\
285 create_repo_perm.permission = self.sa.query(Permission)\
283 .filter(Permission.permission_name == 'hg.create.repository')\
286 .filter(Permission.permission_name == 'hg.create.repository')\
284 .scalar()
287 .scalar()
285
288
286 default_repo_perm = UserToPerm()
289 default_repo_perm = UserToPerm()
287 default_repo_perm.user = default_user
290 default_repo_perm.user = default_user
288 default_repo_perm.permission = self.sa.query(Permission)\
291 default_repo_perm.permission = self.sa.query(Permission)\
289 .filter(Permission.permission_name == 'repository.read')\
292 .filter(Permission.permission_name == 'repository.read')\
290 .scalar()
293 .scalar()
291
294
292 try:
295 try:
293 self.sa.add(reg_perm)
296 self.sa.add(reg_perm)
294 self.sa.add(create_repo_perm)
297 self.sa.add(create_repo_perm)
295 self.sa.add(default_repo_perm)
298 self.sa.add(default_repo_perm)
296 self.sa.commit()
299 self.sa.commit()
297 except:
300 except:
298 self.sa.rollback()
301 self.sa.rollback()
299 raise
302 raise
300
303
@@ -1,155 +1,164 b''
1 from rhodecode.model.meta import Base
1 from rhodecode.model.meta import Base
2 from sqlalchemy import *
2 from sqlalchemy import *
3 from sqlalchemy.orm import relation, backref
3 from sqlalchemy.orm import relation, backref
4 from sqlalchemy.orm.session import Session
4 from sqlalchemy.orm.session import Session
5 from vcs.utils.lazy import LazyProperty
5 from vcs.utils.lazy import LazyProperty
6 import logging
6 import logging
7 log = logging.getLogger(__name__)
7 log = logging.getLogger(__name__)
8
8
9 class RhodeCodeSettings(Base):
9 class RhodeCodeSettings(Base):
10 __tablename__ = 'rhodecode_settings'
10 __tablename__ = 'rhodecode_settings'
11 __table_args__ = (UniqueConstraint('app_settings_name'), {'useexisting':True})
11 __table_args__ = (UniqueConstraint('app_settings_name'), {'useexisting':True})
12 app_settings_id = Column("app_settings_id", INTEGER(), nullable=False, unique=True, default=None, primary_key=True)
12 app_settings_id = Column("app_settings_id", INTEGER(), nullable=False, unique=True, default=None, primary_key=True)
13 app_settings_name = Column("app_settings_name", TEXT(length=None, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
13 app_settings_name = Column("app_settings_name", TEXT(length=None, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
14 app_settings_value = Column("app_settings_value", TEXT(length=None, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
14 app_settings_value = Column("app_settings_value", TEXT(length=None, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
15
15
16 def __init__(self, k, v):
17 self.app_settings_name = k
18 self.app_settings_value = v
19
20 def __repr__(self):
21 return "<RhodeCodeSetting('%s:%s')>" % (self.app_settings_name,
22 self.app_settings_value)
23
16 class RhodeCodeUi(Base):
24 class RhodeCodeUi(Base):
17 __tablename__ = 'rhodecode_ui'
25 __tablename__ = 'rhodecode_ui'
18 __table_args__ = {'useexisting':True}
26 __table_args__ = {'useexisting':True}
19 ui_id = Column("ui_id", INTEGER(), nullable=False, unique=True, default=None, primary_key=True)
27 ui_id = Column("ui_id", INTEGER(), nullable=False, unique=True, default=None, primary_key=True)
20 ui_section = Column("ui_section", TEXT(length=None, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
28 ui_section = Column("ui_section", TEXT(length=None, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
21 ui_key = Column("ui_key", TEXT(length=None, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
29 ui_key = Column("ui_key", TEXT(length=None, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
22 ui_value = Column("ui_value", TEXT(length=None, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
30 ui_value = Column("ui_value", TEXT(length=None, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
23 ui_active = Column("ui_active", BOOLEAN(), nullable=True, unique=None, default=True)
31 ui_active = Column("ui_active", BOOLEAN(), nullable=True, unique=None, default=True)
24
32
25
33
26 class User(Base):
34 class User(Base):
27 __tablename__ = 'users'
35 __tablename__ = 'users'
28 __table_args__ = (UniqueConstraint('username'), UniqueConstraint('email'), {'useexisting':True})
36 __table_args__ = (UniqueConstraint('username'), UniqueConstraint('email'), {'useexisting':True})
29 user_id = Column("user_id", INTEGER(), nullable=False, unique=True, default=None, primary_key=True)
37 user_id = Column("user_id", INTEGER(), nullable=False, unique=True, default=None, primary_key=True)
30 username = Column("username", TEXT(length=None, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
38 username = Column("username", TEXT(length=None, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
31 password = Column("password", TEXT(length=None, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
39 password = Column("password", TEXT(length=None, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
32 active = Column("active", BOOLEAN(), nullable=True, unique=None, default=None)
40 active = Column("active", BOOLEAN(), nullable=True, unique=None, default=None)
33 admin = Column("admin", BOOLEAN(), nullable=True, unique=None, default=False)
41 admin = Column("admin", BOOLEAN(), nullable=True, unique=None, default=False)
34 name = Column("name", TEXT(length=None, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
42 name = Column("name", TEXT(length=None, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
35 lastname = Column("lastname", TEXT(length=None, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
43 lastname = Column("lastname", TEXT(length=None, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
36 email = Column("email", TEXT(length=None, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
44 email = Column("email", TEXT(length=None, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
37 last_login = Column("last_login", DATETIME(timezone=False), nullable=True, unique=None, default=None)
45 last_login = Column("last_login", DATETIME(timezone=False), nullable=True, unique=None, default=None)
46 is_ldap = Column("is_ldap", BOOLEAN(), nullable=False, unique=None, default=False)
38
47
39 user_log = relation('UserLog')
48 user_log = relation('UserLog', cascade='all')
40 user_perms = relation('UserToPerm', primaryjoin="User.user_id==UserToPerm.user_id")
49 user_perms = relation('UserToPerm', primaryjoin="User.user_id==UserToPerm.user_id", cascade='all')
41
50
42 @LazyProperty
51 @LazyProperty
43 def full_contact(self):
52 def full_contact(self):
44 return '%s %s <%s>' % (self.name, self.lastname, self.email)
53 return '%s %s <%s>' % (self.name, self.lastname, self.email)
45
54
46 def __repr__(self):
55 def __repr__(self):
47 return "<User('id:%s:%s')>" % (self.user_id, self.username)
56 return "<User('id:%s:%s')>" % (self.user_id, self.username)
48
57
49 def update_lastlogin(self):
58 def update_lastlogin(self):
50 """Update user lastlogin"""
59 """Update user lastlogin"""
51 import datetime
60 import datetime
52
61
53 try:
62 try:
54 session = Session.object_session(self)
63 session = Session.object_session(self)
55 self.last_login = datetime.datetime.now()
64 self.last_login = datetime.datetime.now()
56 session.add(self)
65 session.add(self)
57 session.commit()
66 session.commit()
58 log.debug('updated user %s lastlogin', self.username)
67 log.debug('updated user %s lastlogin', self.username)
59 except Exception:
68 except Exception:
60 session.rollback()
69 session.rollback()
61
70
62
71
63 class UserLog(Base):
72 class UserLog(Base):
64 __tablename__ = 'user_logs'
73 __tablename__ = 'user_logs'
65 __table_args__ = {'useexisting':True}
74 __table_args__ = {'useexisting':True}
66 user_log_id = Column("user_log_id", INTEGER(), nullable=False, unique=True, default=None, primary_key=True)
75 user_log_id = Column("user_log_id", INTEGER(), nullable=False, unique=True, default=None, primary_key=True)
67 user_id = Column("user_id", INTEGER(), ForeignKey(u'users.user_id'), nullable=False, unique=None, default=None)
76 user_id = Column("user_id", INTEGER(), ForeignKey(u'users.user_id'), nullable=False, unique=None, default=None)
68 repository_id = Column("repository_id", INTEGER(length=None, convert_unicode=False, assert_unicode=None), ForeignKey(u'repositories.repo_id'), nullable=False, unique=None, default=None)
77 repository_id = Column("repository_id", INTEGER(length=None, convert_unicode=False, assert_unicode=None), ForeignKey(u'repositories.repo_id'), nullable=False, unique=None, default=None)
69 repository_name = Column("repository_name", TEXT(length=None, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
78 repository_name = Column("repository_name", TEXT(length=None, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
70 user_ip = Column("user_ip", TEXT(length=None, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
79 user_ip = Column("user_ip", TEXT(length=None, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
71 action = Column("action", TEXT(length=None, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
80 action = Column("action", TEXT(length=None, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
72 action_date = Column("action_date", DATETIME(timezone=False), nullable=True, unique=None, default=None)
81 action_date = Column("action_date", DATETIME(timezone=False), nullable=True, unique=None, default=None)
73
82
74 user = relation('User')
83 user = relation('User')
75 repository = relation('Repository')
84 repository = relation('Repository')
76
85
77 class Repository(Base):
86 class Repository(Base):
78 __tablename__ = 'repositories'
87 __tablename__ = 'repositories'
79 __table_args__ = (UniqueConstraint('repo_name'), {'useexisting':True},)
88 __table_args__ = (UniqueConstraint('repo_name'), {'useexisting':True},)
80 repo_id = Column("repo_id", INTEGER(), nullable=False, unique=True, default=None, primary_key=True)
89 repo_id = Column("repo_id", INTEGER(), nullable=False, unique=True, default=None, primary_key=True)
81 repo_name = Column("repo_name", TEXT(length=None, convert_unicode=False, assert_unicode=None), nullable=False, unique=True, default=None)
90 repo_name = Column("repo_name", TEXT(length=None, convert_unicode=False, assert_unicode=None), nullable=False, unique=True, default=None)
82 repo_type = Column("repo_type", TEXT(length=None, convert_unicode=False, assert_unicode=None), nullable=False, unique=False, default=None)
91 repo_type = Column("repo_type", TEXT(length=None, convert_unicode=False, assert_unicode=None), nullable=False, unique=False, default=None)
83 user_id = Column("user_id", INTEGER(), ForeignKey(u'users.user_id'), nullable=False, unique=False, default=None)
92 user_id = Column("user_id", INTEGER(), ForeignKey(u'users.user_id'), nullable=False, unique=False, default=None)
84 private = Column("private", BOOLEAN(), nullable=True, unique=None, default=None)
93 private = Column("private", BOOLEAN(), nullable=True, unique=None, default=None)
85 description = Column("description", TEXT(length=None, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
94 description = Column("description", TEXT(length=None, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
86 fork_id = Column("fork_id", INTEGER(), ForeignKey(u'repositories.repo_id'), nullable=True, unique=False, default=None)
95 fork_id = Column("fork_id", INTEGER(), ForeignKey(u'repositories.repo_id'), nullable=True, unique=False, default=None)
87
96
88 user = relation('User')
97 user = relation('User')
89 fork = relation('Repository', remote_side=repo_id)
98 fork = relation('Repository', remote_side=repo_id)
90 repo_to_perm = relation('RepoToPerm', cascade='all')
99 repo_to_perm = relation('RepoToPerm', cascade='all')
91 stats = relation('Statistics', cascade='all')
100 stats = relation('Statistics', cascade='all')
92
101
93 def __repr__(self):
102 def __repr__(self):
94 return "<Repository('%s:%s')>" % (self.repo_id, self.repo_name)
103 return "<Repository('%s:%s')>" % (self.repo_id, self.repo_name)
95
104
96 class Permission(Base):
105 class Permission(Base):
97 __tablename__ = 'permissions'
106 __tablename__ = 'permissions'
98 __table_args__ = {'useexisting':True}
107 __table_args__ = {'useexisting':True}
99 permission_id = Column("permission_id", INTEGER(), nullable=False, unique=True, default=None, primary_key=True)
108 permission_id = Column("permission_id", INTEGER(), nullable=False, unique=True, default=None, primary_key=True)
100 permission_name = Column("permission_name", TEXT(length=None, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
109 permission_name = Column("permission_name", TEXT(length=None, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
101 permission_longname = Column("permission_longname", TEXT(length=None, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
110 permission_longname = Column("permission_longname", TEXT(length=None, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
102
111
103 def __repr__(self):
112 def __repr__(self):
104 return "<Permission('%s:%s')>" % (self.permission_id, self.permission_name)
113 return "<Permission('%s:%s')>" % (self.permission_id, self.permission_name)
105
114
106 class RepoToPerm(Base):
115 class RepoToPerm(Base):
107 __tablename__ = 'repo_to_perm'
116 __tablename__ = 'repo_to_perm'
108 __table_args__ = (UniqueConstraint('user_id', 'repository_id'), {'useexisting':True})
117 __table_args__ = (UniqueConstraint('user_id', 'repository_id'), {'useexisting':True})
109 repo_to_perm_id = Column("repo_to_perm_id", INTEGER(), nullable=False, unique=True, default=None, primary_key=True)
118 repo_to_perm_id = Column("repo_to_perm_id", INTEGER(), nullable=False, unique=True, default=None, primary_key=True)
110 user_id = Column("user_id", INTEGER(), ForeignKey(u'users.user_id'), nullable=False, unique=None, default=None)
119 user_id = Column("user_id", INTEGER(), ForeignKey(u'users.user_id'), nullable=False, unique=None, default=None)
111 permission_id = Column("permission_id", INTEGER(), ForeignKey(u'permissions.permission_id'), nullable=False, unique=None, default=None)
120 permission_id = Column("permission_id", INTEGER(), ForeignKey(u'permissions.permission_id'), nullable=False, unique=None, default=None)
112 repository_id = Column("repository_id", INTEGER(), ForeignKey(u'repositories.repo_id'), nullable=False, unique=None, default=None)
121 repository_id = Column("repository_id", INTEGER(), ForeignKey(u'repositories.repo_id'), nullable=False, unique=None, default=None)
113
122
114 user = relation('User')
123 user = relation('User')
115 permission = relation('Permission')
124 permission = relation('Permission')
116 repository = relation('Repository')
125 repository = relation('Repository')
117
126
118 class UserToPerm(Base):
127 class UserToPerm(Base):
119 __tablename__ = 'user_to_perm'
128 __tablename__ = 'user_to_perm'
120 __table_args__ = (UniqueConstraint('user_id', 'permission_id'), {'useexisting':True})
129 __table_args__ = (UniqueConstraint('user_id', 'permission_id'), {'useexisting':True})
121 user_to_perm_id = Column("user_to_perm_id", INTEGER(), nullable=False, unique=True, default=None, primary_key=True)
130 user_to_perm_id = Column("user_to_perm_id", INTEGER(), nullable=False, unique=True, default=None, primary_key=True)
122 user_id = Column("user_id", INTEGER(), ForeignKey(u'users.user_id'), nullable=False, unique=None, default=None)
131 user_id = Column("user_id", INTEGER(), ForeignKey(u'users.user_id'), nullable=False, unique=None, default=None)
123 permission_id = Column("permission_id", INTEGER(), ForeignKey(u'permissions.permission_id'), nullable=False, unique=None, default=None)
132 permission_id = Column("permission_id", INTEGER(), ForeignKey(u'permissions.permission_id'), nullable=False, unique=None, default=None)
124
133
125 user = relation('User')
134 user = relation('User')
126 permission = relation('Permission')
135 permission = relation('Permission')
127
136
128 class Statistics(Base):
137 class Statistics(Base):
129 __tablename__ = 'statistics'
138 __tablename__ = 'statistics'
130 __table_args__ = (UniqueConstraint('repository_id'), {'useexisting':True})
139 __table_args__ = (UniqueConstraint('repository_id'), {'useexisting':True})
131 stat_id = Column("stat_id", INTEGER(), nullable=False, unique=True, default=None, primary_key=True)
140 stat_id = Column("stat_id", INTEGER(), nullable=False, unique=True, default=None, primary_key=True)
132 repository_id = Column("repository_id", INTEGER(), ForeignKey(u'repositories.repo_id'), nullable=False, unique=True, default=None)
141 repository_id = Column("repository_id", INTEGER(), ForeignKey(u'repositories.repo_id'), nullable=False, unique=True, default=None)
133 stat_on_revision = Column("stat_on_revision", INTEGER(), nullable=False)
142 stat_on_revision = Column("stat_on_revision", INTEGER(), nullable=False)
134 commit_activity = Column("commit_activity", BLOB(), nullable=False)#JSON data
143 commit_activity = Column("commit_activity", BLOB(), nullable=False)#JSON data
135 commit_activity_combined = Column("commit_activity_combined", BLOB(), nullable=False)#JSON data
144 commit_activity_combined = Column("commit_activity_combined", BLOB(), nullable=False)#JSON data
136 languages = Column("languages", BLOB(), nullable=False)#JSON data
145 languages = Column("languages", BLOB(), nullable=False)#JSON data
137
146
138 repository = relation('Repository', single_parent=True)
147 repository = relation('Repository', single_parent=True)
139
148
140 class CacheInvalidation(Base):
149 class CacheInvalidation(Base):
141 __tablename__ = 'cache_invalidation'
150 __tablename__ = 'cache_invalidation'
142 __table_args__ = (UniqueConstraint('cache_key'), {'useexisting':True})
151 __table_args__ = (UniqueConstraint('cache_key'), {'useexisting':True})
143 cache_id = Column("cache_id", INTEGER(), nullable=False, unique=True, default=None, primary_key=True)
152 cache_id = Column("cache_id", INTEGER(), nullable=False, unique=True, default=None, primary_key=True)
144 cache_key = Column("cache_key", TEXT(length=None, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
153 cache_key = Column("cache_key", TEXT(length=None, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
145 cache_args = Column("cache_args", TEXT(length=None, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
154 cache_args = Column("cache_args", TEXT(length=None, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
146 cache_active = Column("cache_active", BOOLEAN(), nullable=True, unique=None, default=False)
155 cache_active = Column("cache_active", BOOLEAN(), nullable=True, unique=None, default=False)
147
156
148
157
149 def __init__(self, cache_key, cache_args=''):
158 def __init__(self, cache_key, cache_args=''):
150 self.cache_key = cache_key
159 self.cache_key = cache_key
151 self.cache_args = cache_args
160 self.cache_args = cache_args
152 self.cache_active = False
161 self.cache_active = False
153
162
154 def __repr__(self):
163 def __repr__(self):
155 return "<CacheInvaidation('%s:%s')>" % (self.cache_id, self.cache_key)
164 return "<CacheInvaidation('%s:%s')>" % (self.cache_id, self.cache_key)
General Comments 0
You need to be logged in to leave comments. Login now