diff --git a/kallithea/controllers/admin/repo_groups.py b/kallithea/controllers/admin/repo_groups.py --- a/kallithea/controllers/admin/repo_groups.py +++ b/kallithea/controllers/admin/repo_groups.py @@ -245,6 +245,7 @@ class RepoGroupsController(base.BaseCont @HasRepoGroupPermissionLevelDecorator('admin') def delete(self, group_name): gr = c.repo_group = db.RepoGroup.guess_instance(group_name) + parent_group = gr.parent_group repos = gr.repositories.all() if repos: webutils.flash(_('This group contains %s repositories and cannot be ' @@ -268,8 +269,8 @@ class RepoGroupsController(base.BaseCont webutils.flash(_('Error occurred during deletion of repository group %s') % group_name, category='error') - if gr.parent_group: - raise HTTPFound(location=url('repos_group_home', group_name=gr.parent_group.group_name)) + if parent_group: + raise HTTPFound(location=url('repos_group_home', group_name=parent_group.group_name)) raise HTTPFound(location=url('repos_groups')) def show_by_name(self, group_name): diff --git a/kallithea/tests/functional/test_admin_repo_groups.py b/kallithea/tests/functional/test_admin_repo_groups.py --- a/kallithea/tests/functional/test_admin_repo_groups.py +++ b/kallithea/tests/functional/test_admin_repo_groups.py @@ -1,4 +1,4 @@ -from kallithea.model import meta +from kallithea.model import db, meta from kallithea.model.repo_group import RepoGroupModel from kallithea.tests import base from kallithea.tests.fixture import Fixture @@ -97,3 +97,54 @@ class TestRepoGroupsController(base.Test RepoGroupModel().delete(group_name) meta.Session().commit() + + def test_subgroup_deletion(self): + self.log_user() + parent = None + parent_name = 'parent' + sub = None + sub_name = 'sub' + sub_path = 'parent/sub' + + try: + # create parent group + assert db.RepoGroup.guess_instance(parent_name) is None + response = self.app.post( + base.url('repos_groups'), + fixture._get_repo_group_create_params( + group_name=parent_name, + _session_csrf_secret_token=self.session_csrf_secret_token() + ) + ) + parent = db.RepoGroup.guess_instance(parent_name) + assert parent is not None + + # create sub group + assert db.RepoGroup.guess_instance(sub_path) is None + response = self.app.post( + base.url('repos_groups'), + fixture._get_repo_group_create_params( + group_name=sub_name, + parent_group_id=parent.group_id, + _session_csrf_secret_token=self.session_csrf_secret_token() + ) + ) + sub = db.RepoGroup.guess_instance(sub_path) + assert sub is not None + + # delete sub group + response = self.app.post( + base.url('delete_repo_group', group_name=sub_path), + params={ + '_session_csrf_secret_token': self.session_csrf_secret_token() + }, + ) + sub = db.RepoGroup.guess_instance(sub_path) + assert sub is None + + finally: + if sub: + RepoGroupModel().delete(sub) + if parent: + RepoGroupModel().delete(parent) + meta.Session().commit()