Changeset - 82faecc21324
[Not reviewed]
default
0 8 0
Mads Kiilerich - 10 years ago 2015-07-20 15:11:42
madski@unity3d.com
repogroups: use group IDs as integers instead of unicoding them
8 files changed with 27 insertions and 23 deletions:
0 comments (0 inline, 0 general)
kallithea/controllers/admin/repo_groups.py
Show inline comments
 
@@ -77,7 +77,7 @@ class RepoGroupsController(BaseControlle
 
        # exclude filtered ids
 
        c.repo_groups = filter(lambda x: x[0] not in exclude_group_ids,
 
                               c.repo_groups)
 
        c.repo_groups_choices = map(lambda k: unicode(k[0]), c.repo_groups)
 
        c.repo_groups_choices = map(lambda k: k[0], c.repo_groups)
 
        repo_model = RepoModel()
 
        c.users_array = repo_model.get_users_js()
 
        c.user_groups_array = repo_model.get_user_groups_js()
 
@@ -169,7 +169,7 @@ class RepoGroupsController(BaseControlle
 
        # permissions for can create group based on parent_id are checked
 
        # here in the Form
 
        repo_group_form = RepoGroupForm(available_groups=
 
                                map(lambda k: unicode(k[0]), c.repo_groups))()
 
                                        map(lambda k: k[0], c.repo_groups))()
 
        try:
 
            form_result = repo_group_form.to_python(dict(request.POST))
 
            RepoGroupModel().create(
kallithea/controllers/admin/repos.py
Show inline comments
 
@@ -79,7 +79,7 @@ class ReposController(BaseRepoController
 
        acl_groups = RepoGroupList(RepoGroup.query().all(),
 
                               perm_set=['group.write', 'group.admin'])
 
        c.repo_groups = RepoGroup.groups_choices(groups=acl_groups)
 
        c.repo_groups_choices = map(lambda k: unicode(k[0]), c.repo_groups)
 
        c.repo_groups_choices = map(lambda k: k[0], c.repo_groups)
 

	
 
        # in case someone no longer have a group.write access to a repository
 
        # pre fill the list with this entry, we don't care if this is the same
 
@@ -88,8 +88,8 @@ class ReposController(BaseRepoController
 
        repo_group = None
 
        if repo:
 
            repo_group = repo.group
 
        if repo_group and unicode(repo_group.group_id) not in c.repo_groups_choices:
 
            c.repo_groups_choices.append(unicode(repo_group.group_id))
 
        if repo_group and repo_group.group_id not in c.repo_groups_choices:
 
            c.repo_groups_choices.append(repo_group.group_id)
 
            c.repo_groups.append(RepoGroup._generate_choice(repo_group))
 

	
 
        choices, c.landing_revs = ScmModel().get_repo_landing_revs()
 
@@ -188,7 +188,7 @@ class ReposController(BaseRepoController
 
        acl_groups = RepoGroupList(RepoGroup.query().all(),
 
                               perm_set=['group.write', 'group.admin'])
 
        c.repo_groups = RepoGroup.groups_choices(groups=acl_groups)
 
        c.repo_groups_choices = map(lambda k: unicode(k[0]), c.repo_groups)
 
        c.repo_groups_choices = map(lambda k: k[0], c.repo_groups)
 
        choices, c.landing_revs = ScmModel().get_repo_landing_revs()
 

	
 
        ## apply the defaults from defaults page
kallithea/controllers/forks.py
Show inline comments
 
@@ -59,7 +59,7 @@ class ForksController(BaseRepoController
 
        acl_groups = RepoGroupList(RepoGroup.query().all(),
 
                               perm_set=['group.write', 'group.admin'])
 
        c.repo_groups = RepoGroup.groups_choices(groups=acl_groups)
 
        c.repo_groups_choices = map(lambda k: unicode(k[0]), c.repo_groups)
 
        c.repo_groups_choices = map(lambda k: k[0], c.repo_groups)
 
        choices, c.landing_revs = ScmModel().get_repo_landing_revs()
 
        c.landing_revs_choices = choices
 
        c.can_update = Ui.get_by_key(Ui.HOOK_UPDATE).ui_active
kallithea/model/db.py
Show inline comments
 
@@ -1512,15 +1512,15 @@ class RepoGroup(Base, BaseModel):
 

	
 
    @classmethod
 
    def _generate_choice(cls, repo_group):
 
        """Return tuple with group_id as unicode string and name as html literal"""
 
        """Return tuple with group_id and name as html literal"""
 
        from webhelpers.html import literal
 
        if repo_group is None:
 
            return (u'-1', u'-- %s --' % _('top level'))
 
        return unicode(repo_group.group_id), literal(cls.SEP.join(repo_group.full_path_splitted))
 
            return (-1, u'-- %s --' % _('top level'))
 
        return repo_group.group_id, literal(cls.SEP.join(repo_group.full_path_splitted))
 

	
 
    @classmethod
 
    def groups_choices(cls, groups, show_empty_group=True):
 
        """Return tuples with group_id as unicode string and name as html literal."""
 
        """Return tuples with group_id and name as html literal."""
 

	
 
        if show_empty_group:
 
            groups = list(groups)
kallithea/model/forms.py
Show inline comments
 
@@ -165,7 +165,8 @@ def RepoGroupForm(edit=False, old_data={
 
        group_parent_id = All(v.CanCreateGroup(can_create_in_root),
 
                              v.OneOf(available_groups, hideList=False,
 
                                      testValueList=True,
 
                                      if_missing=None, not_empty=True))
 
                                      if_missing=None, not_empty=True),
 
                              v.Int(min=-1, not_empty=True))
 
        enable_locking = v.StringBoolean(if_missing=False)
 
        chained_validators = [v.ValidRepoGroup(edit, old_data)]
 

	
 
@@ -214,7 +215,8 @@ def RepoForm(edit=False, old_data={}, su
 
        repo_name = All(v.UnicodeString(strip=True, min=1, not_empty=True),
 
                        v.SlugifyName())
 
        repo_group = All(v.CanWriteGroup(old_data),
 
                         v.OneOf(repo_groups, hideList=True))
 
                         v.OneOf(repo_groups, hideList=True),
 
                         v.Int(min=-1, not_empty=True))
 
        repo_type = v.OneOf(supported_backends, required=False,
 
                            if_missing=old_data.get('repo_type'))
 
        repo_description = v.UnicodeString(strip=True, min=1, not_empty=False)
 
@@ -286,7 +288,8 @@ def RepoForkForm(edit=False, old_data={}
 
        repo_name = All(v.UnicodeString(strip=True, min=1, not_empty=True),
 
                        v.SlugifyName())
 
        repo_group = All(v.CanWriteGroup(),
 
                         v.OneOf(repo_groups, hideList=True))
 
                         v.OneOf(repo_groups, hideList=True),
 
                         v.Int(min=-1, not_empty=True))
 
        repo_type = All(v.ValidForkType(old_data), v.OneOf(supported_backends))
 
        description = v.UnicodeString(strip=True, min=1, not_empty=True)
 
        private = v.StringBoolean(if_missing=False)
kallithea/model/validators.py
Show inline comments
 
@@ -212,7 +212,7 @@ def ValidRepoGroup(edit=False, old_data=
 

	
 
            # check for parent of self
 
            parent_of_self = lambda: (
 
                old_data['group_id'] == int(group_parent_id)
 
                old_data['group_id'] == group_parent_id
 
                if group_parent_id else False
 
            )
 
            if edit and parent_of_self():
 
@@ -520,13 +520,14 @@ def CanWriteGroup(old_data=None):
 

	
 
        def _to_python(self, value, state):
 
            #root location
 
            if value in [-1, "-1"]:
 
            if value == -1:
 
                return None
 
            return value
 

	
 
        def validate_python(self, value, state):
 
            gr = RepoGroup.get(value)
 
            gr_name = gr.group_name if gr else None  # None means ROOT location
 
            gr_name = gr.group_name if gr is not None else None # None means ROOT location
 

	
 
            # create repositories with write permission on group is set to true
 
            create_on_write = HasPermissionAny('hg.create.write_on_repogroup.true')()
 
            group_admin = HasRepoGroupPermissionAny('group.admin')(gr_name,
 
@@ -537,7 +538,7 @@ def CanWriteGroup(old_data=None):
 
            can_create_repos = HasPermissionAny('hg.admin', 'hg.create.repository')
 
            gid = (old_data['repo_group'].get('group_id')
 
                   if (old_data and 'repo_group' in old_data) else None)
 
            value_changed = gid != safe_int(value)
 
            value_changed = gid != value
 
            new = not old_data
 
            # do check if we changed the value, there's a case that someone got
 
            # revoked write permissions to a repository, he still created, we
 
@@ -569,13 +570,13 @@ def CanCreateGroup(can_create_in_root=Fa
 

	
 
        def to_python(self, value, state):
 
            #root location
 
            if value in [-1, "-1"]:
 
            if value == -1:
 
                return None
 
            return value
 

	
 
        def validate_python(self, value, state):
 
            gr = RepoGroup.get(value)
 
            gr_name = gr.group_name if gr else None  # None means ROOT location
 
            gr_name = gr.group_name if gr is not None else None # None means ROOT location
 

	
 
            if can_create_in_root and gr is None:
 
                #we can create in root, we're fine no validations required
kallithea/tests/fixture.py
Show inline comments
 
@@ -75,7 +75,7 @@ class Fixture(object):
 
            repo_name=None,
 
            repo_type='hg',
 
            clone_uri='',
 
            repo_group='-1',
 
            repo_group=u'-1',
 
            repo_description='DESC',
 
            repo_private=False,
 
            repo_landing_rev='rev:tip',
kallithea/tests/functional/test_forks.py
Show inline comments
 
@@ -77,7 +77,7 @@ class _BaseTestCase(object):
 
        org_repo = Repository.get_by_repo_name(repo_name)
 
        creation_args = {
 
            'repo_name': fork_name,
 
            'repo_group': '',
 
            'repo_group': u'-1',
 
            'fork_parent_id': org_repo.repo_id,
 
            'repo_type': self.REPO_TYPE,
 
            'description': description,
 
@@ -152,7 +152,7 @@ class _BaseTestCase(object):
 
        org_repo = Repository.get_by_repo_name(repo_name)
 
        creation_args = {
 
            'repo_name': fork_name,
 
            'repo_group': '',
 
            'repo_group': u'-1',
 
            'fork_parent_id': org_repo.repo_id,
 
            'repo_type': self.REPO_TYPE,
 
            'description': description,
0 comments (0 inline, 0 general)