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