Show More
@@ -1,164 +1,165 b'' | |||
|
1 | 1 | import os |
|
2 | 2 | import unittest |
|
3 | 3 | import functools |
|
4 | 4 | from rhodecode.tests import * |
|
5 | 5 | |
|
6 | 6 | from rhodecode.model.repos_group import ReposGroupModel |
|
7 | 7 | from rhodecode.model.db import RepoGroup, Repository, User |
|
8 | 8 | |
|
9 | 9 | from rhodecode.model.meta import Session |
|
10 | 10 | from nose.tools import with_setup |
|
11 | 11 | from rhodecode.tests.models.common import _create_project_tree, check_tree_perms, \ |
|
12 | 12 | _get_perms, _check_expected_count, expected_count, _destroy_project_tree |
|
13 | 13 | from rhodecode.model.repo import RepoModel |
|
14 | 14 | |
|
15 | 15 | |
|
16 | 16 | test_u1_id = None |
|
17 | 17 | _get_repo_perms = None |
|
18 | 18 | _get_group_perms = None |
|
19 | 19 | |
|
20 | 20 | |
|
21 | 21 | def permissions_setup_func(group_name='g0', perm='group.read', recursive=True): |
|
22 | 22 | """ |
|
23 | 23 | Resets all permissions to perm attribute |
|
24 | 24 | """ |
|
25 | 25 | repos_group = RepoGroup.get_by_group_name(group_name=group_name) |
|
26 | 26 | if not repos_group: |
|
27 | 27 | raise Exception('Cannot get group %s' % group_name) |
|
28 | 28 | perms_updates = [[test_u1_id, perm, 'user']] |
|
29 | 29 | ReposGroupModel()._update_permissions(repos_group, |
|
30 | 30 | perms_updates=perms_updates, |
|
31 |
recursive=recursive |
|
|
31 | recursive=recursive, | |
|
32 | check_perms=False) | |
|
32 | 33 | Session().commit() |
|
33 | 34 | |
|
34 | 35 | |
|
35 | 36 | def setup_module(): |
|
36 | 37 | global test_u1_id, _get_repo_perms, _get_group_perms |
|
37 | 38 | test_u1 = _create_project_tree() |
|
38 | 39 | Session().commit() |
|
39 | 40 | test_u1_id = test_u1.user_id |
|
40 | 41 | _get_repo_perms = functools.partial(_get_perms, key='repositories', |
|
41 | 42 | test_u1_id=test_u1_id) |
|
42 | 43 | _get_group_perms = functools.partial(_get_perms, key='repositories_groups', |
|
43 | 44 | test_u1_id=test_u1_id) |
|
44 | 45 | |
|
45 | 46 | |
|
46 | 47 | def teardown_module(): |
|
47 | 48 | _destroy_project_tree(test_u1_id) |
|
48 | 49 | |
|
49 | 50 | |
|
50 | 51 | @with_setup(permissions_setup_func) |
|
51 | 52 | def test_user_permissions_on_group_without_recursive_mode(): |
|
52 | 53 | # set permission to g0 non-recursive mode |
|
53 | 54 | recursive = False |
|
54 | 55 | group = 'g0' |
|
55 | 56 | permissions_setup_func(group, 'group.write', recursive=recursive) |
|
56 | 57 | |
|
57 | 58 | items = [x for x in _get_repo_perms(group, recursive)] |
|
58 | 59 | expected = 0 |
|
59 | 60 | assert len(items) == expected, ' %s != %s' % (len(items), expected) |
|
60 | 61 | for name, perm in items: |
|
61 | 62 | yield check_tree_perms, name, perm, group, 'repository.read' |
|
62 | 63 | |
|
63 | 64 | items = [x for x in _get_group_perms(group, recursive)] |
|
64 | 65 | expected = 1 |
|
65 | 66 | assert len(items) == expected, ' %s != %s' % (len(items), expected) |
|
66 | 67 | for name, perm in items: |
|
67 | 68 | yield check_tree_perms, name, perm, group, 'group.write' |
|
68 | 69 | |
|
69 | 70 | |
|
70 | 71 | @with_setup(permissions_setup_func) |
|
71 | 72 | def test_user_permissions_on_group_without_recursive_mode_subgroup(): |
|
72 | 73 | # set permission to g0 non-recursive mode |
|
73 | 74 | recursive = False |
|
74 | 75 | group = 'g0/g0_1' |
|
75 | 76 | permissions_setup_func(group, 'group.write', recursive=recursive) |
|
76 | 77 | |
|
77 | 78 | items = [x for x in _get_repo_perms(group, recursive)] |
|
78 | 79 | expected = 0 |
|
79 | 80 | assert len(items) == expected, ' %s != %s' % (len(items), expected) |
|
80 | 81 | for name, perm in items: |
|
81 | 82 | yield check_tree_perms, name, perm, group, 'repository.read' |
|
82 | 83 | |
|
83 | 84 | items = [x for x in _get_group_perms(group, recursive)] |
|
84 | 85 | expected = 1 |
|
85 | 86 | assert len(items) == expected, ' %s != %s' % (len(items), expected) |
|
86 | 87 | for name, perm in items: |
|
87 | 88 | yield check_tree_perms, name, perm, group, 'group.write' |
|
88 | 89 | |
|
89 | 90 | |
|
90 | 91 | @with_setup(permissions_setup_func) |
|
91 | 92 | def test_user_permissions_on_group_with_recursive_mode(): |
|
92 | 93 | |
|
93 | 94 | # set permission to g0 recursive mode, all children including |
|
94 | 95 | # other repos and groups should have this permission now set ! |
|
95 | 96 | recursive = True |
|
96 | 97 | group = 'g0' |
|
97 | 98 | permissions_setup_func(group, 'group.write', recursive=recursive) |
|
98 | 99 | |
|
99 | 100 | repo_items = [x for x in _get_repo_perms(group, recursive)] |
|
100 | 101 | items = [x for x in _get_group_perms(group, recursive)] |
|
101 | 102 | _check_expected_count(items, repo_items, expected_count(group, True)) |
|
102 | 103 | |
|
103 | 104 | for name, perm in repo_items: |
|
104 | 105 | if name == 'g0/g0_3/g0_3_r1_private': |
|
105 | 106 | yield check_tree_perms, name, perm, group, 'repository.none' |
|
106 | 107 | else: |
|
107 | 108 | yield check_tree_perms, name, perm, group, 'repository.write' |
|
108 | 109 | |
|
109 | 110 | for name, perm in items: |
|
110 | 111 | yield check_tree_perms, name, perm, group, 'group.write' |
|
111 | 112 | |
|
112 | 113 | |
|
113 | 114 | @with_setup(permissions_setup_func) |
|
114 | 115 | def test_user_permissions_on_group_with_recursive_mode_inner_group(): |
|
115 | 116 | ## set permission to g0_3 group to none |
|
116 | 117 | recursive = True |
|
117 | 118 | group = 'g0/g0_3' |
|
118 | 119 | permissions_setup_func(group, 'group.none', recursive=recursive) |
|
119 | 120 | |
|
120 | 121 | repo_items = [x for x in _get_repo_perms(group, recursive)] |
|
121 | 122 | items = [x for x in _get_group_perms(group, recursive)] |
|
122 | 123 | _check_expected_count(items, repo_items, expected_count(group, True)) |
|
123 | 124 | |
|
124 | 125 | for name, perm in repo_items: |
|
125 | 126 | yield check_tree_perms, name, perm, group, 'repository.none' |
|
126 | 127 | |
|
127 | 128 | for name, perm in items: |
|
128 | 129 | yield check_tree_perms, name, perm, group, 'group.none' |
|
129 | 130 | |
|
130 | 131 | |
|
131 | 132 | @with_setup(permissions_setup_func) |
|
132 | 133 | def test_user_permissions_on_group_with_recursive_mode_deepest(): |
|
133 | 134 | ## set permission to g0_3 group to none |
|
134 | 135 | recursive = True |
|
135 | 136 | group = 'g0/g0_1/g0_1_1' |
|
136 | 137 | permissions_setup_func(group, 'group.write', recursive=recursive) |
|
137 | 138 | |
|
138 | 139 | repo_items = [x for x in _get_repo_perms(group, recursive)] |
|
139 | 140 | items = [x for x in _get_group_perms(group, recursive)] |
|
140 | 141 | _check_expected_count(items, repo_items, expected_count(group, True)) |
|
141 | 142 | |
|
142 | 143 | for name, perm in repo_items: |
|
143 | 144 | yield check_tree_perms, name, perm, group, 'repository.write' |
|
144 | 145 | |
|
145 | 146 | for name, perm in items: |
|
146 | 147 | yield check_tree_perms, name, perm, group, 'group.write' |
|
147 | 148 | |
|
148 | 149 | |
|
149 | 150 | @with_setup(permissions_setup_func) |
|
150 | 151 | def test_user_permissions_on_group_with_recursive_mode_only_with_repos(): |
|
151 | 152 | ## set permission to g0_3 group to none |
|
152 | 153 | recursive = True |
|
153 | 154 | group = 'g0/g0_2' |
|
154 | 155 | permissions_setup_func(group, 'group.admin', recursive=recursive) |
|
155 | 156 | |
|
156 | 157 | repo_items = [x for x in _get_repo_perms(group, recursive)] |
|
157 | 158 | items = [x for x in _get_group_perms(group, recursive)] |
|
158 | 159 | _check_expected_count(items, repo_items, expected_count(group, True)) |
|
159 | 160 | |
|
160 | 161 | for name, perm in repo_items: |
|
161 | 162 | yield check_tree_perms, name, perm, group, 'repository.admin' |
|
162 | 163 | |
|
163 | 164 | for name, perm in items: |
|
164 | 165 | yield check_tree_perms, name, perm, group, 'group.admin' |
@@ -1,171 +1,172 b'' | |||
|
1 | 1 | import os |
|
2 | 2 | import unittest |
|
3 | 3 | import functools |
|
4 | 4 | from rhodecode.tests import * |
|
5 | 5 | |
|
6 | 6 | from rhodecode.model.repos_group import ReposGroupModel |
|
7 | 7 | from rhodecode.model.db import RepoGroup |
|
8 | 8 | |
|
9 | 9 | from rhodecode.model.meta import Session |
|
10 | 10 | from nose.tools import with_setup |
|
11 | 11 | from rhodecode.tests.models.common import _create_project_tree, check_tree_perms, \ |
|
12 | 12 | _get_perms, _check_expected_count, expected_count, _destroy_project_tree |
|
13 | 13 | from rhodecode.model.users_group import UserGroupModel |
|
14 | 14 | from rhodecode.tests.fixture import Fixture |
|
15 | 15 | |
|
16 | 16 | fixture = Fixture() |
|
17 | 17 | |
|
18 | 18 | test_u2_id = None |
|
19 | 19 | test_u2_gr_id = None |
|
20 | 20 | _get_repo_perms = None |
|
21 | 21 | _get_group_perms = None |
|
22 | 22 | |
|
23 | 23 | |
|
24 | 24 | def permissions_setup_func(group_name='g0', perm='group.read', recursive=True): |
|
25 | 25 | """ |
|
26 | 26 | Resets all permissions to perm attribute |
|
27 | 27 | """ |
|
28 | 28 | repos_group = RepoGroup.get_by_group_name(group_name=group_name) |
|
29 | 29 | if not repos_group: |
|
30 | 30 | raise Exception('Cannot get group %s' % group_name) |
|
31 | 31 | perms_updates = [[test_u2_gr_id, perm, 'users_group']] |
|
32 | 32 | ReposGroupModel()._update_permissions(repos_group, |
|
33 | 33 | perms_updates=perms_updates, |
|
34 |
recursive=recursive |
|
|
34 | recursive=recursive, | |
|
35 | check_perms=False) | |
|
35 | 36 | Session().commit() |
|
36 | 37 | |
|
37 | 38 | |
|
38 | 39 | def setup_module(): |
|
39 | 40 | global test_u2_id, test_u2_gr_id, _get_repo_perms, _get_group_perms |
|
40 | 41 | test_u2 = _create_project_tree() |
|
41 | 42 | Session().commit() |
|
42 | 43 | test_u2_id = test_u2.user_id |
|
43 | 44 | |
|
44 | 45 | gr1 = fixture.create_user_group('perms_group_1') |
|
45 | 46 | Session().commit() |
|
46 | 47 | test_u2_gr_id = gr1.users_group_id |
|
47 | 48 | UserGroupModel().add_user_to_group(gr1, user=test_u2_id) |
|
48 | 49 | Session().commit() |
|
49 | 50 | |
|
50 | 51 | _get_repo_perms = functools.partial(_get_perms, key='repositories', |
|
51 | 52 | test_u1_id=test_u2_id) |
|
52 | 53 | _get_group_perms = functools.partial(_get_perms, key='repositories_groups', |
|
53 | 54 | test_u1_id=test_u2_id) |
|
54 | 55 | |
|
55 | 56 | |
|
56 | 57 | def teardown_module(): |
|
57 | 58 | _destroy_project_tree(test_u2_id) |
|
58 | 59 | |
|
59 | 60 | |
|
60 | 61 | @with_setup(permissions_setup_func) |
|
61 | 62 | def test_user_permissions_on_group_without_recursive_mode(): |
|
62 | 63 | # set permission to g0 non-recursive mode |
|
63 | 64 | recursive = False |
|
64 | 65 | group = 'g0' |
|
65 | 66 | permissions_setup_func(group, 'group.write', recursive=recursive) |
|
66 | 67 | |
|
67 | 68 | items = [x for x in _get_repo_perms(group, recursive)] |
|
68 | 69 | expected = 0 |
|
69 | 70 | assert len(items) == expected, ' %s != %s' % (len(items), expected) |
|
70 | 71 | for name, perm in items: |
|
71 | 72 | yield check_tree_perms, name, perm, group, 'repository.read' |
|
72 | 73 | |
|
73 | 74 | items = [x for x in _get_group_perms(group, recursive)] |
|
74 | 75 | expected = 1 |
|
75 | 76 | assert len(items) == expected, ' %s != %s' % (len(items), expected) |
|
76 | 77 | for name, perm in items: |
|
77 | 78 | yield check_tree_perms, name, perm, group, 'group.write' |
|
78 | 79 | |
|
79 | 80 | |
|
80 | 81 | @with_setup(permissions_setup_func) |
|
81 | 82 | def test_user_permissions_on_group_without_recursive_mode_subgroup(): |
|
82 | 83 | # set permission to g0 non-recursive mode |
|
83 | 84 | recursive = False |
|
84 | 85 | group = 'g0/g0_1' |
|
85 | 86 | permissions_setup_func(group, 'group.write', recursive=recursive) |
|
86 | 87 | |
|
87 | 88 | items = [x for x in _get_repo_perms(group, recursive)] |
|
88 | 89 | expected = 0 |
|
89 | 90 | assert len(items) == expected, ' %s != %s' % (len(items), expected) |
|
90 | 91 | for name, perm in items: |
|
91 | 92 | yield check_tree_perms, name, perm, group, 'repository.read' |
|
92 | 93 | |
|
93 | 94 | items = [x for x in _get_group_perms(group, recursive)] |
|
94 | 95 | expected = 1 |
|
95 | 96 | assert len(items) == expected, ' %s != %s' % (len(items), expected) |
|
96 | 97 | for name, perm in items: |
|
97 | 98 | yield check_tree_perms, name, perm, group, 'group.write' |
|
98 | 99 | |
|
99 | 100 | |
|
100 | 101 | @with_setup(permissions_setup_func) |
|
101 | 102 | def test_user_permissions_on_group_with_recursive_mode(): |
|
102 | 103 | |
|
103 | 104 | # set permission to g0 recursive mode, all children including |
|
104 | 105 | # other repos and groups should have this permission now set ! |
|
105 | 106 | recursive = True |
|
106 | 107 | group = 'g0' |
|
107 | 108 | permissions_setup_func(group, 'group.write', recursive=recursive) |
|
108 | 109 | |
|
109 | 110 | repo_items = [x for x in _get_repo_perms(group, recursive)] |
|
110 | 111 | items = [x for x in _get_group_perms(group, recursive)] |
|
111 | 112 | _check_expected_count(items, repo_items, expected_count(group, True)) |
|
112 | 113 | |
|
113 | 114 | for name, perm in repo_items: |
|
114 | 115 | yield check_tree_perms, name, perm, group, 'repository.write' |
|
115 | 116 | |
|
116 | 117 | for name, perm in items: |
|
117 | 118 | yield check_tree_perms, name, perm, group, 'group.write' |
|
118 | 119 | |
|
119 | 120 | |
|
120 | 121 | @with_setup(permissions_setup_func) |
|
121 | 122 | def test_user_permissions_on_group_with_recursive_mode_inner_group(): |
|
122 | 123 | ## set permission to g0_3 group to none |
|
123 | 124 | recursive = True |
|
124 | 125 | group = 'g0/g0_3' |
|
125 | 126 | permissions_setup_func(group, 'group.none', recursive=recursive) |
|
126 | 127 | |
|
127 | 128 | repo_items = [x for x in _get_repo_perms(group, recursive)] |
|
128 | 129 | items = [x for x in _get_group_perms(group, recursive)] |
|
129 | 130 | _check_expected_count(items, repo_items, expected_count(group, True)) |
|
130 | 131 | |
|
131 | 132 | for name, perm in repo_items: |
|
132 | 133 | yield check_tree_perms, name, perm, group, 'repository.none' |
|
133 | 134 | |
|
134 | 135 | for name, perm in items: |
|
135 | 136 | yield check_tree_perms, name, perm, group, 'group.none' |
|
136 | 137 | |
|
137 | 138 | |
|
138 | 139 | @with_setup(permissions_setup_func) |
|
139 | 140 | def test_user_permissions_on_group_with_recursive_mode_deepest(): |
|
140 | 141 | ## set permission to g0_3 group to none |
|
141 | 142 | recursive = True |
|
142 | 143 | group = 'g0/g0_1/g0_1_1' |
|
143 | 144 | permissions_setup_func(group, 'group.write', recursive=recursive) |
|
144 | 145 | |
|
145 | 146 | repo_items = [x for x in _get_repo_perms(group, recursive)] |
|
146 | 147 | items = [x for x in _get_group_perms(group, recursive)] |
|
147 | 148 | _check_expected_count(items, repo_items, expected_count(group, True)) |
|
148 | 149 | |
|
149 | 150 | for name, perm in repo_items: |
|
150 | 151 | yield check_tree_perms, name, perm, group, 'repository.write' |
|
151 | 152 | |
|
152 | 153 | for name, perm in items: |
|
153 | 154 | yield check_tree_perms, name, perm, group, 'group.write' |
|
154 | 155 | |
|
155 | 156 | |
|
156 | 157 | @with_setup(permissions_setup_func) |
|
157 | 158 | def test_user_permissions_on_group_with_recursive_mode_only_with_repos(): |
|
158 | 159 | ## set permission to g0_3 group to none |
|
159 | 160 | recursive = True |
|
160 | 161 | group = 'g0/g0_2' |
|
161 | 162 | permissions_setup_func(group, 'group.admin', recursive=recursive) |
|
162 | 163 | |
|
163 | 164 | repo_items = [x for x in _get_repo_perms(group, recursive)] |
|
164 | 165 | items = [x for x in _get_group_perms(group, recursive)] |
|
165 | 166 | _check_expected_count(items, repo_items, expected_count(group, True)) |
|
166 | 167 | |
|
167 | 168 | for name, perm in repo_items: |
|
168 | 169 | yield check_tree_perms, name, perm, group, 'repository.admin' |
|
169 | 170 | |
|
170 | 171 | for name, perm in items: |
|
171 | 172 | yield check_tree_perms, name, perm, group, 'group.admin' |
General Comments 0
You need to be logged in to leave comments.
Login now