##// END OF EJS Templates
Added group permission autofix for older version of rhodecode which didn't have default permissions for repos groups
marcink -
r1985:40f04021 beta
parent child Browse files
Show More
@@ -37,9 +37,11 b' from rhodecode.model.user import UserMod'
37 from rhodecode.lib.utils import ask_ok
37 from rhodecode.lib.utils import ask_ok
38 from rhodecode.model import init_model
38 from rhodecode.model import init_model
39 from rhodecode.model.db import User, Permission, RhodeCodeUi, \
39 from rhodecode.model.db import User, Permission, RhodeCodeUi, \
40 RhodeCodeSetting, UserToPerm, DbMigrateVersion
40 RhodeCodeSetting, UserToPerm, DbMigrateVersion, RepoGroup,\
41 UserRepoGroupToPerm
41
42
42 from sqlalchemy.engine import create_engine
43 from sqlalchemy.engine import create_engine
44 from rhodecode.model.repos_group import ReposGroupModel
43
45
44 log = logging.getLogger(__name__)
46 log = logging.getLogger(__name__)
45
47
@@ -170,7 +172,7 b' class DbManage(object):'
170
172
171 def step_4(self):
173 def step_4(self):
172 print ('TODO:')
174 print ('TODO:')
173 raise NotImplementedError()
175 self.klass.fixup_groups()
174
176
175 upgrade_steps = [0] + range(curr_version + 1, __dbversion__ + 1)
177 upgrade_steps = [0] + range(curr_version + 1, __dbversion__ + 1)
176
178
@@ -348,6 +350,21 b' class DbManage(object):'
348 setting = RhodeCodeSetting(k, v)
350 setting = RhodeCodeSetting(k, v)
349 self.sa.add(setting)
351 self.sa.add(setting)
350
352
353 def fixup_groups(self):
354 def_usr = User.get_by_username('default')
355 for g in RepoGroup.query().all():
356 g.group_name = g.get_new_name(g.name)
357 self.sa.add(g)
358 # get default perm
359 default = UserRepoGroupToPerm.query()\
360 .filter(UserRepoGroupToPerm.group == g)\
361 .filter(UserRepoGroupToPerm.user == def_usr)\
362 .scalar()
363
364 if default is None:
365 log.debug('missing default permission for group %s adding' % g)
366 ReposGroupModel()._create_default_perms(g)
367
351 def config_prompt(self, test_repo_path='', retries=3):
368 def config_prompt(self, test_repo_path='', retries=3):
352 if retries == 3:
369 if retries == 3:
353 log.info('Setting up repositories config')
370 log.info('Setting up repositories config')
@@ -50,7 +50,7 b' from rhodecode.lib.caching_query import '
50
50
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, UserRepoGroupToPerm
54 from rhodecode.model.meta import Session
54 from rhodecode.model.meta import Session
55 from rhodecode.model.repos_group import ReposGroupModel
55 from rhodecode.model.repos_group import ReposGroupModel
56
56
@@ -415,6 +415,23 b' def repo2db_mapper(initial_repo_list, re'
415 raise Exception('Missing administrative account !')
415 raise Exception('Missing administrative account !')
416 added = []
416 added = []
417
417
418 # fixup groups paths to new format on the fly. Helps with migration from
419 # old rhodecode versions also set permissions if they are not present !
420 # TODO: remove this in future, before release
421 def_usr = User.get_by_username('default')
422 for g in RepoGroup.query().all():
423 g.group_name = g.get_new_name(g.name)
424 sa.add(g)
425 # get default perm
426 default = UserRepoGroupToPerm.query()\
427 .filter(UserRepoGroupToPerm.group == g)\
428 .filter(UserRepoGroupToPerm.user == def_usr)\
429 .scalar()
430
431 if default is None:
432 log.debug('missing default permission for group %s adding' % g)
433 ReposGroupModel()._create_default_perms(g)
434
418 for name, repo in initial_repo_list.items():
435 for name, repo in initial_repo_list.items():
419 group = map_groups(name.split(Repository.url_sep()))
436 group = map_groups(name.split(Repository.url_sep()))
420 if not rm.get_by_repo_name(name, cache=False):
437 if not rm.get_by_repo_name(name, cache=False):
General Comments 0
You need to be logged in to leave comments. Login now