Mercurial > kallithea
changeset 5281:82faecc21324
repogroups: use group IDs as integers instead of unicoding them
author | Mads Kiilerich <madski@unity3d.com> |
---|---|
date | Mon, 20 Jul 2015 15:11:42 +0200 |
parents | 24239f8ea946 |
children | d04e36ef71a8 |
files | kallithea/controllers/admin/repo_groups.py kallithea/controllers/admin/repos.py kallithea/controllers/forks.py kallithea/model/db.py kallithea/model/forms.py kallithea/model/validators.py kallithea/tests/fixture.py kallithea/tests/functional/test_forks.py |
diffstat | 8 files changed, 27 insertions(+), 23 deletions(-) [+] |
line wrap: on
line diff
--- a/kallithea/controllers/admin/repo_groups.py Mon Jul 20 15:11:42 2015 +0200 +++ b/kallithea/controllers/admin/repo_groups.py Mon Jul 20 15:11:42 2015 +0200 @@ -77,7 +77,7 @@ # 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 @@ # 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(
--- a/kallithea/controllers/admin/repos.py Mon Jul 20 15:11:42 2015 +0200 +++ b/kallithea/controllers/admin/repos.py Mon Jul 20 15:11:42 2015 +0200 @@ -79,7 +79,7 @@ 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 @@ 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 @@ 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
--- a/kallithea/controllers/forks.py Mon Jul 20 15:11:42 2015 +0200 +++ b/kallithea/controllers/forks.py Mon Jul 20 15:11:42 2015 +0200 @@ -59,7 +59,7 @@ 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
--- a/kallithea/model/db.py Mon Jul 20 15:11:42 2015 +0200 +++ b/kallithea/model/db.py Mon Jul 20 15:11:42 2015 +0200 @@ -1512,15 +1512,15 @@ @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)
--- a/kallithea/model/forms.py Mon Jul 20 15:11:42 2015 +0200 +++ b/kallithea/model/forms.py Mon Jul 20 15:11:42 2015 +0200 @@ -165,7 +165,8 @@ 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 @@ 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 @@ 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)
--- a/kallithea/model/validators.py Mon Jul 20 15:11:42 2015 +0200 +++ b/kallithea/model/validators.py Mon Jul 20 15:11:42 2015 +0200 @@ -212,7 +212,7 @@ # 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 _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 @@ 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 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
--- a/kallithea/tests/fixture.py Mon Jul 20 15:11:42 2015 +0200 +++ b/kallithea/tests/fixture.py Mon Jul 20 15:11:42 2015 +0200 @@ -75,7 +75,7 @@ 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',
--- a/kallithea/tests/functional/test_forks.py Mon Jul 20 15:11:42 2015 +0200 +++ b/kallithea/tests/functional/test_forks.py Mon Jul 20 15:11:42 2015 +0200 @@ -77,7 +77,7 @@ 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 @@ 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,