Files
@ 8b7294a804a0
Branch filter:
Location: kallithea/rhodecode/tests/models/test_user_permissions_on_groups.py - annotation
8b7294a804a0
7.0 KiB
text/x-python
Update CONTRIBUTORS with new contributors from RhodeCode v2.2.5
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 | c0cc8f8a71b0 c0cc8f8a71b0 c0cc8f8a71b0 c0cc8f8a71b0 c0cc8f8a71b0 c0cc8f8a71b0 c0cc8f8a71b0 c0cc8f8a71b0 c0cc8f8a71b0 c0cc8f8a71b0 c0cc8f8a71b0 c0cc8f8a71b0 c0cc8f8a71b0 c0cc8f8a71b0 c0cc8f8a71b0 c0cc8f8a71b0 c0cc8f8a71b0 69377d1d7604 69377d1d7604 c0cc8f8a71b0 c0cc8f8a71b0 c0cc8f8a71b0 69377d1d7604 69377d1d7604 c0cc8f8a71b0 c0cc8f8a71b0 c0cc8f8a71b0 69377d1d7604 c0cc8f8a71b0 c0cc8f8a71b0 f5270697be3e f5270697be3e c0cc8f8a71b0 c0cc8f8a71b0 c0cc8f8a71b0 c0cc8f8a71b0 c0cc8f8a71b0 c0cc8f8a71b0 c0cc8f8a71b0 c0cc8f8a71b0 c0cc8f8a71b0 c0cc8f8a71b0 c0cc8f8a71b0 c0cc8f8a71b0 c0cc8f8a71b0 c0cc8f8a71b0 c0cc8f8a71b0 c0cc8f8a71b0 c0cc8f8a71b0 c0cc8f8a71b0 c0cc8f8a71b0 c0cc8f8a71b0 c0cc8f8a71b0 c0cc8f8a71b0 c0cc8f8a71b0 c0cc8f8a71b0 c0cc8f8a71b0 c0cc8f8a71b0 c0cc8f8a71b0 c0cc8f8a71b0 c0cc8f8a71b0 c0cc8f8a71b0 c0cc8f8a71b0 c0cc8f8a71b0 c0cc8f8a71b0 c0cc8f8a71b0 c0cc8f8a71b0 c0cc8f8a71b0 c0cc8f8a71b0 c0cc8f8a71b0 c0cc8f8a71b0 c0cc8f8a71b0 c0cc8f8a71b0 c0cc8f8a71b0 c0cc8f8a71b0 c0cc8f8a71b0 c0cc8f8a71b0 c0cc8f8a71b0 c0cc8f8a71b0 c0cc8f8a71b0 c0cc8f8a71b0 c0cc8f8a71b0 c0cc8f8a71b0 c0cc8f8a71b0 c0cc8f8a71b0 c0cc8f8a71b0 c0cc8f8a71b0 c0cc8f8a71b0 c0cc8f8a71b0 c0cc8f8a71b0 c0cc8f8a71b0 c0cc8f8a71b0 c0cc8f8a71b0 c0cc8f8a71b0 c0cc8f8a71b0 c0cc8f8a71b0 c0cc8f8a71b0 c0cc8f8a71b0 c0cc8f8a71b0 c0cc8f8a71b0 c0cc8f8a71b0 c0cc8f8a71b0 c0cc8f8a71b0 c0cc8f8a71b0 69377d1d7604 69377d1d7604 69377d1d7604 69377d1d7604 69377d1d7604 69377d1d7604 69377d1d7604 69377d1d7604 69377d1d7604 69377d1d7604 69377d1d7604 69377d1d7604 69377d1d7604 69377d1d7604 69377d1d7604 69377d1d7604 69377d1d7604 69377d1d7604 69377d1d7604 69377d1d7604 69377d1d7604 69377d1d7604 69377d1d7604 69377d1d7604 69377d1d7604 69377d1d7604 69377d1d7604 69377d1d7604 69377d1d7604 c0cc8f8a71b0 c0cc8f8a71b0 c0cc8f8a71b0 c0cc8f8a71b0 c0cc8f8a71b0 c0cc8f8a71b0 c0cc8f8a71b0 c0cc8f8a71b0 c0cc8f8a71b0 c0cc8f8a71b0 c0cc8f8a71b0 c0cc8f8a71b0 c0cc8f8a71b0 c0cc8f8a71b0 c0cc8f8a71b0 c0cc8f8a71b0 c0cc8f8a71b0 c0cc8f8a71b0 c0cc8f8a71b0 c0cc8f8a71b0 c0cc8f8a71b0 c0cc8f8a71b0 c0cc8f8a71b0 c0cc8f8a71b0 c0cc8f8a71b0 c0cc8f8a71b0 c0cc8f8a71b0 c0cc8f8a71b0 c0cc8f8a71b0 c0cc8f8a71b0 c0cc8f8a71b0 c0cc8f8a71b0 c0cc8f8a71b0 c0cc8f8a71b0 c0cc8f8a71b0 c0cc8f8a71b0 c0cc8f8a71b0 c0cc8f8a71b0 c0cc8f8a71b0 c0cc8f8a71b0 c0cc8f8a71b0 c0cc8f8a71b0 c0cc8f8a71b0 c0cc8f8a71b0 c0cc8f8a71b0 c0cc8f8a71b0 c0cc8f8a71b0 c0cc8f8a71b0 c0cc8f8a71b0 c0cc8f8a71b0 c0cc8f8a71b0 c0cc8f8a71b0 c0cc8f8a71b0 c0cc8f8a71b0 c0cc8f8a71b0 c0cc8f8a71b0 c0cc8f8a71b0 | import functools
from rhodecode.tests import *
from rhodecode.model.repos_group import ReposGroupModel
from rhodecode.model.db import RepoGroup, Repository, User
from rhodecode.model.meta import Session
from nose.tools import with_setup
from rhodecode.tests.models.common import _create_project_tree, check_tree_perms, \
_get_perms, _check_expected_count, expected_count, _destroy_project_tree
test_u1_id = None
_get_repo_perms = None
_get_group_perms = None
def permissions_setup_func(group_name='g0', perm='group.read', recursive=True,
user_id=None):
"""
Resets all permissions to perm attribute
"""
if not user_id:
user_id = test_u1_id
repos_group = RepoGroup.get_by_group_name(group_name=group_name)
if not repos_group:
raise Exception('Cannot get group %s' % group_name)
perms_updates = [[user_id, perm, 'user']]
ReposGroupModel()._update_permissions(repos_group,
perms_updates=perms_updates,
recursive=recursive,
check_perms=False)
Session().commit()
def setup_module():
global test_u1_id, _get_repo_perms, _get_group_perms
test_u1 = _create_project_tree()
Session().commit()
test_u1_id = test_u1.user_id
_get_repo_perms = functools.partial(_get_perms, key='repositories',
test_u1_id=test_u1_id)
_get_group_perms = functools.partial(_get_perms, key='repositories_groups',
test_u1_id=test_u1_id)
def teardown_module():
_destroy_project_tree(test_u1_id)
@with_setup(permissions_setup_func)
def test_user_permissions_on_group_without_recursive_mode():
# set permission to g0 non-recursive mode
recursive = False
group = 'g0'
permissions_setup_func(group, 'group.write', recursive=recursive)
items = [x for x in _get_repo_perms(group, recursive)]
expected = 0
assert len(items) == expected, ' %s != %s' % (len(items), expected)
for name, perm in items:
yield check_tree_perms, name, perm, group, 'repository.read'
items = [x for x in _get_group_perms(group, recursive)]
expected = 1
assert len(items) == expected, ' %s != %s' % (len(items), expected)
for name, perm in items:
yield check_tree_perms, name, perm, group, 'group.write'
@with_setup(permissions_setup_func)
def test_user_permissions_on_group_without_recursive_mode_subgroup():
# set permission to g0 non-recursive mode
recursive = False
group = 'g0/g0_1'
permissions_setup_func(group, 'group.write', recursive=recursive)
items = [x for x in _get_repo_perms(group, recursive)]
expected = 0
assert len(items) == expected, ' %s != %s' % (len(items), expected)
for name, perm in items:
yield check_tree_perms, name, perm, group, 'repository.read'
items = [x for x in _get_group_perms(group, recursive)]
expected = 1
assert len(items) == expected, ' %s != %s' % (len(items), expected)
for name, perm in items:
yield check_tree_perms, name, perm, group, 'group.write'
@with_setup(permissions_setup_func)
def test_user_permissions_on_group_with_recursive_mode():
# set permission to g0 recursive mode, all children including
# other repos and groups should have this permission now set !
recursive = True
group = 'g0'
permissions_setup_func(group, 'group.write', recursive=recursive)
repo_items = [x for x in _get_repo_perms(group, recursive)]
items = [x for x in _get_group_perms(group, recursive)]
_check_expected_count(items, repo_items, expected_count(group, True))
for name, perm in repo_items:
yield check_tree_perms, name, perm, group, 'repository.write'
for name, perm in items:
yield check_tree_perms, name, perm, group, 'group.write'
@with_setup(permissions_setup_func)
def test_user_permissions_on_group_with_recursive_mode_for_default_user():
# set permission to g0 recursive mode, all children including
# other repos and groups should have this permission now set !
recursive = True
group = 'g0'
default_user_id = User.get_default_user().user_id
permissions_setup_func(group, 'group.write', recursive=recursive,
user_id=default_user_id)
# change default to get perms for default user
_get_repo_perms = functools.partial(_get_perms, key='repositories',
test_u1_id=default_user_id)
_get_group_perms = functools.partial(_get_perms, key='repositories_groups',
test_u1_id=default_user_id)
repo_items = [x for x in _get_repo_perms(group, recursive)]
items = [x for x in _get_group_perms(group, recursive)]
_check_expected_count(items, repo_items, expected_count(group, True))
for name, perm in repo_items:
yield check_tree_perms, name, perm, group, 'repository.write'
for name, perm in items:
yield check_tree_perms, name, perm, group, 'group.write'
@with_setup(permissions_setup_func)
def test_user_permissions_on_group_with_recursive_mode_inner_group():
## set permission to g0_3 group to none
recursive = True
group = 'g0/g0_3'
permissions_setup_func(group, 'group.none', recursive=recursive)
repo_items = [x for x in _get_repo_perms(group, recursive)]
items = [x for x in _get_group_perms(group, recursive)]
_check_expected_count(items, repo_items, expected_count(group, True))
for name, perm in repo_items:
yield check_tree_perms, name, perm, group, 'repository.none'
for name, perm in items:
yield check_tree_perms, name, perm, group, 'group.none'
@with_setup(permissions_setup_func)
def test_user_permissions_on_group_with_recursive_mode_deepest():
## set permission to g0_3 group to none
recursive = True
group = 'g0/g0_1/g0_1_1'
permissions_setup_func(group, 'group.write', recursive=recursive)
repo_items = [x for x in _get_repo_perms(group, recursive)]
items = [x for x in _get_group_perms(group, recursive)]
_check_expected_count(items, repo_items, expected_count(group, True))
for name, perm in repo_items:
yield check_tree_perms, name, perm, group, 'repository.write'
for name, perm in items:
yield check_tree_perms, name, perm, group, 'group.write'
@with_setup(permissions_setup_func)
def test_user_permissions_on_group_with_recursive_mode_only_with_repos():
## set permission to g0_3 group to none
recursive = True
group = 'g0/g0_2'
permissions_setup_func(group, 'group.admin', recursive=recursive)
repo_items = [x for x in _get_repo_perms(group, recursive)]
items = [x for x in _get_group_perms(group, recursive)]
_check_expected_count(items, repo_items, expected_count(group, True))
for name, perm in repo_items:
yield check_tree_perms, name, perm, group, 'repository.admin'
for name, perm in items:
yield check_tree_perms, name, perm, group, 'group.admin'
|