Commits

Marcin Kuzminski committed bd604cf

fixes #260 Put repo in group, then move group to another group -> repo becomes unavailable

Comments (0)

Files changed (7)

rhodecode/controllers/admin/repos.py

                          repo_groups=c.repo_groups_choices)()
         try:
             form_result = _form.to_python(dict(request.POST))
-            repo_model.update(repo_name, form_result)
+            repo = repo_model.update(repo_name, form_result)
             invalidate_cache('get_repo_cached_%s' % repo_name)
             h.flash(_('Repository %s updated successfully' % repo_name),
                     category='success')
-            changed_name = form_result['repo_name_full']
+            changed_name = repo.repo_name
             action_logger(self.rhodecode_user, 'admin_updated_repo',
                               changed_name, '', self.sa)
 

rhodecode/model/db.py

     @classmethod
     def get_by_username(cls, username, case_insensitive=False):
         if case_insensitive:
-            return Session.query(cls).filter(cls.username.like(username)).scalar()
+            return Session.query(cls).filter(cls.username.ilike(username)).scalar()
         else:
             return Session.query(cls).filter(cls.username == username).scalar()
 
         p += self.repo_name.split('/')
         return os.path.join(*p)
 
+    def get_new_name(self, repo_name):
+        """
+        returns new full repository name based on assigned group and new new
+        
+        :param group_name:
+        """
+        path_prefix = self.group.full_path_splitted if self.group else []
+        return '/'.join(path_prefix + [repo_name])
+
     @property
     def _ui(self):
         """

rhodecode/model/forms.py

         def validate_python(self, value, state):
             #TODO WRITE VALIDATIONS
             group_name = value.get('group_name')
-            group_parent_id = int(value.get('group_parent_id') or - 1)
+            group_parent_id = int(value.get('group_parent_id') or -1)
 
             # slugify repo group just in case :)
             slug = repo_name_slug(group_name)

rhodecode/model/repo.py

         try:
             cur_repo = self.get_by_repo_name(repo_name, cache=False)
 
-            #update permissions
+            # update permissions
             for member, perm, member_type in form_data['perms_updates']:
                 if member_type == 'user':
                     r2p = self.sa.query(RepoToPerm)\
                                                 perm).scalar()
                     self.sa.add(g2p)
 
-            #set new permissions
+            # set new permissions
             for member, perm, member_type in form_data['perms_new']:
                 if member_type == 'user':
                     r2p = RepoToPerm()
                                                 .scalar()
                     self.sa.add(g2p)
 
-            #update current repo
+            # update current repo
             for k, v in form_data.items():
                 if k == 'user':
                     cur_repo.user = User.get_by_username(v)
                 elif k == 'repo_name':
-                    cur_repo.repo_name = form_data['repo_name_full']
+                    pass
                 elif k == 'repo_group':
                     cur_repo.group_id = v
 
                 else:
                     setattr(cur_repo, k, v)
 
+            new_name = cur_repo.get_new_name(form_data['repo_name'])
+            cur_repo.repo_name = new_name
+
             self.sa.add(cur_repo)
 
-            if repo_name != form_data['repo_name_full']:
+            if repo_name != new_name:
                 # rename repository
-                self.__rename_repo(old=repo_name,
-                                   new=form_data['repo_name_full'])
+                self.__rename_repo(old=repo_name, new=new_name)
 
             self.sa.commit()
+            return cur_repo
         except:
             log.error(traceback.format_exc())
             self.sa.rollback()
             from rhodecode.model.scm import ScmModel
             ScmModel(self.sa).toggle_following_repo(new_repo.repo_id,
                                              cur_user.user_id)
-
+            return new_repo
         except:
             log.error(traceback.format_exc())
             self.sa.rollback()

rhodecode/model/repos_group.py

 
             self.__rename_group(old_path, new_path)
 
+            # we need to get all repositories from this new group and 
+            # rename them accordingly to new group path
+            for r in repos_group.repositories:
+                r.repo_name = r.get_new_name(r.just_name)
+                self.sa.add(r)
+
             self.sa.commit()
             return repos_group
         except:

rhodecode/tests/functional/test_login.py

                                              'lastname':'test'})
 
         self.assertEqual(response.status , '200 OK')
-        assert 'An email address must contain a single @' in response.body
-        assert 'This username already exists' in response.body
+        self.assertTrue('An email address must contain a single @' in response.body)
+        self.assertTrue('This username already exists' in response.body)
 
 
 
                                              'lastname':'test'})
 
         self.assertEqual(response.status , '200 OK')
-        assert 'Invalid characters in password' in response.body
+        self.assertTrue('Invalid characters in password' in response.body)
 
 
     def test_register_password_mismatch(self):

rhodecode/tests/test_models.py

 from rhodecode.tests import *
 
 from rhodecode.model.repos_group import ReposGroupModel
-from rhodecode.model.db import Group
+from rhodecode.model.repo import RepoModel
+from rhodecode.model.db import Group, User
 from sqlalchemy.exc import IntegrityError
 
 class TestReposGroups(unittest.TestCase):
 
         self.assertEqual(Group.get_by_group_name('hello'), new_sg1)
 
+
+
+    def test_subgrouping_with_repo(self):
+
+        g1 = self.__make_group('g1')
+        g2 = self.__make_group('g2')
+
+        # create new repo
+        form_data = dict(repo_name='john',
+                         repo_name_full='john',
+                         fork_name=None,
+                         description=None,
+                         repo_group=None,
+                         private=False,
+                         repo_type='hg',
+                         clone_uri=None)
+        cur_user = User.get_by_username(TEST_USER_ADMIN_LOGIN)
+        r = RepoModel().create(form_data, cur_user)
+
+        self.assertEqual(r.repo_name, 'john')
+
+        # put repo into group
+        form_data = form_data
+        form_data['repo_group'] = g1.group_id
+        form_data['perms_new'] = []
+        form_data['perms_updates'] = []
+        RepoModel().update(r.repo_name, form_data)
+        self.assertEqual(r.repo_name, 'g1/john')
+
+
+        self.__update_group(g1.group_id, 'g1', parent_id=g2.group_id)
+        self.assertTrue(self.__check_path('g2', 'g1'))
+
+        # test repo
+        self.assertEqual(r.repo_name, os.path.join('g2', 'g1', r.just_name))
+
+