def create_repo_group(self, name, **kwargs): if 'skip_if_exists' in kwargs: del kwargs['skip_if_exists'] gr = RepoGroup.get_by_group_name(group_name=name) if gr: return gr form_data = self._get_group_create_params(group_name=name, **kwargs) owner = kwargs.get('cur_user', TEST_USER_ADMIN_LOGIN) gr = RepoGroupModel().create(group_name=form_data['group_name'], group_description=form_data['group_name'], owner=owner, parent=form_data['group_parent_id']) Session().commit() gr = RepoGroup.get_by_group_name(gr.group_name) return gr
def create_repo_group(self, name, **kwargs): if 'skip_if_exists' in kwargs: del kwargs['skip_if_exists'] gr = RepoGroup.get_by_group_name(group_name=name) if gr: return gr form_data = self._get_group_create_params(group_name=name, **kwargs) owner = kwargs.get('cur_user', TEST_USER_ADMIN_LOGIN) gr = RepoGroupModel().create( group_name=form_data['group_name'], group_description=form_data['group_name'], owner=owner, parent=form_data['group_parent_id']) Session().commit() gr = RepoGroup.get_by_group_name(gr.group_name) return gr
def test_update_group_parent(self): sg1 = fixture.create_repo_group('initial', parent_group_id=self.g1.group_id) new_sg1 = _update_repo_group(sg1.group_id, 'after', parent_id=self.g1.group_id) assert self.__check_path('test1', 'after') assert RepoGroup.get_by_group_name('test1/initial') is None new_sg1 = _update_repo_group(sg1.group_id, 'after', parent_id=self.g3.group_id) assert self.__check_path('test3', 'after') assert RepoGroup.get_by_group_name('test3/initial') == None new_sg1 = _update_repo_group(sg1.group_id, 'hello') assert self.__check_path('hello') assert RepoGroup.get_by_group_name('hello') == new_sg1
def permissions_setup_func(group_name='g0', perm='group.read', recursive='all', user_id=None): """ Resets all permissions to perm attribute """ if not user_id: user_id = test_u1_id permissions_setup_func(group_name, perm, recursive, user_id=kallithea.DEFAULT_USER_ID) repo_group = RepoGroup.get_by_group_name(group_name=group_name) if not repo_group: raise Exception('Cannot get group %s' % group_name) # Start with a baseline that current group can read recursive perms_updates = [[user_id, 'group.read', 'user']] RepoGroupModel()._update_permissions(repo_group, perms_updates=perms_updates, recursive='all', check_perms=False) perms_updates = [[user_id, perm, 'user']] RepoGroupModel()._update_permissions(repo_group, perms_updates=perms_updates, recursive=recursive, check_perms=False) Session().commit()
def test_update_group_parent(self): sg1 = fixture.create_repo_group(u'initial', parent_group_id=self.g1.group_id) new_sg1 = _update_repo_group(sg1.group_id, u'after', parent_id=self.g1.group_id) assert self.__check_path('test1', 'after') assert RepoGroup.get_by_group_name(u'test1/initial') == None new_sg1 = _update_repo_group(sg1.group_id, u'after', parent_id=self.g3.group_id) assert self.__check_path('test3', 'after') assert RepoGroup.get_by_group_name(u'test3/initial') == None new_sg1 = _update_repo_group(sg1.group_id, u'hello') assert self.__check_path('hello') assert RepoGroup.get_by_group_name(u'hello') == new_sg1
def permissions_setup_func(group_name='g0', perm='group.read', recursive='all', user_id=None): """ Resets all permissions to perm attribute """ if not user_id: user_id = test_u1_id # called by the @with_setup decorator also reset the default user stuff permissions_setup_func(group_name, perm, recursive, user_id=User.get_default_user().user_id) repo_group = RepoGroup.get_by_group_name(group_name=group_name) if not repo_group: raise Exception('Cannot get group %s' % group_name) perms_updates = [[user_id, perm, 'user']] RepoGroupModel()._update_permissions(repo_group, perms_updates=perms_updates, recursive=recursive, check_perms=False) Session().commit()
def permissions_setup_func(group_name='g0', perm='group.read', recursive='all', user_id=None): """ Resets all permissions to perm attribute """ if not user_id: user_id = test_u1_id permissions_setup_func(group_name, perm, recursive, user_id=User.get_default_user().user_id) repo_group = RepoGroup.get_by_group_name(group_name=group_name) if not repo_group: raise Exception('Cannot get group %s' % group_name) # Start with a baseline that current group can read recursive perms_updates = [[user_id, 'group.read', 'user']] RepoGroupModel()._update_permissions(repo_group, perms_updates=perms_updates, recursive='all', check_perms=False) perms_updates = [[user_id, perm, 'user']] RepoGroupModel()._update_permissions(repo_group, perms_updates=perms_updates, recursive=recursive, check_perms=False) Session().commit()
def test_update_group_parent(self): sg1 = fixture.create_repo_group(u'initial', group_parent_id=self.g1.group_id) new_sg1 = _update_group(sg1.group_id, u'after', parent_id=self.g1.group_id) self.assertTrue(self.__check_path('test1', 'after')) self.assertEqual(RepoGroup.get_by_group_name(u'test1/initial'), None) new_sg1 = _update_group(sg1.group_id, u'after', parent_id=self.g3.group_id) self.assertTrue(self.__check_path('test3', 'after')) self.assertEqual(RepoGroup.get_by_group_name(u'test3/initial'), None) new_sg1 = _update_group(sg1.group_id, u'hello') self.assertTrue(self.__check_path('hello')) self.assertEqual(RepoGroup.get_by_group_name(u'hello'), new_sg1)
def test_update_group_parent(self): sg1 = fixture.create_repo_group('initial', group_parent_id=self.g1.group_id) new_sg1 = _update_group(sg1.group_id, 'after', parent_id=self.g1.group_id) self.assertTrue(self.__check_path('test1', 'after')) self.assertEqual(RepoGroup.get_by_group_name('test1/initial'), None) new_sg1 = _update_group(sg1.group_id, 'after', parent_id=self.g3.group_id) self.assertTrue(self.__check_path('test3', 'after')) self.assertEqual(RepoGroup.get_by_group_name('test3/initial'), None) new_sg1 = _update_group(sg1.group_id, 'hello') self.assertTrue(self.__check_path('hello')) self.assertEqual(RepoGroup.get_by_group_name('hello'), new_sg1)
def user_and_repo_group_fail(): username = '******' groupname = 'repogroup_fail' user = fixture.create_user(name=username) repo_group = fixture.create_repo_group(name=groupname, cur_user=username) yield user, repo_group # cleanup if RepoGroup.get_by_group_name(groupname): fixture.destroy_repo_group(repo_group)
def create_repo_group(self, name, parent_group_id=None, **kwargs): assert '/' not in name, (name, kwargs ) # use group_parent_id to make nested groups if 'skip_if_exists' in kwargs: del kwargs['skip_if_exists'] gr = RepoGroup.get_by_group_name(group_name=name) if gr: return gr form_data = self._get_repo_group_create_params(group_name=name, **kwargs) gr = RepoGroupModel().create( group_name=form_data['group_name'], group_description=form_data['group_name'], parent=parent_group_id, owner=kwargs.get('cur_user', TEST_USER_ADMIN_LOGIN), ) Session().commit() gr = RepoGroup.get_by_group_name(gr.group_name) return gr
def show_by_name(self, group_name): """ This is a proxy that does a lookup group_name -> id, and shows the group by id view instead """ group_name = group_name.rstrip('/') id_ = RepoGroup.get_by_group_name(group_name) if id_: return self.show(group_name) raise HTTPNotFound
def show_by_name(self, group_name): """ This is a proxy that does a lookup group_name -> id, and shows the group by id view instead """ group_name = group_name.rstrip('/') id_ = RepoGroup.get_by_group_name(group_name) if id_: return self.show(group_name) raise HTTPNotFound
def _destroy_project_tree(test_u1_id): Session.remove() repo_group = RepoGroup.get_by_group_name(group_name='g0') for el in reversed(repo_group.recursive_groups_and_repos()): if isinstance(el, Repository): RepoModel().delete(el) elif isinstance(el, RepoGroup): RepoGroupModel().delete(el, force_delete=True) u = User.get(test_u1_id) Session().delete(u) Session().commit()
def _destroy_project_tree(test_u1_id): Session.remove() repo_group = RepoGroup.get_by_group_name(group_name=u'g0') for el in reversed(repo_group.recursive_groups_and_repos()): if isinstance(el, Repository): RepoModel().delete(el) elif isinstance(el, RepoGroup): RepoGroupModel().delete(el, force_delete=True) u = User.get(test_u1_id) Session().delete(u) Session().commit()
def permissions_setup_func(group_name='g0', perm='group.read', recursive='all'): """ Resets all permissions to perm attribute """ repo_group = RepoGroup.get_by_group_name(group_name=group_name) if not repo_group: raise Exception('Cannot get group %s' % group_name) perms_updates = [[test_u2_gr_id, perm, 'users_group']] RepoGroupModel()._update_permissions(repo_group, perms_updates=perms_updates, recursive=recursive, check_perms=False) Session().commit()
def validate_python(self, value, state): repo_name = value.get('repo_name') repo_name_full = value.get('repo_name_full') group_path = value.get('group_path') group_name = value.get('group_name') if repo_name in [ADMIN_PREFIX, '']: msg = self.message('invalid_repo_name', state, repo=repo_name) raise formencode.Invalid(msg, value, state, error_dict=dict(repo_name=msg)) rename = old_data.get('repo_name') != repo_name_full create = not edit if rename or create: repo = Repository.get_by_repo_name(repo_name_full, case_insensitive=True) repo_group = RepoGroup.get_by_group_name(repo_name_full, case_insensitive=True) if group_path != '': if repo is not None: msg = self.message('repository_in_group_exists', state, repo=repo.repo_name, group=group_name) raise formencode.Invalid( msg, value, state, error_dict=dict(repo_name=msg)) elif repo_group is not None: msg = self.message('same_group_exists', state, repo=repo_name) raise formencode.Invalid(msg, value, state, error_dict=dict(repo_name=msg)) elif repo is not None: msg = self.message('repository_exists', state, repo=repo.repo_name) raise formencode.Invalid(msg, value, state, error_dict=dict(repo_name=msg)) return value
def permissions_setup_func(group_name='g0', perm='group.read', recursive='all', user_id=None): """ Resets all permissions to perm attribute """ if not user_id: user_id = test_u1_id # called by the @with_setup decorator also reset the default user stuff permissions_setup_func(group_name, perm, recursive, user_id=User.get_default_user().user_id) repo_group = RepoGroup.get_by_group_name(group_name=group_name) if not repo_group: raise Exception('Cannot get group %s' % group_name) perms_updates = [[user_id, perm, 'user']] RepoGroupModel()._update_permissions(repo_group, perms_updates=perms_updates, recursive=recursive, check_perms=False) Session().commit()
def validate_python(self, value, state): repo_name = value.get('repo_name') repo_name_full = value.get('repo_name_full') group_path = value.get('group_path') group_name = value.get('group_name') if repo_name in [ADMIN_PREFIX, '']: msg = M(self, 'invalid_repo_name', state, repo=repo_name) raise formencode.Invalid(msg, value, state, error_dict=dict(repo_name=msg)) rename = old_data.get('repo_name') != repo_name_full create = not edit if rename or create: if group_path != '': if Repository.get_by_repo_name(repo_name_full): msg = M(self, 'repository_in_group_exists', state, repo=repo_name, group=group_name) raise formencode.Invalid( msg, value, state, error_dict=dict(repo_name=msg)) elif RepoGroup.get_by_group_name(repo_name_full): msg = M(self, 'same_group_exists', state, repo=repo_name) raise formencode.Invalid(msg, value, state, error_dict=dict(repo_name=msg)) elif Repository.get_by_repo_name(repo_name_full): msg = M(self, 'repository_exists', state, repo=repo_name) raise formencode.Invalid(msg, value, state, error_dict=dict(repo_name=msg)) return value
def map_groups(path): """ Given a full path to a repository, create all nested groups that this repo is inside. This function creates parent-child relationships between groups and creates default perms for all new groups. :param paths: full path to repository """ sa = meta.Session() groups = path.split(Repository.url_sep()) parent = None group = None # last element is repo in nested groups structure groups = groups[:-1] rgm = RepoGroupModel(sa) owner = User.get_first_admin() for lvl, group_name in enumerate(groups): group_name = u'/'.join(groups[:lvl] + [group_name]) group = RepoGroup.get_by_group_name(group_name) desc = '%s group' % group_name # skip folders that are now removed repos if REMOVED_REPO_PAT.match(group_name): break if group is None: log.debug('creating group level: %s group_name: %s', lvl, group_name) group = RepoGroup(group_name, parent) group.group_description = desc group.user = owner sa.add(group) perm_obj = rgm._create_default_perms(group) sa.add(perm_obj) sa.flush() parent = group return group
def map_groups(path): """ Given a full path to a repository, create all nested groups that this repo is inside. This function creates parent-child relationships between groups and creates default perms for all new groups. :param paths: full path to repository """ from kallithea.model.repo_group import RepoGroupModel sa = meta.Session() groups = path.split(db.URL_SEP) parent = None group = None # last element is repo in nested groups structure groups = groups[:-1] rgm = RepoGroupModel() owner = User.get_first_admin() for lvl, group_name in enumerate(groups): group_name = '/'.join(groups[:lvl] + [group_name]) group = RepoGroup.get_by_group_name(group_name) desc = '%s group' % group_name # skip folders that are now removed repos if REMOVED_REPO_PAT.match(group_name): break if group is None: log.debug('creating group level: %s group_name: %s', lvl, group_name) group = RepoGroup(group_name, parent) group.group_description = desc group.owner = owner sa.add(group) rgm._create_default_perms(group) sa.flush() parent = group return group
def validate_python(self, value, state): repo_name = value.get('repo_name') repo_name_full = value.get('repo_name_full') group_path = value.get('group_path') group_name = value.get('group_name') if repo_name in [ADMIN_PREFIX, '']: msg = M(self, 'invalid_repo_name', state, repo=repo_name) raise formencode.Invalid(msg, value, state, error_dict=dict(repo_name=msg) ) rename = old_data.get('repo_name') != repo_name_full create = not edit if rename or create: if group_path != '': if Repository.get_by_repo_name(repo_name_full): msg = M(self, 'repository_in_group_exists', state, repo=repo_name, group=group_name) raise formencode.Invalid(msg, value, state, error_dict=dict(repo_name=msg) ) elif RepoGroup.get_by_group_name(repo_name_full): msg = M(self, 'same_group_exists', state, repo=repo_name) raise formencode.Invalid(msg, value, state, error_dict=dict(repo_name=msg) ) elif Repository.get_by_repo_name(repo_name_full): msg = M(self, 'repository_exists', state, repo=repo_name) raise formencode.Invalid(msg, value, state, error_dict=dict(repo_name=msg) ) return value
def test_rename_single_group(self): sg1 = fixture.create_repo_group(u'initial') new_sg1 = _update_group(sg1.group_id, u'after') self.assertTrue(self.__check_path('after')) self.assertEqual(RepoGroup.get_by_group_name(u'initial'), None)
def expected_count(group_name, objects=False): repo_group = RepoGroup.get_by_group_name(group_name=group_name) objs = repo_group.recursive_groups_and_repos() if objects: return objs return len(objs)
def expected_count(group_name, objects=False): repo_group = RepoGroup.get_by_group_name(group_name=group_name) objs = repo_group.recursive_groups_and_repos() if objects: return objs return len(objs)
def test_rename_single_group(self): sg1 = fixture.create_repo_group(u'initial') new_sg1 = _update_repo_group(sg1.group_id, u'after') assert self.__check_path('after') assert RepoGroup.get_by_group_name(u'initial') == None
def test_rename_single_group(self): sg1 = fixture.create_repo_group(u'initial') new_sg1 = _update_repo_group(sg1.group_id, u'after') assert self.__check_path('after') assert RepoGroup.get_by_group_name(u'initial') == None
def test_rename_single_group(self): sg1 = fixture.create_repo_group('initial') new_sg1 = _update_group(sg1.group_id, 'after') self.assertTrue(self.__check_path('after')) self.assertEqual(RepoGroup.get_by_group_name('initial'), None)