changeset 1543:ada6926c374f beta

Added friendly message about removing a group that still contains subgroups. Fixed option to remove a group that is not in filesystem (ex. someone deleted it intentionally on filesystem) in this case RhodeCode will simply just throw an error message saying this group cannot be deleted.
author Marcin Kuzminski <marcin@python-works.com>
date Tue, 11 Oct 2011 08:02:51 +0200
parents 70e646b2806a
children f82cdb15eee3
files rhodecode/controllers/admin/repos_groups.py rhodecode/model/repos_group.py
diffstat 2 files changed, 19 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/rhodecode/controllers/admin/repos_groups.py	Tue Oct 11 02:14:42 2011 +0200
+++ b/rhodecode/controllers/admin/repos_groups.py	Tue Oct 11 08:02:51 2011 +0200
@@ -9,9 +9,10 @@
 from pylons.controllers.util import abort, redirect
 from pylons.i18n.translation import _
 
+from sqlalchemy.exc import IntegrityError
+
 from rhodecode.lib import helpers as h
-from rhodecode.lib.auth import LoginRequired, HasPermissionAllDecorator, \
-    HasPermissionAnyDecorator
+from rhodecode.lib.auth import LoginRequired, HasPermissionAnyDecorator
 from rhodecode.lib.base import BaseController, render
 from rhodecode.model.db import Group
 from rhodecode.model.repos_group import ReposGroupModel
@@ -167,10 +168,21 @@
             repos_group_model.delete(id)
             h.flash(_('removed repos group %s' % gr.group_name), category='success')
             #TODO: in future action_logger(, '', '', '', self.sa)
+        except IntegrityError, e:
+            if e.message.find('groups_group_parent_id_fkey'):
+                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')
+            h.flash(_('error occurred during deletion of repos '
+                      'group %s' % gr.group_name), category='error')
 
         return redirect(url('repos_groups'))
 
--- a/rhodecode/model/repos_group.py	Tue Oct 11 02:14:42 2011 +0200
+++ b/rhodecode/model/repos_group.py	Tue Oct 11 08:02:51 2011 +0200
@@ -100,7 +100,9 @@
         paths = os.sep.join(paths)
 
         rm_path = os.path.join(self.repos_path, paths)
-        os.rmdir(rm_path)
+        if os.path.isdir(rm_path):
+            # delete only if that path really exists
+            os.rmdir(rm_path)
 
     def create(self, form_data):
         try: