Show More
@@ -38,6 +38,7 b' from rhodecode.lib.base import BaseContr' | |||||
38 | from rhodecode.model.forms import DefaultPermissionsForm |
|
38 | from rhodecode.model.forms import DefaultPermissionsForm | |
39 | from rhodecode.model.permission import PermissionModel |
|
39 | from rhodecode.model.permission import PermissionModel | |
40 | from rhodecode.model.db import User |
|
40 | from rhodecode.model.db import User | |
|
41 | from rhodecode.model.meta import Session | |||
41 |
|
42 | |||
42 | log = logging.getLogger(__name__) |
|
43 | log = logging.getLogger(__name__) | |
43 |
|
44 | |||
@@ -101,6 +102,7 b' class PermissionsController(BaseControll' | |||||
101 | form_result = _form.to_python(dict(request.POST)) |
|
102 | form_result = _form.to_python(dict(request.POST)) | |
102 | form_result.update({'perm_user_name': id}) |
|
103 | form_result.update({'perm_user_name': id}) | |
103 | permission_model.update(form_result) |
|
104 | permission_model.update(form_result) | |
|
105 | Session().commit() | |||
104 | h.flash(_('Default permissions updated successfully'), |
|
106 | h.flash(_('Default permissions updated successfully'), | |
105 | category='success') |
|
107 | category='success') | |
106 |
|
108 |
@@ -17,6 +17,7 b' from rhodecode.lib.base import BaseContr' | |||||
17 | from rhodecode.model.db import RepoGroup |
|
17 | from rhodecode.model.db import RepoGroup | |
18 | from rhodecode.model.repos_group import ReposGroupModel |
|
18 | from rhodecode.model.repos_group import ReposGroupModel | |
19 | from rhodecode.model.forms import ReposGroupForm |
|
19 | from rhodecode.model.forms import ReposGroupForm | |
|
20 | from rhodecode.model.meta import Session | |||
20 |
|
21 | |||
21 | log = logging.getLogger(__name__) |
|
22 | log = logging.getLogger(__name__) | |
22 |
|
23 | |||
@@ -65,12 +66,12 b' class ReposGroupsController(BaseControll' | |||||
65 | """POST /repos_groups: Create a new item""" |
|
66 | """POST /repos_groups: Create a new item""" | |
66 | # url('repos_groups') |
|
67 | # url('repos_groups') | |
67 | self.__load_defaults() |
|
68 | self.__load_defaults() | |
68 | repos_group_model = ReposGroupModel() |
|
|||
69 | repos_group_form = ReposGroupForm(available_groups= |
|
69 | repos_group_form = ReposGroupForm(available_groups= | |
70 | c.repo_groups_choices)() |
|
70 | c.repo_groups_choices)() | |
71 | try: |
|
71 | try: | |
72 | form_result = repos_group_form.to_python(dict(request.POST)) |
|
72 | form_result = repos_group_form.to_python(dict(request.POST)) | |
73 |
|
|
73 | ReposGroupModel().create(form_result) | |
|
74 | Session().commit() | |||
74 | h.flash(_('created repos group %s') \ |
|
75 | h.flash(_('created repos group %s') \ | |
75 | % form_result['group_name'], category='success') |
|
76 | % form_result['group_name'], category='success') | |
76 | #TODO: in futureaction_logger(, '', '', '', self.sa) |
|
77 | #TODO: in futureaction_logger(, '', '', '', self.sa) | |
@@ -110,14 +111,14 b' class ReposGroupsController(BaseControll' | |||||
110 | self.__load_defaults() |
|
111 | self.__load_defaults() | |
111 | c.repos_group = RepoGroup.get(id) |
|
112 | c.repos_group = RepoGroup.get(id) | |
112 |
|
113 | |||
113 | repos_group_model = ReposGroupModel() |
|
|||
114 | repos_group_form = ReposGroupForm(edit=True, |
|
114 | repos_group_form = ReposGroupForm(edit=True, | |
115 | old_data=c.repos_group.get_dict(), |
|
115 | old_data=c.repos_group.get_dict(), | |
116 | available_groups= |
|
116 | available_groups= | |
117 | c.repo_groups_choices)() |
|
117 | c.repo_groups_choices)() | |
118 | try: |
|
118 | try: | |
119 | form_result = repos_group_form.to_python(dict(request.POST)) |
|
119 | form_result = repos_group_form.to_python(dict(request.POST)) | |
120 |
|
|
120 | ReposGroupModel().update(id, form_result) | |
|
121 | Session().commit() | |||
121 | h.flash(_('updated repos group %s') \ |
|
122 | h.flash(_('updated repos group %s') \ | |
122 | % form_result['group_name'], category='success') |
|
123 | % form_result['group_name'], category='success') | |
123 | #TODO: in futureaction_logger(, '', '', '', self.sa) |
|
124 | #TODO: in futureaction_logger(, '', '', '', self.sa) | |
@@ -147,7 +148,6 b' class ReposGroupsController(BaseControll' | |||||
147 | # method='delete') |
|
148 | # method='delete') | |
148 | # url('repos_group', id=ID) |
|
149 | # url('repos_group', id=ID) | |
149 |
|
150 | |||
150 | repos_group_model = ReposGroupModel() |
|
|||
151 | gr = RepoGroup.get(id) |
|
151 | gr = RepoGroup.get(id) | |
152 | repos = gr.repositories.all() |
|
152 | repos = gr.repositories.all() | |
153 | if repos: |
|
153 | if repos: | |
@@ -157,7 +157,8 b' class ReposGroupsController(BaseControll' | |||||
157 | return redirect(url('repos_groups')) |
|
157 | return redirect(url('repos_groups')) | |
158 |
|
158 | |||
159 | try: |
|
159 | try: | |
160 |
|
|
160 | ReposGroupModel().delete(id) | |
|
161 | Session().commit() | |||
161 | h.flash(_('removed repos group %s' % gr.group_name), category='success') |
|
162 | h.flash(_('removed repos group %s' % gr.group_name), category='success') | |
162 | #TODO: in future action_logger(, '', '', '', self.sa) |
|
163 | #TODO: in future action_logger(, '', '', '', self.sa) | |
163 | except IntegrityError, e: |
|
164 | except IntegrityError, e: |
@@ -1,19 +1,21 b'' | |||||
1 | import traceback |
|
1 | import traceback | |
2 | import logging |
|
2 | import logging | |
3 |
|
3 | |||
|
4 | from sqlalchemy.orm.exc import NoResultFound | |||
|
5 | ||||
4 | from rhodecode.controllers.api import JSONRPCController, JSONRPCError |
|
6 | from rhodecode.controllers.api import JSONRPCController, JSONRPCError | |
5 | from rhodecode.lib.auth import HasPermissionAllDecorator, \ |
|
7 | from rhodecode.lib.auth import HasPermissionAllDecorator, \ | |
6 | HasPermissionAnyDecorator |
|
8 | HasPermissionAnyDecorator | |
|
9 | ||||
|
10 | from rhodecode.model.meta import Session | |||
7 | from rhodecode.model.scm import ScmModel |
|
11 | from rhodecode.model.scm import ScmModel | |
8 |
|
||||
9 | from rhodecode.model.db import User, UsersGroup, RepoGroup, Repository |
|
12 | from rhodecode.model.db import User, UsersGroup, RepoGroup, Repository | |
10 | from rhodecode.model.repo import RepoModel |
|
13 | from rhodecode.model.repo import RepoModel | |
11 | from rhodecode.model.user import UserModel |
|
14 | from rhodecode.model.user import UserModel | |
12 | from rhodecode.model.repo_permission import RepositoryPermissionModel |
|
15 | from rhodecode.model.repo_permission import RepositoryPermissionModel | |
13 | from rhodecode.model.users_group import UsersGroupModel |
|
16 | from rhodecode.model.users_group import UsersGroupModel | |
14 | from rhodecode.model import users_group |
|
|||
15 | from rhodecode.model.repos_group import ReposGroupModel |
|
17 | from rhodecode.model.repos_group import ReposGroupModel | |
16 | from sqlalchemy.orm.exc import NoResultFound |
|
18 | ||
17 |
|
19 | |||
18 | log = logging.getLogger(__name__) |
|
20 | log = logging.getLogger(__name__) | |
19 |
|
21 | |||
@@ -116,8 +118,9 b' class ApiController(JSONRPCController):' | |||||
116 | raise JSONRPCError("user %s already exist" % username) |
|
118 | raise JSONRPCError("user %s already exist" % username) | |
117 |
|
119 | |||
118 | try: |
|
120 | try: | |
119 |
UserModel().create_or_update(username, password, email, firstname, |
|
121 | UserModel().create_or_update(username, password, email, firstname, | |
120 | lastname, active, admin, ldap_dn) |
|
122 | lastname, active, admin, ldap_dn) | |
|
123 | Session().commit() | |||
121 | return dict(msg='created new user %s' % username) |
|
124 | return dict(msg='created new user %s' % username) | |
122 | except Exception: |
|
125 | except Exception: | |
123 | log.error(traceback.format_exc()) |
|
126 | log.error(traceback.format_exc()) | |
@@ -194,9 +197,8 b' class ApiController(JSONRPCController):' | |||||
194 | raise JSONRPCError("users group %s already exist" % name) |
|
197 | raise JSONRPCError("users group %s already exist" % name) | |
195 |
|
198 | |||
196 | try: |
|
199 | try: | |
197 | form_data = dict(users_group_name=name, |
|
200 | ug = UsersGroupModel().create(name=name, active=active) | |
198 | users_group_active=active) |
|
201 | Session().commit() | |
199 | ug = UsersGroup.create(form_data) |
|
|||
200 | return dict(id=ug.users_group_id, |
|
202 | return dict(id=ug.users_group_id, | |
201 | msg='created new users group %s' % name) |
|
203 | msg='created new users group %s' % name) | |
202 | except Exception: |
|
204 | except Exception: | |
@@ -224,7 +226,7 b' class ApiController(JSONRPCController):' | |||||
224 | raise JSONRPCError('unknown user %s' % user_name) |
|
226 | raise JSONRPCError('unknown user %s' % user_name) | |
225 |
|
227 | |||
226 | ugm = UsersGroupModel().add_user_to_group(users_group, user) |
|
228 | ugm = UsersGroupModel().add_user_to_group(users_group, user) | |
227 |
|
229 | Session().commit() | ||
228 | return dict(id=ugm.users_group_member_id, |
|
230 | return dict(id=ugm.users_group_member_id, | |
229 | msg='created new users group member') |
|
231 | msg='created new users group member') | |
230 | except Exception: |
|
232 | except Exception: | |
@@ -291,7 +293,7 b' class ApiController(JSONRPCController):' | |||||
291 | return result |
|
293 | return result | |
292 |
|
294 | |||
293 | @HasPermissionAnyDecorator('hg.admin', 'hg.create.repository') |
|
295 | @HasPermissionAnyDecorator('hg.admin', 'hg.create.repository') | |
294 |
def create_repo(self, apiuser, name, owner_name, description='', |
|
296 | def create_repo(self, apiuser, name, owner_name, description='', | |
295 | repo_type='hg', private=False): |
|
297 | repo_type='hg', private=False): | |
296 | """ |
|
298 | """ | |
297 | Create a repository |
|
299 | Create a repository | |
@@ -332,6 +334,7 b' class ApiController(JSONRPCController):' | |||||
332 | repo_type=repo_type, |
|
334 | repo_type=repo_type, | |
333 | repo_group=parent_id, |
|
335 | repo_group=parent_id, | |
334 | clone_uri=None), owner) |
|
336 | clone_uri=None), owner) | |
|
337 | Session().commit() | |||
335 | except Exception: |
|
338 | except Exception: | |
336 | log.error(traceback.format_exc()) |
|
339 | log.error(traceback.format_exc()) | |
337 | raise JSONRPCError('failed to create repository %s' % name) |
|
340 | raise JSONRPCError('failed to create repository %s' % name) | |
@@ -360,6 +363,7 b' class ApiController(JSONRPCController):' | |||||
360 |
|
363 | |||
361 | RepositoryPermissionModel()\ |
|
364 | RepositoryPermissionModel()\ | |
362 | .update_or_delete_user_permission(repo, user, perm) |
|
365 | .update_or_delete_user_permission(repo, user, perm) | |
|
366 | Session().commit() | |||
363 | except Exception: |
|
367 | except Exception: | |
364 | log.error(traceback.format_exc()) |
|
368 | log.error(traceback.format_exc()) | |
365 | raise JSONRPCError('failed to edit permission %(repo)s for %(user)s' |
|
369 | raise JSONRPCError('failed to edit permission %(repo)s for %(user)s' |
@@ -78,16 +78,11 b' class DbManage(object):' | |||||
78 | log.info('Created tables for %s', self.dbname) |
|
78 | log.info('Created tables for %s', self.dbname) | |
79 |
|
79 | |||
80 | def set_db_version(self): |
|
80 | def set_db_version(self): | |
81 | try: |
|
81 | ver = DbMigrateVersion() | |
82 | ver = DbMigrateVersion() |
|
82 | ver.version = __dbversion__ | |
83 | ver.version = __dbversion__ |
|
83 | ver.repository_id = 'rhodecode_db_migrations' | |
84 |
|
|
84 | ver.repository_path = 'versions' | |
85 | ver.repository_path = 'versions' |
|
85 | self.sa.add(ver) | |
86 | self.sa.add(ver) |
|
|||
87 | self.sa.commit() |
|
|||
88 | except: |
|
|||
89 | self.sa.rollback() |
|
|||
90 | raise |
|
|||
91 | log.info('db version set to: %s', __dbversion__) |
|
86 | log.info('db version set to: %s', __dbversion__) | |
92 |
|
87 | |||
93 | def upgrade(self): |
|
88 | def upgrade(self): | |
@@ -162,7 +157,7 b' class DbManage(object):' | |||||
162 | self.klass.fix_settings() |
|
157 | self.klass.fix_settings() | |
163 | print ('Adding ldap defaults') |
|
158 | print ('Adding ldap defaults') | |
164 | self.klass.create_ldap_options(skip_existing=True) |
|
159 | self.klass.create_ldap_options(skip_existing=True) | |
165 |
|
160 | |||
166 | upgrade_steps = [0] + range(curr_version + 1, __dbversion__ + 1) |
|
161 | upgrade_steps = [0] + range(curr_version + 1, __dbversion__ + 1) | |
167 |
|
162 | |||
168 | #CALL THE PROPER ORDER OF STEPS TO PERFORM FULL UPGRADE |
|
163 | #CALL THE PROPER ORDER OF STEPS TO PERFORM FULL UPGRADE | |
@@ -299,43 +294,33 b' class DbManage(object):' | |||||
299 | dotencode_disable.ui_value = 'false' |
|
294 | dotencode_disable.ui_value = 'false' | |
300 |
|
295 | |||
301 | # enable largefiles |
|
296 | # enable largefiles | |
302 |
|
|
297 | largefiles = RhodeCodeUi() | |
303 |
|
|
298 | largefiles.ui_section = 'extensions' | |
304 |
|
|
299 | largefiles.ui_key = 'largefiles' | |
305 |
|
|
300 | largefiles.ui_value = '1' | |
306 |
|
301 | |||
307 | try: |
|
302 | self.sa.add(hooks1) | |
308 |
|
|
303 | self.sa.add(hooks2) | |
309 |
|
|
304 | self.sa.add(hooks3) | |
310 |
|
|
305 | self.sa.add(hooks4) | |
311 |
|
|
306 | self.sa.add(largefiles) | |
312 | self.sa.add(dotencode_disable) |
|
|||
313 | self.sa.commit() |
|
|||
314 | except: |
|
|||
315 | self.sa.rollback() |
|
|||
316 | raise |
|
|||
317 |
|
307 | |||
318 | def create_ldap_options(self,skip_existing=False): |
|
308 | def create_ldap_options(self, skip_existing=False): | |
319 | """Creates ldap settings""" |
|
309 | """Creates ldap settings""" | |
320 |
|
310 | |||
321 | try: |
|
311 | for k, v in [('ldap_active', 'false'), ('ldap_host', ''), | |
322 |
|
|
312 | ('ldap_port', '389'), ('ldap_tls_kind', 'PLAIN'), | |
323 |
|
|
313 | ('ldap_tls_reqcert', ''), ('ldap_dn_user', ''), | |
324 |
|
|
314 | ('ldap_dn_pass', ''), ('ldap_base_dn', ''), | |
325 |
|
|
315 | ('ldap_filter', ''), ('ldap_search_scope', ''), | |
326 |
|
|
316 | ('ldap_attr_login', ''), ('ldap_attr_firstname', ''), | |
327 |
|
|
317 | ('ldap_attr_lastname', ''), ('ldap_attr_email', '')]: | |
328 | ('ldap_attr_lastname', ''), ('ldap_attr_email', '')]: |
|
|||
329 |
|
318 | |||
330 |
|
|
319 | if skip_existing and RhodeCodeSetting.get_by_name(k) != None: | |
331 |
|
|
320 | log.debug('Skipping option %s' % k) | |
332 |
|
|
321 | continue | |
333 |
|
|
322 | setting = RhodeCodeSetting(k, v) | |
334 |
|
|
323 | self.sa.add(setting) | |
335 | self.sa.commit() |
|
|||
336 | except: |
|
|||
337 | self.sa.rollback() |
|
|||
338 | raise |
|
|||
339 |
|
324 | |||
340 | def config_prompt(self, test_repo_path='', retries=3): |
|
325 | def config_prompt(self, test_repo_path='', retries=3): | |
341 | if retries == 3: |
|
326 | if retries == 3: | |
@@ -401,20 +386,14 b' class DbManage(object):' | |||||
401 | hgsettings2 = RhodeCodeSetting('title', 'RhodeCode') |
|
386 | hgsettings2 = RhodeCodeSetting('title', 'RhodeCode') | |
402 | hgsettings3 = RhodeCodeSetting('ga_code', '') |
|
387 | hgsettings3 = RhodeCodeSetting('ga_code', '') | |
403 |
|
388 | |||
404 | try: |
|
389 | self.sa.add(web1) | |
405 |
|
|
390 | self.sa.add(web2) | |
406 |
|
|
391 | self.sa.add(web3) | |
407 |
|
|
392 | self.sa.add(web4) | |
408 |
|
|
393 | self.sa.add(paths) | |
409 |
|
|
394 | self.sa.add(hgsettings1) | |
410 |
|
|
395 | self.sa.add(hgsettings2) | |
411 |
|
|
396 | self.sa.add(hgsettings3) | |
412 | self.sa.add(hgsettings3) |
|
|||
413 |
|
||||
414 | self.sa.commit() |
|
|||
415 | except: |
|
|||
416 | self.sa.rollback() |
|
|||
417 | raise |
|
|||
418 |
|
397 | |||
419 | self.create_ldap_options() |
|
398 | self.create_ldap_options() | |
420 |
|
399 | |||
@@ -422,18 +401,18 b' class DbManage(object):' | |||||
422 |
|
401 | |||
423 | def create_user(self, username, password, email='', admin=False): |
|
402 | def create_user(self, username, password, email='', admin=False): | |
424 | log.info('creating user %s', username) |
|
403 | log.info('creating user %s', username) | |
425 |
UserModel().create_or_update(username, password, email, |
|
404 | UserModel().create_or_update(username, password, email, | |
426 |
name='RhodeCode', lastname='Admin', |
|
405 | name='RhodeCode', lastname='Admin', | |
427 | active=True, admin=admin) |
|
406 | active=True, admin=admin) | |
428 |
|
407 | |||
429 | def create_default_user(self): |
|
408 | def create_default_user(self): | |
430 | log.info('creating default user') |
|
409 | log.info('creating default user') | |
431 | # create default user for handling default permissions. |
|
410 | # create default user for handling default permissions. | |
432 |
UserModel().create_or_update(username='default', |
|
411 | UserModel().create_or_update(username='default', | |
433 |
password=str(uuid.uuid1())[:8], |
|
412 | password=str(uuid.uuid1())[:8], | |
434 |
email='anonymous@rhodecode.org', |
|
413 | email='anonymous@rhodecode.org', | |
435 | name='Anonymous', lastname='User') |
|
414 | name='Anonymous', lastname='User') | |
436 |
|
415 | |||
437 | def create_permissions(self): |
|
416 | def create_permissions(self): | |
438 | #module.(access|create|change|delete)_[name] |
|
417 | #module.(access|create|change|delete)_[name] | |
439 | #module.(read|write|owner) |
|
418 | #module.(read|write|owner) | |
@@ -458,12 +437,7 b' class DbManage(object):' | |||||
458 | new_perm = Permission() |
|
437 | new_perm = Permission() | |
459 | new_perm.permission_name = p[0] |
|
438 | new_perm.permission_name = p[0] | |
460 | new_perm.permission_longname = p[1] |
|
439 | new_perm.permission_longname = p[1] | |
461 | try: |
|
440 | self.sa.add(new_perm) | |
462 | self.sa.add(new_perm) |
|
|||
463 | self.sa.commit() |
|
|||
464 | except: |
|
|||
465 | self.sa.rollback() |
|
|||
466 | raise |
|
|||
467 |
|
441 | |||
468 | def populate_default_permissions(self): |
|
442 | def populate_default_permissions(self): | |
469 | log.info('creating default user permissions') |
|
443 | log.info('creating default user permissions') | |
@@ -489,11 +463,6 b' class DbManage(object):' | |||||
489 | .filter(Permission.permission_name == 'repository.read')\ |
|
463 | .filter(Permission.permission_name == 'repository.read')\ | |
490 | .scalar() |
|
464 | .scalar() | |
491 |
|
465 | |||
492 | try: |
|
466 | self.sa.add(reg_perm) | |
493 |
|
|
467 | self.sa.add(create_repo_perm) | |
494 |
|
|
468 | self.sa.add(default_repo_perm) | |
495 | self.sa.add(default_repo_perm) |
|
|||
496 | self.sa.commit() |
|
|||
497 | except: |
|
|||
498 | self.sa.rollback() |
|
|||
499 | raise |
|
@@ -51,6 +51,7 b' from rhodecode.lib.caching_query import ' | |||||
51 | from rhodecode.model import meta |
|
51 | from rhodecode.model import meta | |
52 | from rhodecode.model.db import Repository, User, RhodeCodeUi, \ |
|
52 | from rhodecode.model.db import Repository, User, RhodeCodeUi, \ | |
53 | UserLog, RepoGroup, RhodeCodeSetting |
|
53 | UserLog, RepoGroup, RhodeCodeSetting | |
|
54 | from rhodecode.model.meta import Session | |||
54 |
|
55 | |||
55 | log = logging.getLogger(__name__) |
|
56 | log = logging.getLogger(__name__) | |
56 |
|
57 | |||
@@ -509,7 +510,7 b' def create_test_env(repos_test_path, con' | |||||
509 | dbmanage.admin_prompt() |
|
510 | dbmanage.admin_prompt() | |
510 | dbmanage.create_permissions() |
|
511 | dbmanage.create_permissions() | |
511 | dbmanage.populate_default_permissions() |
|
512 | dbmanage.populate_default_permissions() | |
512 |
|
513 | Session().commit() | ||
513 | # PART TWO make test repo |
|
514 | # PART TWO make test repo | |
514 | log.debug('making test vcs repositories') |
|
515 | log.debug('making test vcs repositories') | |
515 |
|
516 |
@@ -109,7 +109,6 b' class ChangesetCommentsModel(BaseModel):' | |||||
109 | recipients=mention_recipients, |
|
109 | recipients=mention_recipients, | |
110 | type_=Notification.TYPE_CHANGESET_COMMENT) |
|
110 | type_=Notification.TYPE_CHANGESET_COMMENT) | |
111 |
|
111 | |||
112 | self.sa.commit() |
|
|||
113 | return comment |
|
112 | return comment | |
114 |
|
113 | |||
115 | def delete(self, comment): |
|
114 | def delete(self, comment): |
@@ -70,8 +70,8 b' class PermissionModel(BaseModel):' | |||||
70 |
|
70 | |||
71 | def update(self, form_result): |
|
71 | def update(self, form_result): | |
72 | perm_user = self.sa.query(User)\ |
|
72 | perm_user = self.sa.query(User)\ | |
73 | .filter(User.username == |
|
73 | .filter(User.username == | |
74 | form_result['perm_user_name']).scalar() |
|
74 | form_result['perm_user_name']).scalar() | |
75 | u2p = self.sa.query(UserToPerm).filter(UserToPerm.user == |
|
75 | u2p = self.sa.query(UserToPerm).filter(UserToPerm.user == | |
76 | perm_user).all() |
|
76 | perm_user).all() | |
77 | if len(u2p) != 3: |
|
77 | if len(u2p) != 3: | |
@@ -110,8 +110,6 b' class PermissionModel(BaseModel):' | |||||
110 | perm_user.active = bool(form_result['anonymous']) |
|
110 | perm_user.active = bool(form_result['anonymous']) | |
111 | self.sa.add(perm_user) |
|
111 | self.sa.add(perm_user) | |
112 |
|
112 | |||
113 | self.sa.commit() |
|
|||
114 | except (DatabaseError,): |
|
113 | except (DatabaseError,): | |
115 | log.error(traceback.format_exc()) |
|
114 | log.error(traceback.format_exc()) | |
116 | self.sa.rollback() |
|
|||
117 | raise |
|
115 | raise |
@@ -50,13 +50,11 b' class RepositoryPermissionModel(BaseMode' | |||||
50 | p.repository = repository |
|
50 | p.repository = repository | |
51 | p.permission = permission |
|
51 | p.permission = permission | |
52 | self.sa.add(p) |
|
52 | self.sa.add(p) | |
53 | self.sa.commit() |
|
|||
54 |
|
53 | |||
55 | def delete_user_permission(self, repository, user): |
|
54 | def delete_user_permission(self, repository, user): | |
56 | current = self.get_user_permission(repository, user) |
|
55 | current = self.get_user_permission(repository, user) | |
57 | if current: |
|
56 | if current: | |
58 | self.sa.delete(current) |
|
57 | self.sa.delete(current) | |
59 | self.sa.commit() |
|
|||
60 |
|
58 | |||
61 | def update_or_delete_user_permission(self, repository, user, permission): |
|
59 | def update_or_delete_user_permission(self, repository, user, permission): | |
62 | if permission: |
|
60 | if permission: |
@@ -111,14 +111,12 b' class ReposGroupModel(BaseModel):' | |||||
111 | new_repos_group.group_name = new_repos_group.get_new_name(form_data['group_name']) |
|
111 | new_repos_group.group_name = new_repos_group.get_new_name(form_data['group_name']) | |
112 |
|
112 | |||
113 | self.sa.add(new_repos_group) |
|
113 | self.sa.add(new_repos_group) | |
114 |
|
114 | self.sa.flush() | ||
115 | self.__create_group(new_repos_group.group_name) |
|
115 | self.__create_group(new_repos_group.group_name) | |
116 |
|
116 | |||
117 | self.sa.commit() |
|
|||
118 | return new_repos_group |
|
117 | return new_repos_group | |
119 | except: |
|
118 | except: | |
120 | log.error(traceback.format_exc()) |
|
119 | log.error(traceback.format_exc()) | |
121 | self.sa.rollback() |
|
|||
122 | raise |
|
120 | raise | |
123 |
|
121 | |||
124 | def update(self, repos_group_id, form_data): |
|
122 | def update(self, repos_group_id, form_data): | |
@@ -126,7 +124,7 b' class ReposGroupModel(BaseModel):' | |||||
126 | try: |
|
124 | try: | |
127 | repos_group = RepoGroup.get(repos_group_id) |
|
125 | repos_group = RepoGroup.get(repos_group_id) | |
128 | old_path = repos_group.full_path |
|
126 | old_path = repos_group.full_path | |
129 |
|
127 | |||
130 | # change properties |
|
128 | # change properties | |
131 | repos_group.group_description = form_data['group_description'] |
|
129 | repos_group.group_description = form_data['group_description'] | |
132 | repos_group.parent_group = RepoGroup.get(form_data['group_parent_id']) |
|
130 | repos_group.parent_group = RepoGroup.get(form_data['group_parent_id']) | |
@@ -144,11 +142,9 b' class ReposGroupModel(BaseModel):' | |||||
144 | r.repo_name = r.get_new_name(r.just_name) |
|
142 | r.repo_name = r.get_new_name(r.just_name) | |
145 | self.sa.add(r) |
|
143 | self.sa.add(r) | |
146 |
|
144 | |||
147 | self.sa.commit() |
|
|||
148 | return repos_group |
|
145 | return repos_group | |
149 | except: |
|
146 | except: | |
150 | log.error(traceback.format_exc()) |
|
147 | log.error(traceback.format_exc()) | |
151 | self.sa.rollback() |
|
|||
152 | raise |
|
148 | raise | |
153 |
|
149 | |||
154 | def delete(self, users_group_id): |
|
150 | def delete(self, users_group_id): | |
@@ -156,8 +152,6 b' class ReposGroupModel(BaseModel):' | |||||
156 | users_group = RepoGroup.get(users_group_id) |
|
152 | users_group = RepoGroup.get(users_group_id) | |
157 | self.sa.delete(users_group) |
|
153 | self.sa.delete(users_group) | |
158 | self.__delete_group(users_group) |
|
154 | self.__delete_group(users_group) | |
159 | self.sa.commit() |
|
|||
160 | except: |
|
155 | except: | |
161 | log.error(traceback.format_exc()) |
|
156 | log.error(traceback.format_exc()) | |
162 | self.sa.rollback() |
|
|||
163 | raise |
|
157 | raise |
@@ -129,13 +129,10 b' class UserModel(BaseModel):' | |||||
129 | new_user.ldap_dn = safe_unicode(ldap_dn) if ldap_dn else None |
|
129 | new_user.ldap_dn = safe_unicode(ldap_dn) if ldap_dn else None | |
130 | new_user.name = name |
|
130 | new_user.name = name | |
131 | new_user.lastname = lastname |
|
131 | new_user.lastname = lastname | |
132 |
|
||||
133 | self.sa.add(new_user) |
|
132 | self.sa.add(new_user) | |
134 | self.sa.commit() |
|
|||
135 | return new_user |
|
133 | return new_user | |
136 | except (DatabaseError,): |
|
134 | except (DatabaseError,): | |
137 | log.error(traceback.format_exc()) |
|
135 | log.error(traceback.format_exc()) | |
138 | self.sa.rollback() |
|
|||
139 | raise |
|
136 | raise | |
140 |
|
137 | |||
141 |
|
138 |
@@ -43,22 +43,7 b' class UsersGroupModel(BaseModel):' | |||||
43 | def get_by_name(self, name, cache=False, case_insensitive=False): |
|
43 | def get_by_name(self, name, cache=False, case_insensitive=False): | |
44 | return UsersGroup.get_by_group_name(name, cache, case_insensitive) |
|
44 | return UsersGroup.get_by_group_name(name, cache, case_insensitive) | |
45 |
|
45 | |||
46 |
def create(self, |
|
46 | def create(self, name, active=True): | |
47 | try: |
|
|||
48 | new_users_group = UsersGroup() |
|
|||
49 | for k, v in form_data.items(): |
|
|||
50 | setattr(new_users_group, k, v) |
|
|||
51 |
|
||||
52 | self.sa.add(new_users_group) |
|
|||
53 | self.sa.commit() |
|
|||
54 | return new_users_group |
|
|||
55 | except: |
|
|||
56 | log.error(traceback.format_exc()) |
|
|||
57 | self.sa.rollback() |
|
|||
58 | raise |
|
|||
59 |
|
||||
60 |
|
||||
61 | def create_(self, name, active=True): |
|
|||
62 | new = UsersGroup() |
|
47 | new = UsersGroup() | |
63 | new.users_group_name = name |
|
48 | new.users_group_name = name | |
64 | new.users_group_active = active |
|
49 | new.users_group_active = active | |
@@ -84,9 +69,7 b' class UsersGroupModel(BaseModel):' | |||||
84 | user.group_member.append(users_group_member) |
|
69 | user.group_member.append(users_group_member) | |
85 |
|
70 | |||
86 | self.sa.add(users_group_member) |
|
71 | self.sa.add(users_group_member) | |
87 | self.sa.commit() |
|
|||
88 | return users_group_member |
|
72 | return users_group_member | |
89 | except: |
|
73 | except: | |
90 | log.error(traceback.format_exc()) |
|
74 | log.error(traceback.format_exc()) | |
91 | self.sa.rollback() |
|
|||
92 | raise |
|
75 | raise |
@@ -53,7 +53,7 b' add_cache(conf)' | |||||
53 |
|
53 | |||
54 | USER = 'test_admin' |
|
54 | USER = 'test_admin' | |
55 | PASS = 'test12' |
|
55 | PASS = 'test12' | |
56 | HOST = '127.0.0.1:5000' |
|
56 | HOST = 'hg.local' | |
57 | METHOD = 'pull' |
|
57 | METHOD = 'pull' | |
58 | DEBUG = True |
|
58 | DEBUG = True | |
59 | log = logging.getLogger(__name__) |
|
59 | log = logging.getLogger(__name__) |
@@ -42,6 +42,7 b' class TestReposGroups(unittest.TestCase)' | |||||
42 | group_description=desc, |
|
42 | group_description=desc, | |
43 | group_parent_id=parent_id) |
|
43 | group_parent_id=parent_id) | |
44 | gr = ReposGroupModel().create(form_data) |
|
44 | gr = ReposGroupModel().create(form_data) | |
|
45 | Session.commit() | |||
45 | return gr |
|
46 | return gr | |
46 |
|
47 | |||
47 | def __delete_group(self, id_): |
|
48 | def __delete_group(self, id_): | |
@@ -65,7 +66,7 b' class TestReposGroups(unittest.TestCase)' | |||||
65 |
|
66 | |||
66 | def test_create_same_name_group(self): |
|
67 | def test_create_same_name_group(self): | |
67 | self.assertRaises(IntegrityError, lambda:self.__make_group('newGroup')) |
|
68 | self.assertRaises(IntegrityError, lambda:self.__make_group('newGroup')) | |
68 |
|
69 | Session().rollback() | ||
69 |
|
70 | |||
70 | def test_same_subgroup(self): |
|
71 | def test_same_subgroup(self): | |
71 | sg1 = self.__make_group('sub1', parent_id=self.g1.group_id) |
|
72 | sg1 = self.__make_group('sub1', parent_id=self.g1.group_id) | |
@@ -162,16 +163,20 b' class TestUser(unittest.TestCase):' | |||||
162 | usr = UserModel().create_or_update(username=u'test_user', password=u'qweqwe', |
|
163 | usr = UserModel().create_or_update(username=u'test_user', password=u'qweqwe', | |
163 | email=u'u232@rhodecode.org', |
|
164 | email=u'u232@rhodecode.org', | |
164 | name=u'u1', lastname=u'u1') |
|
165 | name=u'u1', lastname=u'u1') | |
|
166 | Session().commit() | |||
165 | self.assertEqual(User.get_by_username(u'test_user'), usr) |
|
167 | self.assertEqual(User.get_by_username(u'test_user'), usr) | |
166 |
|
168 | |||
167 | # make users group |
|
169 | # make users group | |
168 |
users_group = UsersGroupModel().create |
|
170 | users_group = UsersGroupModel().create('some_example_group') | |
169 | Session().commit() |
|
171 | Session().commit() | |
|
172 | ||||
170 | UsersGroupModel().add_user_to_group(users_group, usr) |
|
173 | UsersGroupModel().add_user_to_group(users_group, usr) | |
|
174 | Session().commit() | |||
171 |
|
175 | |||
172 | self.assertEqual(UsersGroup.get(users_group.users_group_id), users_group) |
|
176 | self.assertEqual(UsersGroup.get(users_group.users_group_id), users_group) | |
173 | self.assertEqual(UsersGroupMember.query().count(), 1) |
|
177 | self.assertEqual(UsersGroupMember.query().count(), 1) | |
174 | UserModel().delete(usr.user_id) |
|
178 | UserModel().delete(usr.user_id) | |
|
179 | Session().commit() | |||
175 |
|
180 | |||
176 | self.assertEqual(UsersGroupMember.query().all(), []) |
|
181 | self.assertEqual(UsersGroupMember.query().all(), []) | |
177 |
|
182 | |||
@@ -182,15 +187,24 b' class TestNotifications(unittest.TestCas' | |||||
182 | self.u1 = UserModel().create_or_update(username=u'u1', |
|
187 | self.u1 = UserModel().create_or_update(username=u'u1', | |
183 | password=u'qweqwe', |
|
188 | password=u'qweqwe', | |
184 | email=u'u1@rhodecode.org', |
|
189 | email=u'u1@rhodecode.org', | |
185 |
name=u'u1', lastname=u'u1') |
|
190 | name=u'u1', lastname=u'u1') | |
|
191 | Session.commit() | |||
|
192 | self.u1 = self.u1.user_id | |||
|
193 | ||||
186 | self.u2 = UserModel().create_or_update(username=u'u2', |
|
194 | self.u2 = UserModel().create_or_update(username=u'u2', | |
187 | password=u'qweqwe', |
|
195 | password=u'qweqwe', | |
188 | email=u'u2@rhodecode.org', |
|
196 | email=u'u2@rhodecode.org', | |
189 |
name=u'u2', lastname=u'u3') |
|
197 | name=u'u2', lastname=u'u3') | |
|
198 | Session.commit() | |||
|
199 | self.u2 = self.u2.user_id | |||
|
200 | ||||
190 | self.u3 = UserModel().create_or_update(username=u'u3', |
|
201 | self.u3 = UserModel().create_or_update(username=u'u3', | |
191 | password=u'qweqwe', |
|
202 | password=u'qweqwe', | |
192 | email=u'u3@rhodecode.org', |
|
203 | email=u'u3@rhodecode.org', | |
193 |
name=u'u3', lastname=u'u3') |
|
204 | name=u'u3', lastname=u'u3') | |
|
205 | Session.commit() | |||
|
206 | self.u3 = self.u3.user_id | |||
|
207 | ||||
194 | super(TestNotifications, self).__init__(methodName=methodName) |
|
208 | super(TestNotifications, self).__init__(methodName=methodName) | |
195 |
|
209 | |||
196 | def _clean_notifications(self): |
|
210 | def _clean_notifications(self): |
@@ -28,6 +28,7 b' import logging' | |||||
28 |
|
28 | |||
29 | from rhodecode.config.environment import load_environment |
|
29 | from rhodecode.config.environment import load_environment | |
30 | from rhodecode.lib.db_manage import DbManage |
|
30 | from rhodecode.lib.db_manage import DbManage | |
|
31 | from rhodecode.model.meta import Session | |||
31 |
|
32 | |||
32 |
|
33 | |||
33 | log = logging.getLogger(__name__) |
|
34 | log = logging.getLogger(__name__) | |
@@ -45,5 +46,5 b' def setup_app(command, conf, vars):' | |||||
45 | dbmanage.admin_prompt() |
|
46 | dbmanage.admin_prompt() | |
46 | dbmanage.create_permissions() |
|
47 | dbmanage.create_permissions() | |
47 | dbmanage.populate_default_permissions() |
|
48 | dbmanage.populate_default_permissions() | |
48 |
|
49 | Session().commit() | ||
49 | load_environment(conf.global_conf, conf.local_conf, initial=True) |
|
50 | load_environment(conf.global_conf, conf.local_conf, initial=True) |
General Comments 0
You need to be logged in to leave comments.
Login now