Commits

Marcin Kuzminski committed 87ca175

fixed #47 adding a new repo that have a group chosen had wrong paths.

Comments (0)

Files changed (4)

rhodecode/controllers/admin/repos.py

 from rhodecode.model.forms import RepoForm
 from rhodecode.model.scm import ScmModel
 from rhodecode.model.repo import RepoModel
+from sqlalchemy.exc import IntegrityError
 
 log = logging.getLogger(__name__)
 
                     category='success')
 
             if request.POST.get('user_created'):
+                #created by regular non admin user
                 action_logger(self.rhodecode_user, 'user_created_repo',
-                              form_result['repo_name'], '', self.sa)
+                              form_result['repo_name_full'], '', self.sa)
             else:
                 action_logger(self.rhodecode_user, 'admin_created_repo',
-                              form_result['repo_name'], '', self.sa)
+                              form_result['repo_name_full'], '', self.sa)
 
         except formencode.Invalid, errors:
 
             invalidate_cache('get_repo_cached_%s' % repo_name)
             h.flash(_('deleted repository %s') % repo_name, category='success')
 
+        except IntegrityError, e:
+            if e.message.find('repositories_fork_id_fkey'):
+                log.error(traceback.format_exc())
+                h.flash(_('Cannot delete %s it still contains attached '
+                          'forks') % repo_name,
+                        category='warning')
+            else:
+                log.error(traceback.format_exc())
+                h.flash(_('An error occurred during '
+                          'deletion of %s') % repo_name,
+                        category='error')
+
         except Exception, e:
             log.error(traceback.format_exc())
             h.flash(_('An error occurred during deletion of %s') % repo_name,

rhodecode/lib/utils.py

             added.append(name)
             form_data = {
                          'repo_name': name,
+                         'repo_name_full': name,
                          'repo_type': repo.alias,
                          'description': repo.description \
                             if repo.description != 'unknown' else \

rhodecode/model/forms.py

 
     def to_python(self, value, state):
         try:
-            self.user_db = User.query()\
-                .filter(User.active == True)\
+            User.query().filter(User.active == True)\
                 .filter(User.username == value).one()
         except Exception:
             raise formencode.Invalid(_('This username is not valid'),
                 gr = Group.get(value.get('repo_group'))
                 group_path = gr.full_path
                 # value needs to be aware of group name in order to check
-                # db key
+                # db key This is an actuall just the name to store in the
+                # database
                 repo_name_full = group_path + Group.url_sep() + repo_name
             else:
                 group_path = ''

rhodecode/model/repo.py

                 #force str since hg doesn't go with unicode
                 repo_name = str(form_data['fork_name'])
                 org_name = str(form_data['repo_name'])
+                org_full_name = str(form_data['repo_name_full'])
 
             else:
                 org_name = repo_name = str(form_data['repo_name'])
+                repo_name_full = form_data['repo_name_full']
+
             new_repo = Repository()
             new_repo.enable_statistics = False
             for k, v in form_data.items():
                 if k == 'repo_name':
-                    v = repo_name
+                    v = repo_name_full
                 if k == 'repo_group':
                     k = 'group_id'
 
 
             if fork:
                 parent_repo = self.sa.query(Repository)\
-                        .filter(Repository.repo_name == org_name).scalar()
+                        .filter(Repository.repo_name == org_full_name).scalar()
                 new_repo.fork = parent_repo
 
             new_repo.user_id = cur_user.user_id
 
     def __create_repo(self, repo_name, alias, new_parent_id, clone_uri=False):
         """
-        makes repository on filesystem it's group aware
+        makes repository on filesystem. It's group aware means it'll create
+        a repository within a group, and alter the paths accordingly of
+        group location
 
         :param repo_name:
         :param alias: