Changeset - 0ad025ee005e
[Not reviewed]
beta
0 3 0
Marcin Kuzminski - 13 years ago 2013-03-05 22:37:58
marcin@python-works.com
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)
3 files changed with 26 insertions and 20 deletions:
0 comments (0 inline, 0 general)
rhodecode/config/routing.py
Show inline comments
 
@@ -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"],
rhodecode/controllers/admin/repos_groups.py
Show inline comments
 
@@ -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'))
 

	
rhodecode/lib/utils.py
Show inline comments
 
@@ -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
 

	
 

	
0 comments (0 inline, 0 general)