# HG changeset patch # User Marcin Kuzminski # Date 2013-03-05 21:37:58 # Node ID 0ad025ee005edf2ac7c3fa22ce5e9b891c517057 # Parent 08e8115585bd3ce9a0eb4e3ff6bb05c19a83a8b2 better detection of deleting groups with subgroups inside. Added less strict checks on delete group routing so we can delete zombie groups (those that are not in filesystem but in DB) diff --git a/rhodecode/config/routing.py b/rhodecode/config/routing.py --- a/rhodecode/config/routing.py +++ b/rhodecode/config/routing.py @@ -56,6 +56,18 @@ def make_map(config): repos_group_name = match_dict.get('group_name') return is_valid_repos_group(repos_group_name, config['base_path']) + def check_group_skip_path(environ, match_dict): + """ + check for valid repository group for proper 404 handling, but skips + verification of existing path + + :param environ: + :param match_dict: + """ + repos_group_name = match_dict.get('group_name') + return is_valid_repos_group(repos_group_name, config['base_path'], + skip_path_check=True) + def check_int(environ, match_dict): return match_dict.get('id').isdigit() @@ -171,9 +183,10 @@ def make_map(config): function=check_group)) m.connect("delete_repos_group", "/repos_groups/{group_name:.*?}", action="delete", conditions=dict(method=["DELETE"], - function=check_group)) + function=check_group_skip_path)) m.connect("edit_repos_group", "/repos_groups/{group_name:.*?}/edit", - action="edit", conditions=dict(method=["GET"],)) + action="edit", conditions=dict(method=["GET"], + function=check_group)) m.connect("formatted_edit_repos_group", "/repos_groups/{group_name:.*?}.{format}/edit", action="edit", conditions=dict(method=["GET"], diff --git a/rhodecode/controllers/admin/repos_groups.py b/rhodecode/controllers/admin/repos_groups.py --- a/rhodecode/controllers/admin/repos_groups.py +++ b/rhodecode/controllers/admin/repos_groups.py @@ -251,31 +251,25 @@ class ReposGroupsController(BaseControll repos = gr.repositories.all() if repos: h.flash(_('This group contains %s repositores and cannot be ' - 'deleted') % len(repos), - category='error') + 'deleted') % len(repos), category='warning') + return redirect(url('repos_groups')) + + children = gr.children.all() + if children: + h.flash(_('This group contains %s subgroups and cannot be deleted' + % (len(children))), category='warning') return redirect(url('repos_groups')) try: ReposGroupModel().delete(group_name) Session().commit() - h.flash(_('removed repos group %s') % gr.group_name, + h.flash(_('removed repos group %s') % group_name, category='success') #TODO: in future action_logger(, '', '', '', self.sa) - except IntegrityError, e: - if str(e.message).find('groups_group_parent_id_fkey') != -1: - log.error(traceback.format_exc()) - h.flash(_('Cannot delete this group it still contains ' - 'subgroups'), - category='warning') - else: - log.error(traceback.format_exc()) - h.flash(_('error occurred during deletion of repos ' - 'group %s') % gr.group_name, category='error') - except Exception: log.error(traceback.format_exc()) h.flash(_('error occurred during deletion of repos ' - 'group %s') % gr.group_name, category='error') + 'group %s') % group_name, category='error') return redirect(url('repos_groups')) diff --git a/rhodecode/lib/utils.py b/rhodecode/lib/utils.py --- a/rhodecode/lib/utils.py +++ b/rhodecode/lib/utils.py @@ -240,7 +240,7 @@ def is_valid_repo(repo_name, base_path, return False -def is_valid_repos_group(repos_group_name, base_path): +def is_valid_repos_group(repos_group_name, base_path, skip_path_check=False): """ Returns True if given path is a repos group False otherwise @@ -263,7 +263,7 @@ def is_valid_repos_group(repos_group_nam pass # check if it's a valid path - if os.path.isdir(full_path): + if skip_path_check or os.path.isdir(full_path): return True return False @@ -495,7 +495,6 @@ def repo2db_mapper(initial_repo_list, re #don't hold further removals on error log.error(traceback.format_exc()) sa.rollback() - return added, removed