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