Show More
@@ -234,11 +234,11 b' class ReposController(BaseController):' | |||||
234 | repo_groups=c.repo_groups_choices)() |
|
234 | repo_groups=c.repo_groups_choices)() | |
235 | try: |
|
235 | try: | |
236 | form_result = _form.to_python(dict(request.POST)) |
|
236 | form_result = _form.to_python(dict(request.POST)) | |
237 | repo_model.update(repo_name, form_result) |
|
237 | repo = repo_model.update(repo_name, form_result) | |
238 | invalidate_cache('get_repo_cached_%s' % repo_name) |
|
238 | invalidate_cache('get_repo_cached_%s' % repo_name) | |
239 | h.flash(_('Repository %s updated successfully' % repo_name), |
|
239 | h.flash(_('Repository %s updated successfully' % repo_name), | |
240 | category='success') |
|
240 | category='success') | |
241 |
changed_name = |
|
241 | changed_name = repo.repo_name | |
242 | action_logger(self.rhodecode_user, 'admin_updated_repo', |
|
242 | action_logger(self.rhodecode_user, 'admin_updated_repo', | |
243 | changed_name, '', self.sa) |
|
243 | changed_name, '', self.sa) | |
244 |
|
244 |
@@ -284,7 +284,7 b' class User(Base, BaseModel):' | |||||
284 | @classmethod |
|
284 | @classmethod | |
285 | def get_by_username(cls, username, case_insensitive=False): |
|
285 | def get_by_username(cls, username, case_insensitive=False): | |
286 | if case_insensitive: |
|
286 | if case_insensitive: | |
287 | return Session.query(cls).filter(cls.username.like(username)).scalar() |
|
287 | return Session.query(cls).filter(cls.username.ilike(username)).scalar() | |
288 | else: |
|
288 | else: | |
289 | return Session.query(cls).filter(cls.username == username).scalar() |
|
289 | return Session.query(cls).filter(cls.username == username).scalar() | |
290 |
|
290 | |||
@@ -555,6 +555,15 b' class Repository(Base, BaseModel):' | |||||
555 | p += self.repo_name.split('/') |
|
555 | p += self.repo_name.split('/') | |
556 | return os.path.join(*p) |
|
556 | return os.path.join(*p) | |
557 |
|
557 | |||
|
558 | def get_new_name(self, repo_name): | |||
|
559 | """ | |||
|
560 | returns new full repository name based on assigned group and new new | |||
|
561 | ||||
|
562 | :param group_name: | |||
|
563 | """ | |||
|
564 | path_prefix = self.group.full_path_splitted if self.group else [] | |||
|
565 | return '/'.join(path_prefix + [repo_name]) | |||
|
566 | ||||
558 | @property |
|
567 | @property | |
559 | def _ui(self): |
|
568 | def _ui(self): | |
560 | """ |
|
569 | """ |
@@ -122,7 +122,7 b' def ValidReposGroup(edit, old_data):' | |||||
122 | def validate_python(self, value, state): |
|
122 | def validate_python(self, value, state): | |
123 | #TODO WRITE VALIDATIONS |
|
123 | #TODO WRITE VALIDATIONS | |
124 | group_name = value.get('group_name') |
|
124 | group_name = value.get('group_name') | |
125 |
group_parent_id = int(value.get('group_parent_id') or - |
|
125 | group_parent_id = int(value.get('group_parent_id') or -1) | |
126 |
|
126 | |||
127 | # slugify repo group just in case :) |
|
127 | # slugify repo group just in case :) | |
128 | slug = repo_name_slug(group_name) |
|
128 | slug = repo_name_slug(group_name) |
@@ -98,7 +98,7 b' class RepoModel(BaseModel):' | |||||
98 | try: |
|
98 | try: | |
99 | cur_repo = self.get_by_repo_name(repo_name, cache=False) |
|
99 | cur_repo = self.get_by_repo_name(repo_name, cache=False) | |
100 |
|
100 | |||
101 | #update permissions |
|
101 | # update permissions | |
102 | for member, perm, member_type in form_data['perms_updates']: |
|
102 | for member, perm, member_type in form_data['perms_updates']: | |
103 | if member_type == 'user': |
|
103 | if member_type == 'user': | |
104 | r2p = self.sa.query(RepoToPerm)\ |
|
104 | r2p = self.sa.query(RepoToPerm)\ | |
@@ -122,7 +122,7 b' class RepoModel(BaseModel):' | |||||
122 | perm).scalar() |
|
122 | perm).scalar() | |
123 | self.sa.add(g2p) |
|
123 | self.sa.add(g2p) | |
124 |
|
124 | |||
125 | #set new permissions |
|
125 | # set new permissions | |
126 | for member, perm, member_type in form_data['perms_new']: |
|
126 | for member, perm, member_type in form_data['perms_new']: | |
127 | if member_type == 'user': |
|
127 | if member_type == 'user': | |
128 | r2p = RepoToPerm() |
|
128 | r2p = RepoToPerm() | |
@@ -144,26 +144,29 b' class RepoModel(BaseModel):' | |||||
144 | .scalar() |
|
144 | .scalar() | |
145 | self.sa.add(g2p) |
|
145 | self.sa.add(g2p) | |
146 |
|
146 | |||
147 | #update current repo |
|
147 | # update current repo | |
148 | for k, v in form_data.items(): |
|
148 | for k, v in form_data.items(): | |
149 | if k == 'user': |
|
149 | if k == 'user': | |
150 | cur_repo.user = User.get_by_username(v) |
|
150 | cur_repo.user = User.get_by_username(v) | |
151 | elif k == 'repo_name': |
|
151 | elif k == 'repo_name': | |
152 | cur_repo.repo_name = form_data['repo_name_full'] |
|
152 | pass | |
153 | elif k == 'repo_group': |
|
153 | elif k == 'repo_group': | |
154 | cur_repo.group_id = v |
|
154 | cur_repo.group_id = v | |
155 |
|
155 | |||
156 | else: |
|
156 | else: | |
157 | setattr(cur_repo, k, v) |
|
157 | setattr(cur_repo, k, v) | |
158 |
|
158 | |||
|
159 | new_name = cur_repo.get_new_name(form_data['repo_name']) | |||
|
160 | cur_repo.repo_name = new_name | |||
|
161 | ||||
159 | self.sa.add(cur_repo) |
|
162 | self.sa.add(cur_repo) | |
160 |
|
163 | |||
161 |
if repo_name != |
|
164 | if repo_name != new_name: | |
162 | # rename repository |
|
165 | # rename repository | |
163 | self.__rename_repo(old=repo_name, |
|
166 | self.__rename_repo(old=repo_name, new=new_name) | |
164 | new=form_data['repo_name_full']) |
|
|||
165 |
|
167 | |||
166 | self.sa.commit() |
|
168 | self.sa.commit() | |
|
169 | return cur_repo | |||
167 | except: |
|
170 | except: | |
168 | log.error(traceback.format_exc()) |
|
171 | log.error(traceback.format_exc()) | |
169 | self.sa.rollback() |
|
172 | self.sa.rollback() | |
@@ -235,7 +238,7 b' class RepoModel(BaseModel):' | |||||
235 | from rhodecode.model.scm import ScmModel |
|
238 | from rhodecode.model.scm import ScmModel | |
236 | ScmModel(self.sa).toggle_following_repo(new_repo.repo_id, |
|
239 | ScmModel(self.sa).toggle_following_repo(new_repo.repo_id, | |
237 | cur_user.user_id) |
|
240 | cur_user.user_id) | |
238 |
|
241 | return new_repo | ||
239 | except: |
|
242 | except: | |
240 | log.error(traceback.format_exc()) |
|
243 | log.error(traceback.format_exc()) | |
241 | self.sa.rollback() |
|
244 | self.sa.rollback() |
@@ -137,6 +137,12 b' class ReposGroupModel(BaseModel):' | |||||
137 |
|
137 | |||
138 | self.__rename_group(old_path, new_path) |
|
138 | self.__rename_group(old_path, new_path) | |
139 |
|
139 | |||
|
140 | # we need to get all repositories from this new group and | |||
|
141 | # rename them accordingly to new group path | |||
|
142 | for r in repos_group.repositories: | |||
|
143 | r.repo_name = r.get_new_name(r.just_name) | |||
|
144 | self.sa.add(r) | |||
|
145 | ||||
140 | self.sa.commit() |
|
146 | self.sa.commit() | |
141 | return repos_group |
|
147 | return repos_group | |
142 | except: |
|
148 | except: |
@@ -145,8 +145,8 b' class TestLoginController(TestController' | |||||
145 | 'lastname':'test'}) |
|
145 | 'lastname':'test'}) | |
146 |
|
146 | |||
147 | self.assertEqual(response.status , '200 OK') |
|
147 | self.assertEqual(response.status , '200 OK') | |
148 |
assert |
|
148 | self.assertTrue('An email address must contain a single @' in response.body) | |
149 |
assert |
|
149 | self.assertTrue('This username already exists' in response.body) | |
150 |
|
150 | |||
151 |
|
151 | |||
152 |
|
152 | |||
@@ -160,7 +160,7 b' class TestLoginController(TestController' | |||||
160 | 'lastname':'test'}) |
|
160 | 'lastname':'test'}) | |
161 |
|
161 | |||
162 | self.assertEqual(response.status , '200 OK') |
|
162 | self.assertEqual(response.status , '200 OK') | |
163 |
assert |
|
163 | self.assertTrue('Invalid characters in password' in response.body) | |
164 |
|
164 | |||
165 |
|
165 | |||
166 | def test_register_password_mismatch(self): |
|
166 | def test_register_password_mismatch(self): |
@@ -3,7 +3,8 b' import unittest' | |||||
3 | from rhodecode.tests import * |
|
3 | from rhodecode.tests import * | |
4 |
|
4 | |||
5 | from rhodecode.model.repos_group import ReposGroupModel |
|
5 | from rhodecode.model.repos_group import ReposGroupModel | |
6 |
from rhodecode.model. |
|
6 | from rhodecode.model.repo import RepoModel | |
|
7 | from rhodecode.model.db import Group, User | |||
7 | from sqlalchemy.exc import IntegrityError |
|
8 | from sqlalchemy.exc import IntegrityError | |
8 |
|
9 | |||
9 | class TestReposGroups(unittest.TestCase): |
|
10 | class TestReposGroups(unittest.TestCase): | |
@@ -113,3 +114,40 b' class TestReposGroups(unittest.TestCase)' | |||||
113 |
|
114 | |||
114 | self.assertEqual(Group.get_by_group_name('hello'), new_sg1) |
|
115 | self.assertEqual(Group.get_by_group_name('hello'), new_sg1) | |
115 |
|
116 | |||
|
117 | ||||
|
118 | ||||
|
119 | def test_subgrouping_with_repo(self): | |||
|
120 | ||||
|
121 | g1 = self.__make_group('g1') | |||
|
122 | g2 = self.__make_group('g2') | |||
|
123 | ||||
|
124 | # create new repo | |||
|
125 | form_data = dict(repo_name='john', | |||
|
126 | repo_name_full='john', | |||
|
127 | fork_name=None, | |||
|
128 | description=None, | |||
|
129 | repo_group=None, | |||
|
130 | private=False, | |||
|
131 | repo_type='hg', | |||
|
132 | clone_uri=None) | |||
|
133 | cur_user = User.get_by_username(TEST_USER_ADMIN_LOGIN) | |||
|
134 | r = RepoModel().create(form_data, cur_user) | |||
|
135 | ||||
|
136 | self.assertEqual(r.repo_name, 'john') | |||
|
137 | ||||
|
138 | # put repo into group | |||
|
139 | form_data = form_data | |||
|
140 | form_data['repo_group'] = g1.group_id | |||
|
141 | form_data['perms_new'] = [] | |||
|
142 | form_data['perms_updates'] = [] | |||
|
143 | RepoModel().update(r.repo_name, form_data) | |||
|
144 | self.assertEqual(r.repo_name, 'g1/john') | |||
|
145 | ||||
|
146 | ||||
|
147 | self.__update_group(g1.group_id, 'g1', parent_id=g2.group_id) | |||
|
148 | self.assertTrue(self.__check_path('g2', 'g1')) | |||
|
149 | ||||
|
150 | # test repo | |||
|
151 | self.assertEqual(r.repo_name, os.path.join('g2', 'g1', r.just_name)) | |||
|
152 | ||||
|
153 |
General Comments 0
You need to be logged in to leave comments.
Login now