# HG changeset patch # User Marcin Kuzminski # Date 1305153077 -7200 # Node ID a7a772ea7b9599760dc95a08eee98844c9a18178 # Parent 8cca07df79dd0a0082bb6188a26b8c6edfcb8173 fixed saving settings on repositories inside groups, also fixes #187 added options to properly rename directories in groups diff -r 8cca07df79dd -r a7a772ea7b95 rhodecode/controllers/admin/repos.py --- a/rhodecode/controllers/admin/repos.py Sun May 08 20:11:26 2011 +0200 +++ b/rhodecode/controllers/admin/repos.py Thu May 12 00:31:17 2011 +0200 @@ -234,7 +234,7 @@ invalidate_cache('get_repo_cached_%s' % repo_name) h.flash(_('Repository %s updated successfully' % repo_name), category='success') - changed_name = form_result['repo_name'] + changed_name = form_result['repo_name_full'] action_logger(self.rhodecode_user, 'admin_updated_repo', changed_name, '', self.sa) diff -r 8cca07df79dd -r a7a772ea7b95 rhodecode/model/db.py --- a/rhodecode/model/db.py Sun May 08 20:11:26 2011 +0200 +++ b/rhodecode/model/db.py Thu May 12 00:31:17 2011 +0200 @@ -327,6 +327,12 @@ groups.insert(0, gr) return groups + + @property + def full_path(self): + return '/'.join([g.group_name for g in self.parents] + + [self.group_name]) + @property def repositories(self): return Session.query(Repository).filter(Repository.group == self).all() diff -r 8cca07df79dd -r a7a772ea7b95 rhodecode/model/forms.py --- a/rhodecode/model/forms.py Sun May 08 20:11:26 2011 +0200 +++ b/rhodecode/model/forms.py Thu May 12 00:31:17 2011 +0200 @@ -38,7 +38,7 @@ from rhodecode.model import meta from rhodecode.model.user import UserModel from rhodecode.model.repo import RepoModel -from rhodecode.model.db import User, UsersGroup +from rhodecode.model.db import User, UsersGroup, Group from rhodecode import BACKENDS log = logging.getLogger(__name__) @@ -204,25 +204,52 @@ finally: meta.Session.remove() - return self.user_db.user_id + return value def ValidRepoName(edit, old_data): class _ValidRepoName(formencode.validators.FancyValidator): + def to_python(self, value, state): - def to_python(self, value, state): - slug = repo_name_slug(value) - if slug in ['_admin']: - raise formencode.Invalid(_('This repository name is disallowed'), - value, state) - if old_data.get('repo_name') != value or not edit: - if RepoModel().get_by_repo_name(slug, cache=False): - raise formencode.Invalid(_('This repository already exists') , - value, state) - return slug + repo_name = value.get('repo_name') + + slug = repo_name_slug(repo_name) + if slug in ['_admin', '']: + e_dict = {'repo_name': _('This repository name is disallowed')} + raise formencode.Invalid('', value, state, error_dict=e_dict) + + gr = Group.get(value.get('repo_group')) + + # value needs to be aware of group name + repo_name_full = gr.full_path + '/' + repo_name + value['repo_name_full'] = repo_name_full + if old_data.get('repo_name') != repo_name_full or not edit: + + if gr.full_path != '': + if RepoModel().get_by_repo_name(repo_name_full,): + e_dict = {'repo_name':_('This repository already ' + 'exists in group "%s"') % + gr.group_name} + raise formencode.Invalid('', value, state, + error_dict=e_dict) + + else: + if RepoModel().get_by_repo_name(repo_name_full): + e_dict = {'repo_name':_('This repository already exists')} + raise formencode.Invalid('', value, state, + error_dict=e_dict) + return value return _ValidRepoName +def SlugifyRepo(): + class _SlugifyRepo(formencode.validators.FancyValidator): + + def to_python(self, value, state): + return repo_name_slug(value) + + return _SlugifyRepo + def ValidCloneUri(): from mercurial.httprepo import httprepository, httpsrepository from rhodecode.lib.utils import make_ui @@ -484,7 +511,7 @@ allow_extra_fields = True filter_extra_fields = False repo_name = All(UnicodeString(strip=True, min=1, not_empty=True), - ValidRepoName(edit, old_data)) + SlugifyRepo()) clone_uri = All(UnicodeString(strip=True, min=1, not_empty=False), ValidCloneUri()()) repo_group = OneOf(repo_groups, hideList=True) @@ -496,9 +523,9 @@ if edit: #this is repo owner - user = All(Int(not_empty=True), ValidRepoUser) + user = All(UnicodeString(not_empty=True), ValidRepoUser) - chained_validators = [ValidPerms] + chained_validators = [ValidRepoName(edit, old_data), ValidPerms] return _RepoForm def RepoForkForm(edit=False, old_data={}, supported_backends=BACKENDS.keys()): @@ -506,7 +533,7 @@ allow_extra_fields = True filter_extra_fields = False fork_name = All(UnicodeString(strip=True, min=1, not_empty=True), - ValidRepoName(edit, old_data)) + SlugifyRepo()) description = UnicodeString(strip=True, min=1, not_empty=True) private = StringBoolean(if_missing=False) repo_type = All(ValidForkType(old_data), OneOf(supported_backends)) @@ -517,11 +544,11 @@ allow_extra_fields = True filter_extra_fields = False repo_name = All(UnicodeString(strip=True, min=1, not_empty=True), - ValidRepoName(edit, old_data)) + SlugifyRepo()) description = UnicodeString(strip=True, min=1, not_empty=True) private = StringBoolean(if_missing=False) - chained_validators = [ValidPerms, ValidSettings] + chained_validators = [ValidRepoName(edit, old_data), ValidPerms, ValidSettings] return _RepoForm diff -r 8cca07df79dd -r a7a772ea7b95 rhodecode/model/repo.py --- a/rhodecode/model/repo.py Sun May 08 20:11:26 2011 +0200 +++ b/rhodecode/model/repo.py Thu May 12 00:31:17 2011 +0200 @@ -36,7 +36,7 @@ from rhodecode.model import BaseModel from rhodecode.model.caching_query import FromCache from rhodecode.model.db import Repository, RepoToPerm, User, Permission, \ - Statistics, UsersGroup, UsersGroupRepoToPerm, RhodeCodeUi + Statistics, UsersGroup, UsersGroupRepoToPerm, RhodeCodeUi, Group from rhodecode.model.user import UserModel log = logging.getLogger(__name__) @@ -169,15 +169,21 @@ #update current repo for k, v in form_data.items(): if k == 'user': - cur_repo.user = user_model.get(v) + cur_repo.user = user_model.get_by_username(v) + elif k == 'repo_name': + cur_repo.repo_name = form_data['repo_name_full'] + elif k == 'repo_group' and v: + cur_repo.group_id = v + else: setattr(cur_repo, k, v) self.sa.add(cur_repo) - if repo_name != form_data['repo_name']: - #rename our data - self.__rename_repo(repo_name, form_data['repo_name']) + if repo_name != form_data['repo_name_full']: + # rename repository + self.__rename_repo(old=repo_name, + new=form_data['repo_name_full']) self.sa.commit() except: