##// END OF EJS Templates
repogroups: use group IDs as integers instead of unicoding them
Mads Kiilerich -
r5281:82faecc2 default
parent child Browse files
Show More
@@ -77,7 +77,7 b' class RepoGroupsController(BaseControlle'
77 # exclude filtered ids
77 # exclude filtered ids
78 c.repo_groups = filter(lambda x: x[0] not in exclude_group_ids,
78 c.repo_groups = filter(lambda x: x[0] not in exclude_group_ids,
79 c.repo_groups)
79 c.repo_groups)
80 c.repo_groups_choices = map(lambda k: unicode(k[0]), c.repo_groups)
80 c.repo_groups_choices = map(lambda k: k[0], c.repo_groups)
81 repo_model = RepoModel()
81 repo_model = RepoModel()
82 c.users_array = repo_model.get_users_js()
82 c.users_array = repo_model.get_users_js()
83 c.user_groups_array = repo_model.get_user_groups_js()
83 c.user_groups_array = repo_model.get_user_groups_js()
@@ -169,7 +169,7 b' class RepoGroupsController(BaseControlle'
169 # permissions for can create group based on parent_id are checked
169 # permissions for can create group based on parent_id are checked
170 # here in the Form
170 # here in the Form
171 repo_group_form = RepoGroupForm(available_groups=
171 repo_group_form = RepoGroupForm(available_groups=
172 map(lambda k: unicode(k[0]), c.repo_groups))()
172 map(lambda k: k[0], c.repo_groups))()
173 try:
173 try:
174 form_result = repo_group_form.to_python(dict(request.POST))
174 form_result = repo_group_form.to_python(dict(request.POST))
175 RepoGroupModel().create(
175 RepoGroupModel().create(
@@ -79,7 +79,7 b' class ReposController(BaseRepoController'
79 acl_groups = RepoGroupList(RepoGroup.query().all(),
79 acl_groups = RepoGroupList(RepoGroup.query().all(),
80 perm_set=['group.write', 'group.admin'])
80 perm_set=['group.write', 'group.admin'])
81 c.repo_groups = RepoGroup.groups_choices(groups=acl_groups)
81 c.repo_groups = RepoGroup.groups_choices(groups=acl_groups)
82 c.repo_groups_choices = map(lambda k: unicode(k[0]), c.repo_groups)
82 c.repo_groups_choices = map(lambda k: k[0], c.repo_groups)
83
83
84 # in case someone no longer have a group.write access to a repository
84 # in case someone no longer have a group.write access to a repository
85 # pre fill the list with this entry, we don't care if this is the same
85 # pre fill the list with this entry, we don't care if this is the same
@@ -88,8 +88,8 b' class ReposController(BaseRepoController'
88 repo_group = None
88 repo_group = None
89 if repo:
89 if repo:
90 repo_group = repo.group
90 repo_group = repo.group
91 if repo_group and unicode(repo_group.group_id) not in c.repo_groups_choices:
91 if repo_group and repo_group.group_id not in c.repo_groups_choices:
92 c.repo_groups_choices.append(unicode(repo_group.group_id))
92 c.repo_groups_choices.append(repo_group.group_id)
93 c.repo_groups.append(RepoGroup._generate_choice(repo_group))
93 c.repo_groups.append(RepoGroup._generate_choice(repo_group))
94
94
95 choices, c.landing_revs = ScmModel().get_repo_landing_revs()
95 choices, c.landing_revs = ScmModel().get_repo_landing_revs()
@@ -188,7 +188,7 b' class ReposController(BaseRepoController'
188 acl_groups = RepoGroupList(RepoGroup.query().all(),
188 acl_groups = RepoGroupList(RepoGroup.query().all(),
189 perm_set=['group.write', 'group.admin'])
189 perm_set=['group.write', 'group.admin'])
190 c.repo_groups = RepoGroup.groups_choices(groups=acl_groups)
190 c.repo_groups = RepoGroup.groups_choices(groups=acl_groups)
191 c.repo_groups_choices = map(lambda k: unicode(k[0]), c.repo_groups)
191 c.repo_groups_choices = map(lambda k: k[0], c.repo_groups)
192 choices, c.landing_revs = ScmModel().get_repo_landing_revs()
192 choices, c.landing_revs = ScmModel().get_repo_landing_revs()
193
193
194 ## apply the defaults from defaults page
194 ## apply the defaults from defaults page
@@ -59,7 +59,7 b' class ForksController(BaseRepoController'
59 acl_groups = RepoGroupList(RepoGroup.query().all(),
59 acl_groups = RepoGroupList(RepoGroup.query().all(),
60 perm_set=['group.write', 'group.admin'])
60 perm_set=['group.write', 'group.admin'])
61 c.repo_groups = RepoGroup.groups_choices(groups=acl_groups)
61 c.repo_groups = RepoGroup.groups_choices(groups=acl_groups)
62 c.repo_groups_choices = map(lambda k: unicode(k[0]), c.repo_groups)
62 c.repo_groups_choices = map(lambda k: k[0], c.repo_groups)
63 choices, c.landing_revs = ScmModel().get_repo_landing_revs()
63 choices, c.landing_revs = ScmModel().get_repo_landing_revs()
64 c.landing_revs_choices = choices
64 c.landing_revs_choices = choices
65 c.can_update = Ui.get_by_key(Ui.HOOK_UPDATE).ui_active
65 c.can_update = Ui.get_by_key(Ui.HOOK_UPDATE).ui_active
@@ -1512,15 +1512,15 b' class RepoGroup(Base, BaseModel):'
1512
1512
1513 @classmethod
1513 @classmethod
1514 def _generate_choice(cls, repo_group):
1514 def _generate_choice(cls, repo_group):
1515 """Return tuple with group_id as unicode string and name as html literal"""
1515 """Return tuple with group_id and name as html literal"""
1516 from webhelpers.html import literal
1516 from webhelpers.html import literal
1517 if repo_group is None:
1517 if repo_group is None:
1518 return (u'-1', u'-- %s --' % _('top level'))
1518 return (-1, u'-- %s --' % _('top level'))
1519 return unicode(repo_group.group_id), literal(cls.SEP.join(repo_group.full_path_splitted))
1519 return repo_group.group_id, literal(cls.SEP.join(repo_group.full_path_splitted))
1520
1520
1521 @classmethod
1521 @classmethod
1522 def groups_choices(cls, groups, show_empty_group=True):
1522 def groups_choices(cls, groups, show_empty_group=True):
1523 """Return tuples with group_id as unicode string and name as html literal."""
1523 """Return tuples with group_id and name as html literal."""
1524
1524
1525 if show_empty_group:
1525 if show_empty_group:
1526 groups = list(groups)
1526 groups = list(groups)
@@ -165,7 +165,8 b' def RepoGroupForm(edit=False, old_data={'
165 group_parent_id = All(v.CanCreateGroup(can_create_in_root),
165 group_parent_id = All(v.CanCreateGroup(can_create_in_root),
166 v.OneOf(available_groups, hideList=False,
166 v.OneOf(available_groups, hideList=False,
167 testValueList=True,
167 testValueList=True,
168 if_missing=None, not_empty=True))
168 if_missing=None, not_empty=True),
169 v.Int(min=-1, not_empty=True))
169 enable_locking = v.StringBoolean(if_missing=False)
170 enable_locking = v.StringBoolean(if_missing=False)
170 chained_validators = [v.ValidRepoGroup(edit, old_data)]
171 chained_validators = [v.ValidRepoGroup(edit, old_data)]
171
172
@@ -214,7 +215,8 b' def RepoForm(edit=False, old_data={}, su'
214 repo_name = All(v.UnicodeString(strip=True, min=1, not_empty=True),
215 repo_name = All(v.UnicodeString(strip=True, min=1, not_empty=True),
215 v.SlugifyName())
216 v.SlugifyName())
216 repo_group = All(v.CanWriteGroup(old_data),
217 repo_group = All(v.CanWriteGroup(old_data),
217 v.OneOf(repo_groups, hideList=True))
218 v.OneOf(repo_groups, hideList=True),
219 v.Int(min=-1, not_empty=True))
218 repo_type = v.OneOf(supported_backends, required=False,
220 repo_type = v.OneOf(supported_backends, required=False,
219 if_missing=old_data.get('repo_type'))
221 if_missing=old_data.get('repo_type'))
220 repo_description = v.UnicodeString(strip=True, min=1, not_empty=False)
222 repo_description = v.UnicodeString(strip=True, min=1, not_empty=False)
@@ -286,7 +288,8 b' def RepoForkForm(edit=False, old_data={}'
286 repo_name = All(v.UnicodeString(strip=True, min=1, not_empty=True),
288 repo_name = All(v.UnicodeString(strip=True, min=1, not_empty=True),
287 v.SlugifyName())
289 v.SlugifyName())
288 repo_group = All(v.CanWriteGroup(),
290 repo_group = All(v.CanWriteGroup(),
289 v.OneOf(repo_groups, hideList=True))
291 v.OneOf(repo_groups, hideList=True),
292 v.Int(min=-1, not_empty=True))
290 repo_type = All(v.ValidForkType(old_data), v.OneOf(supported_backends))
293 repo_type = All(v.ValidForkType(old_data), v.OneOf(supported_backends))
291 description = v.UnicodeString(strip=True, min=1, not_empty=True)
294 description = v.UnicodeString(strip=True, min=1, not_empty=True)
292 private = v.StringBoolean(if_missing=False)
295 private = v.StringBoolean(if_missing=False)
@@ -212,7 +212,7 b' def ValidRepoGroup(edit=False, old_data='
212
212
213 # check for parent of self
213 # check for parent of self
214 parent_of_self = lambda: (
214 parent_of_self = lambda: (
215 old_data['group_id'] == int(group_parent_id)
215 old_data['group_id'] == group_parent_id
216 if group_parent_id else False
216 if group_parent_id else False
217 )
217 )
218 if edit and parent_of_self():
218 if edit and parent_of_self():
@@ -520,13 +520,14 b' def CanWriteGroup(old_data=None):'
520
520
521 def _to_python(self, value, state):
521 def _to_python(self, value, state):
522 #root location
522 #root location
523 if value in [-1, "-1"]:
523 if value == -1:
524 return None
524 return None
525 return value
525 return value
526
526
527 def validate_python(self, value, state):
527 def validate_python(self, value, state):
528 gr = RepoGroup.get(value)
528 gr = RepoGroup.get(value)
529 gr_name = gr.group_name if gr else None # None means ROOT location
529 gr_name = gr.group_name if gr is not None else None # None means ROOT location
530
530 # create repositories with write permission on group is set to true
531 # create repositories with write permission on group is set to true
531 create_on_write = HasPermissionAny('hg.create.write_on_repogroup.true')()
532 create_on_write = HasPermissionAny('hg.create.write_on_repogroup.true')()
532 group_admin = HasRepoGroupPermissionAny('group.admin')(gr_name,
533 group_admin = HasRepoGroupPermissionAny('group.admin')(gr_name,
@@ -537,7 +538,7 b' def CanWriteGroup(old_data=None):'
537 can_create_repos = HasPermissionAny('hg.admin', 'hg.create.repository')
538 can_create_repos = HasPermissionAny('hg.admin', 'hg.create.repository')
538 gid = (old_data['repo_group'].get('group_id')
539 gid = (old_data['repo_group'].get('group_id')
539 if (old_data and 'repo_group' in old_data) else None)
540 if (old_data and 'repo_group' in old_data) else None)
540 value_changed = gid != safe_int(value)
541 value_changed = gid != value
541 new = not old_data
542 new = not old_data
542 # do check if we changed the value, there's a case that someone got
543 # do check if we changed the value, there's a case that someone got
543 # revoked write permissions to a repository, he still created, we
544 # revoked write permissions to a repository, he still created, we
@@ -569,13 +570,13 b' def CanCreateGroup(can_create_in_root=Fa'
569
570
570 def to_python(self, value, state):
571 def to_python(self, value, state):
571 #root location
572 #root location
572 if value in [-1, "-1"]:
573 if value == -1:
573 return None
574 return None
574 return value
575 return value
575
576
576 def validate_python(self, value, state):
577 def validate_python(self, value, state):
577 gr = RepoGroup.get(value)
578 gr = RepoGroup.get(value)
578 gr_name = gr.group_name if gr else None # None means ROOT location
579 gr_name = gr.group_name if gr is not None else None # None means ROOT location
579
580
580 if can_create_in_root and gr is None:
581 if can_create_in_root and gr is None:
581 #we can create in root, we're fine no validations required
582 #we can create in root, we're fine no validations required
@@ -75,7 +75,7 b' class Fixture(object):'
75 repo_name=None,
75 repo_name=None,
76 repo_type='hg',
76 repo_type='hg',
77 clone_uri='',
77 clone_uri='',
78 repo_group='-1',
78 repo_group=u'-1',
79 repo_description='DESC',
79 repo_description='DESC',
80 repo_private=False,
80 repo_private=False,
81 repo_landing_rev='rev:tip',
81 repo_landing_rev='rev:tip',
@@ -77,7 +77,7 b' class _BaseTestCase(object):'
77 org_repo = Repository.get_by_repo_name(repo_name)
77 org_repo = Repository.get_by_repo_name(repo_name)
78 creation_args = {
78 creation_args = {
79 'repo_name': fork_name,
79 'repo_name': fork_name,
80 'repo_group': '',
80 'repo_group': u'-1',
81 'fork_parent_id': org_repo.repo_id,
81 'fork_parent_id': org_repo.repo_id,
82 'repo_type': self.REPO_TYPE,
82 'repo_type': self.REPO_TYPE,
83 'description': description,
83 'description': description,
@@ -152,7 +152,7 b' class _BaseTestCase(object):'
152 org_repo = Repository.get_by_repo_name(repo_name)
152 org_repo = Repository.get_by_repo_name(repo_name)
153 creation_args = {
153 creation_args = {
154 'repo_name': fork_name,
154 'repo_name': fork_name,
155 'repo_group': '',
155 'repo_group': u'-1',
156 'fork_parent_id': org_repo.repo_id,
156 'fork_parent_id': org_repo.repo_id,
157 'repo_type': self.REPO_TYPE,
157 'repo_type': self.REPO_TYPE,
158 'description': description,
158 'description': description,
General Comments 0
You need to be logged in to leave comments. Login now