本文整理汇总了Python中kallithea.model.db.RepoGroup类的典型用法代码示例。如果您正苦于以下问题:Python RepoGroup类的具体用法?Python RepoGroup怎么用?Python RepoGroup使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了RepoGroup类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __load_defaults
def __load_defaults(self):
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)
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
示例2: test_remove_group
def test_remove_group(self):
sg1 = fixture.create_repo_group(u'deleteme')
self.__delete_group(sg1.group_id)
assert RepoGroup.get(sg1.group_id) == None
assert not self.__check_path('deteteme')
sg1 = fixture.create_repo_group(u'deleteme', parent_group_id=self.g1.group_id)
self.__delete_group(sg1.group_id)
assert RepoGroup.get(sg1.group_id) == None
assert not self.__check_path('test1', 'deteteme')
示例3: show
def show(self, group_name):
c.active = 'settings'
c.group = c.repo_group = RepoGroup.guess_instance(group_name)
groups = RepoGroup.query(sorted=True).filter_by(parent_group=c.group).all()
c.groups = self.scm_model.get_repo_groups(groups)
repos_list = Repository.query(sorted=True).filter_by(group=c.group).all()
repos_data = RepoModel().get_repos_as_dict(repos_list=repos_list,
admin=False, short_name=True)
# data used to render the grid
c.data = repos_data
return render('admin/repo_groups/repo_group_show.html')
示例4: create_repo_group
def create_repo_group(self, name, **kwargs):
if 'skip_if_exists' in kwargs:
del kwargs['skip_if_exists']
gr = RepoGroup.get_by_group_name(group_name=name)
if gr:
return gr
form_data = self._get_group_create_params(group_name=name, **kwargs)
owner = kwargs.get('cur_user', TEST_USER_ADMIN_LOGIN)
gr = RepoGroupModel().create(
group_name=form_data['group_name'],
group_description=form_data['group_name'],
owner=owner, parent=form_data['group_parent_id'])
Session().commit()
gr = RepoGroup.get_by_group_name(gr.group_name)
return gr
示例5: test_update_group_parent
def test_update_group_parent(self):
sg1 = fixture.create_repo_group(u'initial', parent_group_id=self.g1.group_id)
new_sg1 = _update_repo_group(sg1.group_id, u'after', parent_id=self.g1.group_id)
assert self.__check_path('test1', 'after')
assert RepoGroup.get_by_group_name(u'test1/initial') == None
new_sg1 = _update_repo_group(sg1.group_id, u'after', parent_id=self.g3.group_id)
assert self.__check_path('test3', 'after')
assert RepoGroup.get_by_group_name(u'test3/initial') == None
new_sg1 = _update_repo_group(sg1.group_id, u'hello')
assert self.__check_path('hello')
assert RepoGroup.get_by_group_name(u'hello') == new_sg1
示例6: update_perms
def update_perms(self, group_name):
"""
Update permissions for given repository group
:param group_name:
"""
c.repo_group = RepoGroup.guess_instance(group_name)
valid_recursive_choices = ['none', 'repos', 'groups', 'all']
form_result = RepoGroupPermsForm(valid_recursive_choices)().to_python(request.POST)
if not request.authuser.is_admin:
if self._revoke_perms_on_yourself(form_result):
msg = _('Cannot revoke permission for yourself as admin')
h.flash(msg, category='warning')
raise HTTPFound(location=url('edit_repo_group_perms', group_name=group_name))
recursive = form_result['recursive']
# iterate over all members(if in recursive mode) of this groups and
# set the permissions !
# this can be potentially heavy operation
RepoGroupModel()._update_permissions(c.repo_group,
form_result['perms_new'],
form_result['perms_updates'],
recursive)
#TODO: implement this
#action_logger(request.authuser, 'admin_changed_repo_permissions',
# repo_name, request.ip_addr)
Session().commit()
h.flash(_('Repository group permissions updated'), category='success')
raise HTTPFound(location=url('edit_repo_group_perms', group_name=group_name))
示例7: delete
def delete(self, group_name):
gr = c.repo_group = RepoGroup.guess_instance(group_name)
repos = gr.repositories.all()
if repos:
h.flash(_('This group contains %s repositories and cannot be '
'deleted') % len(repos), category='warning')
raise HTTPFound(location=url('repos_groups'))
children = gr.children.all()
if children:
h.flash(_('This group contains %s subgroups and cannot be deleted'
% (len(children))), category='warning')
raise HTTPFound(location=url('repos_groups'))
try:
RepoGroupModel().delete(group_name)
Session().commit()
h.flash(_('Removed repository group %s') % group_name,
category='success')
#TODO: in future action_logger(, '', '', '')
except Exception:
log.error(traceback.format_exc())
h.flash(_('Error occurred during deletion of repository group %s')
% group_name, category='error')
if gr.parent_group:
raise HTTPFound(location=url('repos_group_home', group_name=gr.parent_group.group_name))
raise HTTPFound(location=url('repos_groups'))
示例8: permissions_setup_func
def permissions_setup_func(group_name='g0', perm='group.read', recursive='all',
user_id=None):
"""
Resets all permissions to perm attribute
"""
if not user_id:
user_id = test_u1_id
permissions_setup_func(group_name, perm, recursive,
user_id=User.get_default_user().user_id)
repo_group = RepoGroup.get_by_group_name(group_name=group_name)
if not repo_group:
raise Exception('Cannot get group %s' % group_name)
# Start with a baseline that current group can read recursive
perms_updates = [[user_id, 'group.read', 'user']]
RepoGroupModel()._update_permissions(repo_group,
perms_updates=perms_updates,
recursive='all', check_perms=False)
perms_updates = [[user_id, perm, 'user']]
RepoGroupModel()._update_permissions(repo_group,
perms_updates=perms_updates,
recursive=recursive, check_perms=False)
Session().commit()
示例9: show
def show(self, group_name):
"""GET /repo_groups/group_name: Show a specific item"""
# url('repos_group', group_name=GROUP_NAME)
c.active = 'settings'
c.group = c.repo_group = RepoGroupModel()._get_repo_group(group_name)
c.group_repos = c.group.repositories.all()
#overwrite our cached list with current filter
c.repo_cnt = 0
groups = RepoGroup.query().order_by(RepoGroup.group_name)\
.filter(RepoGroup.group_parent_id == c.group.group_id).all()
c.groups = self.scm_model.get_repo_groups(groups)
c.repos_list = Repository.query()\
.filter(Repository.group_id == c.group.group_id)\
.order_by(func.lower(Repository.repo_name))\
.all()
repos_data = RepoModel().get_repos_as_dict(repos_list=c.repos_list,
admin=False)
#json used to render the grid
c.data = json.dumps(repos_data)
return render('admin/repo_groups/repo_group_show.html')
示例10: update
def update(self, repo, **kwargs):
try:
cur_repo = self._get_repo(repo)
org_repo_name = cur_repo.repo_name
if 'user' in kwargs:
cur_repo.user = User.get_by_username(kwargs['user'])
if 'repo_group' in kwargs:
cur_repo.group = RepoGroup.get(kwargs['repo_group'])
log.debug('Updating repo %s with params:%s' % (cur_repo, kwargs))
for strip, k in [(1, 'repo_enable_downloads'),
(1, 'repo_description'),
(1, 'repo_enable_locking'),
(1, 'repo_landing_rev'),
(1, 'repo_private'),
(1, 'repo_enable_statistics'),
(0, 'clone_uri'),]:
if k in kwargs:
val = kwargs[k]
if strip:
k = remove_prefix(k, 'repo_')
if k == 'clone_uri':
from kallithea.model.validators import Missing
_change = kwargs.get('clone_uri_change')
if _change == Missing:
# we don't change the value, so use original one
val = cur_repo.clone_uri
setattr(cur_repo, k, val)
new_name = cur_repo.get_new_name(kwargs['repo_name'])
cur_repo.repo_name = new_name
#if private flag is set, reset default permission to NONE
if kwargs.get('repo_private'):
EMPTY_PERM = 'repository.none'
RepoModel().grant_user_permission(
repo=cur_repo, user='default', perm=EMPTY_PERM
)
#handle extra fields
for field in filter(lambda k: k.startswith(RepositoryField.PREFIX),
kwargs):
k = RepositoryField.un_prefix_key(field)
ex_field = RepositoryField.get_by_key_name(key=k, repo=cur_repo)
if ex_field:
ex_field.field_value = kwargs[field]
self.sa.add(ex_field)
self.sa.add(cur_repo)
if org_repo_name != new_name:
# rename repository
self._rename_filesystem_repo(old=org_repo_name, new=new_name)
return cur_repo
except Exception:
log.error(traceback.format_exc())
raise
示例11: __load_defaults
def __load_defaults(self, allow_empty_group=False, exclude_group_ids=[]):
if HasPermissionAll('hg.admin')('group edit'):
#we're global admin, we're ok and we can create TOP level groups
allow_empty_group = True
#override the choices for this form, we need to filter choices
#and display only those we have ADMIN right
groups_with_admin_rights = RepoGroupList(RepoGroup.query().all(),
perm_set=['group.admin'])
c.repo_groups = RepoGroup.groups_choices(groups=groups_with_admin_rights,
show_empty_group=allow_empty_group)
# 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)
repo_model = RepoModel()
c.users_array = repo_model.get_users_js()
c.user_groups_array = repo_model.get_user_groups_js()
示例12: __load_defaults
def __load_defaults(self, repo=None):
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)
# 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
# but it will allow saving repo data properly.
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))
c.repo_groups.append(RepoGroup._generate_choice(repo_group))
choices, c.landing_revs = ScmModel().get_repo_landing_revs()
c.landing_revs_choices = choices
示例13: show_by_name
def show_by_name(self, group_name):
"""
This is a proxy that does a lookup group_name -> id, and shows
the group by id view instead
"""
group_name = group_name.rstrip('/')
id_ = RepoGroup.get_by_group_name(group_name)
if id_:
return self.show(group_name)
raise HTTPNotFound
示例14: test_create_in_group
def test_create_in_group(self):
self.log_user()
## create GROUP
group_name = 'sometest_%s' % self.REPO_TYPE
gr = RepoGroupModel().create(group_name=group_name,
group_description='test',
owner=TEST_USER_ADMIN_LOGIN)
Session().commit()
repo_name = 'ingroup'
repo_name_full = RepoGroup.url_sep().join([group_name, repo_name])
description = 'description for newly created repo'
response = self.app.post(url('repos'),
fixture._get_repo_create_params(repo_private=False,
repo_name=repo_name,
repo_type=self.REPO_TYPE,
repo_description=description,
repo_group=gr.group_id,
_authentication_token=self.authentication_token()))
## run the check page that triggers the flash message
response = self.app.get(url('repo_check_home', repo_name=repo_name_full))
self.assertEqual(response.json, {u'result': True})
self.checkSessionFlash(response,
'Created repository <a href="/%s">%s</a>'
% (repo_name_full, repo_name_full))
# test if the repo was created in the database
new_repo = Session().query(Repository)\
.filter(Repository.repo_name == repo_name_full).one()
new_repo_id = new_repo.repo_id
self.assertEqual(new_repo.repo_name, repo_name_full)
self.assertEqual(new_repo.description, description)
# test if the repository is visible in the list ?
response = self.app.get(url('summary_home', repo_name=repo_name_full))
response.mustcontain(repo_name_full)
response.mustcontain(self.REPO_TYPE)
inherited_perms = UserRepoToPerm.query()\
.filter(UserRepoToPerm.repository_id == new_repo_id).all()
self.assertEqual(len(inherited_perms), 1)
# test if the repository was created on filesystem
try:
vcs.get_repo(os.path.join(TESTS_TMP_PATH, repo_name_full))
except vcs.exceptions.VCSError:
RepoGroupModel().delete(group_name)
Session().commit()
self.fail('no repo %s in filesystem' % repo_name)
RepoModel().delete(repo_name_full)
RepoGroupModel().delete(group_name)
Session().commit()
示例15: edit_repo_group_perms
def edit_repo_group_perms(self, group_name):
c.active = 'perms'
c.repo_group = RepoGroup.guess_instance(group_name)
self.__load_defaults()
defaults = self.__load_data(c.repo_group.group_id)
return htmlfill.render(
render('admin/repo_groups/repo_group_edit.html'),
defaults=defaults,
encoding="UTF-8",
force_defaults=False
)