changeset 3458:0ad025ee005e beta

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)
author Marcin Kuzminski <marcin@python-works.com>
date Tue, 05 Mar 2013 22:37:58 +0100
parents 08e8115585bd
children 94f251fda314
files rhodecode/config/routing.py rhodecode/controllers/admin/repos_groups.py rhodecode/lib/utils.py
diffstat 3 files changed, 26 insertions(+), 20 deletions(-) [+]
line wrap: on
line diff
--- a/rhodecode/config/routing.py	Tue Mar 05 20:03:33 2013 +0100
+++ b/rhodecode/config/routing.py	Tue Mar 05 22:37:58 2013 +0100
@@ -56,6 +56,18 @@
         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 @@
                                                    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"],
--- a/rhodecode/controllers/admin/repos_groups.py	Tue Mar 05 20:03:33 2013 +0100
+++ b/rhodecode/controllers/admin/repos_groups.py	Tue Mar 05 22:37:58 2013 +0100
@@ -251,31 +251,25 @@
         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'))
 
--- a/rhodecode/lib/utils.py	Tue Mar 05 20:03:33 2013 +0100
+++ b/rhodecode/lib/utils.py	Tue Mar 05 22:37:58 2013 +0100
@@ -240,7 +240,7 @@
         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 @@
         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 @@
                     #don't hold further removals on error
                     log.error(traceback.format_exc())
                     sa.rollback()
-
     return added, removed