Show More
@@ -234,7 +234,7 b' class ReposController(BaseController):' | |||
|
234 | 234 | invalidate_cache('get_repo_cached_%s' % repo_name) |
|
235 | 235 | h.flash(_('Repository %s updated successfully' % repo_name), |
|
236 | 236 | category='success') |
|
237 | changed_name = form_result['repo_name'] | |
|
237 | changed_name = form_result['repo_name_full'] | |
|
238 | 238 | action_logger(self.rhodecode_user, 'admin_updated_repo', |
|
239 | 239 | changed_name, '', self.sa) |
|
240 | 240 |
@@ -327,6 +327,12 b' class Group(Base):' | |||
|
327 | 327 | groups.insert(0, gr) |
|
328 | 328 | return groups |
|
329 | 329 | |
|
330 | ||
|
331 | @property | |
|
332 | def full_path(self): | |
|
333 | return '/'.join([g.group_name for g in self.parents] + | |
|
334 | [self.group_name]) | |
|
335 | ||
|
330 | 336 | @property |
|
331 | 337 | def repositories(self): |
|
332 | 338 | return Session.query(Repository).filter(Repository.group == self).all() |
@@ -38,7 +38,7 b' from rhodecode.lib.exceptions import Lda' | |||
|
38 | 38 | from rhodecode.model import meta |
|
39 | 39 | from rhodecode.model.user import UserModel |
|
40 | 40 | from rhodecode.model.repo import RepoModel |
|
41 | from rhodecode.model.db import User, UsersGroup | |
|
41 | from rhodecode.model.db import User, UsersGroup, Group | |
|
42 | 42 | from rhodecode import BACKENDS |
|
43 | 43 | |
|
44 | 44 | log = logging.getLogger(__name__) |
@@ -204,25 +204,52 b' class ValidRepoUser(formencode.validator' | |||
|
204 | 204 | finally: |
|
205 | 205 | meta.Session.remove() |
|
206 | 206 | |
|
207 | return self.user_db.user_id | |
|
207 | return value | |
|
208 | 208 | |
|
209 | 209 | def ValidRepoName(edit, old_data): |
|
210 | 210 | class _ValidRepoName(formencode.validators.FancyValidator): |
|
211 | def to_python(self, value, state): | |
|
211 | 212 | |
|
212 | def to_python(self, value, state): | |
|
213 | slug = repo_name_slug(value) | |
|
214 | if slug in ['_admin']: | |
|
215 | raise formencode.Invalid(_('This repository name is disallowed'), | |
|
216 | value, state) | |
|
217 | if old_data.get('repo_name') != value or not edit: | |
|
218 | if RepoModel().get_by_repo_name(slug, cache=False): | |
|
219 | raise formencode.Invalid(_('This repository already exists') , | |
|
220 | value, state) | |
|
221 | return slug | |
|
213 | repo_name = value.get('repo_name') | |
|
214 | ||
|
215 | slug = repo_name_slug(repo_name) | |
|
216 | if slug in ['_admin', '']: | |
|
217 | e_dict = {'repo_name': _('This repository name is disallowed')} | |
|
218 | raise formencode.Invalid('', value, state, error_dict=e_dict) | |
|
219 | ||
|
220 | gr = Group.get(value.get('repo_group')) | |
|
221 | ||
|
222 | # value needs to be aware of group name | |
|
223 | repo_name_full = gr.full_path + '/' + repo_name | |
|
224 | value['repo_name_full'] = repo_name_full | |
|
225 | if old_data.get('repo_name') != repo_name_full or not edit: | |
|
226 | ||
|
227 | if gr.full_path != '': | |
|
228 | if RepoModel().get_by_repo_name(repo_name_full,): | |
|
229 | e_dict = {'repo_name':_('This repository already ' | |
|
230 | 'exists in group "%s"') % | |
|
231 | gr.group_name} | |
|
232 | raise formencode.Invalid('', value, state, | |
|
233 | error_dict=e_dict) | |
|
234 | ||
|
235 | else: | |
|
236 | if RepoModel().get_by_repo_name(repo_name_full): | |
|
237 | e_dict = {'repo_name':_('This repository already exists')} | |
|
238 | raise formencode.Invalid('', value, state, | |
|
239 | error_dict=e_dict) | |
|
240 | return value | |
|
222 | 241 | |
|
223 | 242 | |
|
224 | 243 | return _ValidRepoName |
|
225 | 244 | |
|
245 | def SlugifyRepo(): | |
|
246 | class _SlugifyRepo(formencode.validators.FancyValidator): | |
|
247 | ||
|
248 | def to_python(self, value, state): | |
|
249 | return repo_name_slug(value) | |
|
250 | ||
|
251 | return _SlugifyRepo | |
|
252 | ||
|
226 | 253 | def ValidCloneUri(): |
|
227 | 254 | from mercurial.httprepo import httprepository, httpsrepository |
|
228 | 255 | from rhodecode.lib.utils import make_ui |
@@ -484,7 +511,7 b' def RepoForm(edit=False, old_data={}, su' | |||
|
484 | 511 | allow_extra_fields = True |
|
485 | 512 | filter_extra_fields = False |
|
486 | 513 | repo_name = All(UnicodeString(strip=True, min=1, not_empty=True), |
|
487 |
|
|
|
514 | SlugifyRepo()) | |
|
488 | 515 | clone_uri = All(UnicodeString(strip=True, min=1, not_empty=False), |
|
489 | 516 | ValidCloneUri()()) |
|
490 | 517 | repo_group = OneOf(repo_groups, hideList=True) |
@@ -496,9 +523,9 b' def RepoForm(edit=False, old_data={}, su' | |||
|
496 | 523 | |
|
497 | 524 | if edit: |
|
498 | 525 | #this is repo owner |
|
499 |
user = All( |
|
|
526 | user = All(UnicodeString(not_empty=True), ValidRepoUser) | |
|
500 | 527 | |
|
501 | chained_validators = [ValidPerms] | |
|
528 | chained_validators = [ValidRepoName(edit, old_data), ValidPerms] | |
|
502 | 529 | return _RepoForm |
|
503 | 530 | |
|
504 | 531 | def RepoForkForm(edit=False, old_data={}, supported_backends=BACKENDS.keys()): |
@@ -506,7 +533,7 b' def RepoForkForm(edit=False, old_data={}' | |||
|
506 | 533 | allow_extra_fields = True |
|
507 | 534 | filter_extra_fields = False |
|
508 | 535 | fork_name = All(UnicodeString(strip=True, min=1, not_empty=True), |
|
509 |
|
|
|
536 | SlugifyRepo()) | |
|
510 | 537 | description = UnicodeString(strip=True, min=1, not_empty=True) |
|
511 | 538 | private = StringBoolean(if_missing=False) |
|
512 | 539 | repo_type = All(ValidForkType(old_data), OneOf(supported_backends)) |
@@ -517,11 +544,11 b' def RepoSettingsForm(edit=False, old_dat' | |||
|
517 | 544 | allow_extra_fields = True |
|
518 | 545 | filter_extra_fields = False |
|
519 | 546 | repo_name = All(UnicodeString(strip=True, min=1, not_empty=True), |
|
520 |
|
|
|
547 | SlugifyRepo()) | |
|
521 | 548 | description = UnicodeString(strip=True, min=1, not_empty=True) |
|
522 | 549 | private = StringBoolean(if_missing=False) |
|
523 | 550 | |
|
524 | chained_validators = [ValidPerms, ValidSettings] | |
|
551 | chained_validators = [ValidRepoName(edit, old_data), ValidPerms, ValidSettings] | |
|
525 | 552 | return _RepoForm |
|
526 | 553 | |
|
527 | 554 |
@@ -36,7 +36,7 b' from vcs.backends import get_backend' | |||
|
36 | 36 | from rhodecode.model import BaseModel |
|
37 | 37 | from rhodecode.model.caching_query import FromCache |
|
38 | 38 | from rhodecode.model.db import Repository, RepoToPerm, User, Permission, \ |
|
39 | Statistics, UsersGroup, UsersGroupRepoToPerm, RhodeCodeUi | |
|
39 | Statistics, UsersGroup, UsersGroupRepoToPerm, RhodeCodeUi, Group | |
|
40 | 40 | from rhodecode.model.user import UserModel |
|
41 | 41 | |
|
42 | 42 | log = logging.getLogger(__name__) |
@@ -169,15 +169,21 b' class RepoModel(BaseModel):' | |||
|
169 | 169 | #update current repo |
|
170 | 170 | for k, v in form_data.items(): |
|
171 | 171 | if k == 'user': |
|
172 | cur_repo.user = user_model.get(v) | |
|
172 | cur_repo.user = user_model.get_by_username(v) | |
|
173 | elif k == 'repo_name': | |
|
174 | cur_repo.repo_name = form_data['repo_name_full'] | |
|
175 | elif k == 'repo_group' and v: | |
|
176 | cur_repo.group_id = v | |
|
177 | ||
|
173 | 178 | else: |
|
174 | 179 | setattr(cur_repo, k, v) |
|
175 | 180 | |
|
176 | 181 | self.sa.add(cur_repo) |
|
177 | 182 | |
|
178 | if repo_name != form_data['repo_name']: | |
|
179 |
#rename |
|
|
180 |
self.__rename_repo(repo_name, |
|
|
183 | if repo_name != form_data['repo_name_full']: | |
|
184 | # rename repository | |
|
185 | self.__rename_repo(old=repo_name, | |
|
186 | new=form_data['repo_name_full']) | |
|
181 | 187 | |
|
182 | 188 | self.sa.commit() |
|
183 | 189 | except: |
General Comments 0
You need to be logged in to leave comments.
Login now