Changeset - a7a772ea7b95
[Not reviewed]
beta
0 4 0
Marcin Kuzminski - 15 years ago 2011-05-12 00:31:17
marcin@python-works.com
fixed saving settings on repositories inside groups, also fixes #187
added options to properly rename directories in groups
4 files changed with 63 insertions and 24 deletions:
0 comments (0 inline, 0 general)
rhodecode/controllers/admin/repos.py
Show inline comments
 
@@ -234,7 +234,7 @@ class ReposController(BaseController):
 
            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)
 

	
rhodecode/model/db.py
Show inline comments
 
@@ -327,6 +327,12 @@ class Group(Base):
 
            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()
rhodecode/model/forms.py
Show inline comments
 
@@ -38,7 +38,7 @@ from rhodecode.lib.exceptions import Lda
 
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 @@ class ValidRepoUser(formencode.validator
 
        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 @@ def RepoForm(edit=False, old_data={}, su
 
        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 @@ def RepoForm(edit=False, old_data={}, su
 

	
 
        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 @@ def RepoForkForm(edit=False, old_data={}
 
        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 @@ def RepoSettingsForm(edit=False, old_dat
 
        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
 

	
 

	
rhodecode/model/repo.py
Show inline comments
 
@@ -36,7 +36,7 @@ from vcs.backends import get_backend
 
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 @@ class RepoModel(BaseModel):
 
            #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:
0 comments (0 inline, 0 general)