Show More
@@ -46,10 +46,10 b' def route_path(name, params=None, **kwar' | |||||
46 |
|
46 | |||
47 | class TestAdminMainView(TestController): |
|
47 | class TestAdminMainView(TestController): | |
48 |
|
48 | |||
49 |
def test_ |
|
49 | def test_access_admin_home(self): | |
50 | self.log_user() |
|
50 | self.log_user() | |
51 |
response = self.app.get(route_path('admin_home'), status= |
|
51 | response = self.app.get(route_path('admin_home'), status=200) | |
52 | assert response.location.endswith('/audit_logs') |
|
52 | response.mustcontain("Administration area") | |
53 |
|
53 | |||
54 | def test_redirect_pull_request_view(self, view): |
|
54 | def test_redirect_pull_request_view(self, view): | |
55 | self.log_user() |
|
55 | self.log_user() |
@@ -30,6 +30,7 b' def route_path(name, params=None, **kwar' | |||||
30 |
|
30 | |||
31 | base_url = { |
|
31 | base_url = { | |
32 | 'home': '/', |
|
32 | 'home': '/', | |
|
33 | 'admin_home': ADMIN_PREFIX, | |||
33 | 'repos': |
|
34 | 'repos': | |
34 | ADMIN_PREFIX + '/repos', |
|
35 | ADMIN_PREFIX + '/repos', | |
35 | 'repo_groups': |
|
36 | 'repo_groups': | |
@@ -50,19 +51,14 b' fixture = Fixture()' | |||||
50 |
|
51 | |||
51 | class TestAdminDelegatedUser(TestController): |
|
52 | class TestAdminDelegatedUser(TestController): | |
52 |
|
53 | |||
53 | def test_regular_user_cannot_see_admin_interfaces( |
|
54 | def test_regular_user_cannot_see_admin_interfaces(self, user_util, xhr_header): | |
54 | self, user_util, xhr_header): |
|
|||
55 | user = user_util.create_user(password='qweqwe') |
|
55 | user = user_util.create_user(password='qweqwe') | |
|
56 | user_util.inherit_default_user_permissions(user.username, False) | |||
|
57 | ||||
56 | self.log_user(user.username, 'qweqwe') |
|
58 | self.log_user(user.username, 'qweqwe') | |
57 |
|
59 | |||
58 | # check if in home view, such user doesn't see the "admin" menus |
|
60 | # user doesn't have any access to resources so main admin page should 404 | |
59 |
|
|
61 | self.app.get(route_path('admin_home'), status=404) | |
60 |
|
||||
61 | assert_response = response.assert_response() |
|
|||
62 |
|
||||
63 | assert_response.no_element_exists('li.local-admin-repos') |
|
|||
64 | assert_response.no_element_exists('li.local-admin-repo-groups') |
|
|||
65 | assert_response.no_element_exists('li.local-admin-user-groups') |
|
|||
66 |
|
62 | |||
67 | response = self.app.get(route_path('repos'), status=200) |
|
63 | response = self.app.get(route_path('repos'), status=200) | |
68 | response.mustcontain('data: []') |
|
64 | response.mustcontain('data: []') | |
@@ -74,8 +70,7 b' class TestAdminDelegatedUser(TestControl' | |||||
74 | status=200, extra_environ=xhr_header) |
|
70 | status=200, extra_environ=xhr_header) | |
75 | assert response.json['data'] == [] |
|
71 | assert response.json['data'] == [] | |
76 |
|
72 | |||
77 | def test_regular_user_can_see_admin_interfaces_if_owner( |
|
73 | def test_regular_user_can_see_admin_interfaces_if_owner(self, user_util, xhr_header): | |
78 | self, user_util, xhr_header): |
|
|||
79 | user = user_util.create_user(password='qweqwe') |
|
74 | user = user_util.create_user(password='qweqwe') | |
80 | username = user.username |
|
75 | username = user.username | |
81 |
|
76 | |||
@@ -89,14 +84,14 b' class TestAdminDelegatedUser(TestControl' | |||||
89 | user_group_name = user_group.users_group_name |
|
84 | user_group_name = user_group.users_group_name | |
90 |
|
85 | |||
91 | self.log_user(username, 'qweqwe') |
|
86 | self.log_user(username, 'qweqwe') | |
92 | # check if in home view, such user doesn't see the "admin" menus |
|
87 | ||
93 | response = self.app.get(route_path('home')) |
|
88 | response = self.app.get(route_path('admin_home')) | |
94 |
|
89 | |||
95 | assert_response = response.assert_response() |
|
90 | assert_response = response.assert_response() | |
96 |
|
91 | |||
97 |
assert_response. |
|
92 | assert_response.element_contains('td.delegated-admin-repos', '1') | |
98 |
assert_response. |
|
93 | assert_response.element_contains('td.delegated-admin-repo-groups', '1') | |
99 |
assert_response. |
|
94 | assert_response.element_contains('td.delegated-admin-user-groups', '1') | |
100 |
|
95 | |||
101 | # admin interfaces have visible elements |
|
96 | # admin interfaces have visible elements | |
102 | response = self.app.get(route_path('repos'), status=200) |
|
97 | response = self.app.get(route_path('repos'), status=200) | |
@@ -132,13 +127,13 b' class TestAdminDelegatedUser(TestControl' | |||||
132 |
|
127 | |||
133 | self.log_user(username, 'qweqwe') |
|
128 | self.log_user(username, 'qweqwe') | |
134 | # check if in home view, such user doesn't see the "admin" menus |
|
129 | # check if in home view, such user doesn't see the "admin" menus | |
135 | response = self.app.get(route_path('home')) |
|
130 | response = self.app.get(route_path('admin_home')) | |
136 |
|
131 | |||
137 | assert_response = response.assert_response() |
|
132 | assert_response = response.assert_response() | |
138 |
|
133 | |||
139 |
assert_response. |
|
134 | assert_response.element_contains('td.delegated-admin-repos', '1') | |
140 |
assert_response. |
|
135 | assert_response.element_contains('td.delegated-admin-repo-groups', '1') | |
141 |
assert_response. |
|
136 | assert_response.element_contains('td.delegated-admin-user-groups', '1') | |
142 |
|
137 | |||
143 | # admin interfaces have visible elements |
|
138 | # admin interfaces have visible elements | |
144 | response = self.app.get(route_path('repos'), status=200) |
|
139 | response = self.app.get(route_path('repos'), status=200) |
@@ -1224,7 +1224,7 b' class UserUtility(object):' | |||||
1224 | return user_group |
|
1224 | return user_group | |
1225 |
|
1225 | |||
1226 | def grant_user_permission(self, user_name, permission_name): |
|
1226 | def grant_user_permission(self, user_name, permission_name): | |
1227 |
self. |
|
1227 | self.inherit_default_user_permissions(user_name, False) | |
1228 | self.user_permissions.append((user_name, permission_name)) |
|
1228 | self.user_permissions.append((user_name, permission_name)) | |
1229 |
|
1229 | |||
1230 | def grant_user_permission_to_repo_group( |
|
1230 | def grant_user_permission_to_repo_group( | |
@@ -1276,10 +1276,10 b' class UserUtility(object):' | |||||
1276 | return permission |
|
1276 | return permission | |
1277 |
|
1277 | |||
1278 | def revoke_user_permission(self, user_name, permission_name): |
|
1278 | def revoke_user_permission(self, user_name, permission_name): | |
1279 |
self. |
|
1279 | self.inherit_default_user_permissions(user_name, True) | |
1280 | UserModel().revoke_perm(user_name, permission_name) |
|
1280 | UserModel().revoke_perm(user_name, permission_name) | |
1281 |
|
1281 | |||
1282 |
def |
|
1282 | def inherit_default_user_permissions(self, user_name, value): | |
1283 | user = UserModel().get_by_username(user_name) |
|
1283 | user = UserModel().get_by_username(user_name) | |
1284 | user.inherit_default_permissions = value |
|
1284 | user.inherit_default_permissions = value | |
1285 | Session().add(user) |
|
1285 | Session().add(user) |
General Comments 0
You need to be logged in to leave comments.
Login now