Show More
@@ -1,325 +1,322 b'' | |||||
1 | # -*- coding: utf-8 -*- |
|
1 | # -*- coding: utf-8 -*- | |
2 |
|
2 | |||
3 | # Copyright (C) 2016-2017 RhodeCode GmbH |
|
3 | # Copyright (C) 2016-2017 RhodeCode GmbH | |
4 | # |
|
4 | # | |
5 | # This program is free software: you can redistribute it and/or modify |
|
5 | # This program is free software: you can redistribute it and/or modify | |
6 | # it under the terms of the GNU Affero General Public License, version 3 |
|
6 | # it under the terms of the GNU Affero General Public License, version 3 | |
7 | # (only), as published by the Free Software Foundation. |
|
7 | # (only), as published by the Free Software Foundation. | |
8 | # |
|
8 | # | |
9 | # This program is distributed in the hope that it will be useful, |
|
9 | # This program is distributed in the hope that it will be useful, | |
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | # GNU General Public License for more details. |
|
12 | # GNU General Public License for more details. | |
13 | # |
|
13 | # | |
14 | # You should have received a copy of the GNU Affero General Public License |
|
14 | # You should have received a copy of the GNU Affero General Public License | |
15 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
15 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | |
16 | # |
|
16 | # | |
17 | # This program is dual-licensed. If you wish to learn more about the |
|
17 | # This program is dual-licensed. If you wish to learn more about the | |
18 | # RhodeCode Enterprise Edition, including its added features, Support services, |
|
18 | # RhodeCode Enterprise Edition, including its added features, Support services, | |
19 | # and proprietary license terms, please see https://rhodecode.com/licenses/ |
|
19 | # and proprietary license terms, please see https://rhodecode.com/licenses/ | |
20 |
|
20 | |||
21 |
|
21 | |||
22 | from rhodecode.apps.admin.navigation import NavigationRegistry |
|
|||
23 | from rhodecode.apps._base import ADMIN_PREFIX |
|
22 | from rhodecode.apps._base import ADMIN_PREFIX | |
24 | from rhodecode.lib.utils2 import str2bool |
|
23 | from rhodecode.lib.utils2 import str2bool | |
25 |
|
24 | |||
26 |
|
25 | |||
27 | def admin_routes(config): |
|
26 | def admin_routes(config): | |
28 | """ |
|
27 | """ | |
29 | Admin prefixed routes |
|
28 | Admin prefixed routes | |
30 | """ |
|
29 | """ | |
31 |
|
30 | |||
32 | config.add_route( |
|
31 | config.add_route( | |
33 | name='admin_audit_logs', |
|
32 | name='admin_audit_logs', | |
34 | pattern='/audit_logs') |
|
33 | pattern='/audit_logs') | |
35 |
|
34 | |||
36 | config.add_route( |
|
35 | config.add_route( | |
37 | name='admin_audit_log_entry', |
|
36 | name='admin_audit_log_entry', | |
38 | pattern='/audit_logs/{audit_log_id}') |
|
37 | pattern='/audit_logs/{audit_log_id}') | |
39 |
|
38 | |||
40 | config.add_route( |
|
39 | config.add_route( | |
41 | name='pull_requests_global_0', # backward compat |
|
40 | name='pull_requests_global_0', # backward compat | |
42 | pattern='/pull_requests/{pull_request_id:\d+}') |
|
41 | pattern='/pull_requests/{pull_request_id:\d+}') | |
43 | config.add_route( |
|
42 | config.add_route( | |
44 | name='pull_requests_global_1', # backward compat |
|
43 | name='pull_requests_global_1', # backward compat | |
45 | pattern='/pull-requests/{pull_request_id:\d+}') |
|
44 | pattern='/pull-requests/{pull_request_id:\d+}') | |
46 | config.add_route( |
|
45 | config.add_route( | |
47 | name='pull_requests_global', |
|
46 | name='pull_requests_global', | |
48 | pattern='/pull-request/{pull_request_id:\d+}') |
|
47 | pattern='/pull-request/{pull_request_id:\d+}') | |
49 |
|
48 | |||
50 | config.add_route( |
|
49 | config.add_route( | |
51 | name='admin_settings_open_source', |
|
50 | name='admin_settings_open_source', | |
52 | pattern='/settings/open_source') |
|
51 | pattern='/settings/open_source') | |
53 | config.add_route( |
|
52 | config.add_route( | |
54 | name='admin_settings_vcs_svn_generate_cfg', |
|
53 | name='admin_settings_vcs_svn_generate_cfg', | |
55 | pattern='/settings/vcs/svn_generate_cfg') |
|
54 | pattern='/settings/vcs/svn_generate_cfg') | |
56 |
|
55 | |||
57 | config.add_route( |
|
56 | config.add_route( | |
58 | name='admin_settings_system', |
|
57 | name='admin_settings_system', | |
59 | pattern='/settings/system') |
|
58 | pattern='/settings/system') | |
60 | config.add_route( |
|
59 | config.add_route( | |
61 | name='admin_settings_system_update', |
|
60 | name='admin_settings_system_update', | |
62 | pattern='/settings/system/updates') |
|
61 | pattern='/settings/system/updates') | |
63 |
|
62 | |||
64 | config.add_route( |
|
63 | config.add_route( | |
65 | name='admin_settings_sessions', |
|
64 | name='admin_settings_sessions', | |
66 | pattern='/settings/sessions') |
|
65 | pattern='/settings/sessions') | |
67 | config.add_route( |
|
66 | config.add_route( | |
68 | name='admin_settings_sessions_cleanup', |
|
67 | name='admin_settings_sessions_cleanup', | |
69 | pattern='/settings/sessions/cleanup') |
|
68 | pattern='/settings/sessions/cleanup') | |
70 |
|
69 | |||
71 | config.add_route( |
|
70 | config.add_route( | |
72 | name='admin_settings_process_management', |
|
71 | name='admin_settings_process_management', | |
73 | pattern='/settings/process_management') |
|
72 | pattern='/settings/process_management') | |
74 | config.add_route( |
|
73 | config.add_route( | |
75 | name='admin_settings_process_management_signal', |
|
74 | name='admin_settings_process_management_signal', | |
76 | pattern='/settings/process_management/signal') |
|
75 | pattern='/settings/process_management/signal') | |
77 |
|
76 | |||
78 | # default settings |
|
77 | # default settings | |
79 | config.add_route( |
|
78 | config.add_route( | |
80 | name='admin_defaults_repositories', |
|
79 | name='admin_defaults_repositories', | |
81 | pattern='/defaults/repositories') |
|
80 | pattern='/defaults/repositories') | |
82 | config.add_route( |
|
81 | config.add_route( | |
83 | name='admin_defaults_repositories_update', |
|
82 | name='admin_defaults_repositories_update', | |
84 | pattern='/defaults/repositories/update') |
|
83 | pattern='/defaults/repositories/update') | |
85 |
|
84 | |||
86 | # global permissions |
|
85 | # global permissions | |
87 |
|
86 | |||
88 | config.add_route( |
|
87 | config.add_route( | |
89 | name='admin_permissions_application', |
|
88 | name='admin_permissions_application', | |
90 | pattern='/permissions/application') |
|
89 | pattern='/permissions/application') | |
91 | config.add_route( |
|
90 | config.add_route( | |
92 | name='admin_permissions_application_update', |
|
91 | name='admin_permissions_application_update', | |
93 | pattern='/permissions/application/update') |
|
92 | pattern='/permissions/application/update') | |
94 |
|
93 | |||
95 | config.add_route( |
|
94 | config.add_route( | |
96 | name='admin_permissions_global', |
|
95 | name='admin_permissions_global', | |
97 | pattern='/permissions/global') |
|
96 | pattern='/permissions/global') | |
98 | config.add_route( |
|
97 | config.add_route( | |
99 | name='admin_permissions_global_update', |
|
98 | name='admin_permissions_global_update', | |
100 | pattern='/permissions/global/update') |
|
99 | pattern='/permissions/global/update') | |
101 |
|
100 | |||
102 | config.add_route( |
|
101 | config.add_route( | |
103 | name='admin_permissions_object', |
|
102 | name='admin_permissions_object', | |
104 | pattern='/permissions/object') |
|
103 | pattern='/permissions/object') | |
105 | config.add_route( |
|
104 | config.add_route( | |
106 | name='admin_permissions_object_update', |
|
105 | name='admin_permissions_object_update', | |
107 | pattern='/permissions/object/update') |
|
106 | pattern='/permissions/object/update') | |
108 |
|
107 | |||
109 | config.add_route( |
|
108 | config.add_route( | |
110 | name='admin_permissions_ips', |
|
109 | name='admin_permissions_ips', | |
111 | pattern='/permissions/ips') |
|
110 | pattern='/permissions/ips') | |
112 |
|
111 | |||
113 | config.add_route( |
|
112 | config.add_route( | |
114 | name='admin_permissions_overview', |
|
113 | name='admin_permissions_overview', | |
115 | pattern='/permissions/overview') |
|
114 | pattern='/permissions/overview') | |
116 |
|
115 | |||
117 | config.add_route( |
|
116 | config.add_route( | |
118 | name='admin_permissions_auth_token_access', |
|
117 | name='admin_permissions_auth_token_access', | |
119 | pattern='/permissions/auth_token_access') |
|
118 | pattern='/permissions/auth_token_access') | |
120 |
|
119 | |||
121 | config.add_route( |
|
120 | config.add_route( | |
122 | name='admin_permissions_ssh_keys', |
|
121 | name='admin_permissions_ssh_keys', | |
123 | pattern='/permissions/ssh_keys') |
|
122 | pattern='/permissions/ssh_keys') | |
124 | config.add_route( |
|
123 | config.add_route( | |
125 | name='admin_permissions_ssh_keys_data', |
|
124 | name='admin_permissions_ssh_keys_data', | |
126 | pattern='/permissions/ssh_keys/data') |
|
125 | pattern='/permissions/ssh_keys/data') | |
127 | config.add_route( |
|
126 | config.add_route( | |
128 | name='admin_permissions_ssh_keys_update', |
|
127 | name='admin_permissions_ssh_keys_update', | |
129 | pattern='/permissions/ssh_keys/update') |
|
128 | pattern='/permissions/ssh_keys/update') | |
130 |
|
129 | |||
131 | # users admin |
|
130 | # users admin | |
132 | config.add_route( |
|
131 | config.add_route( | |
133 | name='users', |
|
132 | name='users', | |
134 | pattern='/users') |
|
133 | pattern='/users') | |
135 |
|
134 | |||
136 | config.add_route( |
|
135 | config.add_route( | |
137 | name='users_data', |
|
136 | name='users_data', | |
138 | pattern='/users_data') |
|
137 | pattern='/users_data') | |
139 |
|
138 | |||
140 | config.add_route( |
|
139 | config.add_route( | |
141 | name='users_create', |
|
140 | name='users_create', | |
142 | pattern='/users/create') |
|
141 | pattern='/users/create') | |
143 |
|
142 | |||
144 | config.add_route( |
|
143 | config.add_route( | |
145 | name='users_new', |
|
144 | name='users_new', | |
146 | pattern='/users/new') |
|
145 | pattern='/users/new') | |
147 |
|
146 | |||
148 | # user management |
|
147 | # user management | |
149 | config.add_route( |
|
148 | config.add_route( | |
150 | name='user_edit', |
|
149 | name='user_edit', | |
151 | pattern='/users/{user_id:\d+}/edit', |
|
150 | pattern='/users/{user_id:\d+}/edit', | |
152 | user_route=True) |
|
151 | user_route=True) | |
153 | config.add_route( |
|
152 | config.add_route( | |
154 | name='user_edit_advanced', |
|
153 | name='user_edit_advanced', | |
155 | pattern='/users/{user_id:\d+}/edit/advanced', |
|
154 | pattern='/users/{user_id:\d+}/edit/advanced', | |
156 | user_route=True) |
|
155 | user_route=True) | |
157 | config.add_route( |
|
156 | config.add_route( | |
158 | name='user_edit_global_perms', |
|
157 | name='user_edit_global_perms', | |
159 | pattern='/users/{user_id:\d+}/edit/global_permissions', |
|
158 | pattern='/users/{user_id:\d+}/edit/global_permissions', | |
160 | user_route=True) |
|
159 | user_route=True) | |
161 | config.add_route( |
|
160 | config.add_route( | |
162 | name='user_edit_global_perms_update', |
|
161 | name='user_edit_global_perms_update', | |
163 | pattern='/users/{user_id:\d+}/edit/global_permissions/update', |
|
162 | pattern='/users/{user_id:\d+}/edit/global_permissions/update', | |
164 | user_route=True) |
|
163 | user_route=True) | |
165 | config.add_route( |
|
164 | config.add_route( | |
166 | name='user_update', |
|
165 | name='user_update', | |
167 | pattern='/users/{user_id:\d+}/update', |
|
166 | pattern='/users/{user_id:\d+}/update', | |
168 | user_route=True) |
|
167 | user_route=True) | |
169 | config.add_route( |
|
168 | config.add_route( | |
170 | name='user_delete', |
|
169 | name='user_delete', | |
171 | pattern='/users/{user_id:\d+}/delete', |
|
170 | pattern='/users/{user_id:\d+}/delete', | |
172 | user_route=True) |
|
171 | user_route=True) | |
173 | config.add_route( |
|
172 | config.add_route( | |
174 | name='user_force_password_reset', |
|
173 | name='user_force_password_reset', | |
175 | pattern='/users/{user_id:\d+}/password_reset', |
|
174 | pattern='/users/{user_id:\d+}/password_reset', | |
176 | user_route=True) |
|
175 | user_route=True) | |
177 | config.add_route( |
|
176 | config.add_route( | |
178 | name='user_create_personal_repo_group', |
|
177 | name='user_create_personal_repo_group', | |
179 | pattern='/users/{user_id:\d+}/create_repo_group', |
|
178 | pattern='/users/{user_id:\d+}/create_repo_group', | |
180 | user_route=True) |
|
179 | user_route=True) | |
181 |
|
180 | |||
182 | # user auth tokens |
|
181 | # user auth tokens | |
183 | config.add_route( |
|
182 | config.add_route( | |
184 | name='edit_user_auth_tokens', |
|
183 | name='edit_user_auth_tokens', | |
185 | pattern='/users/{user_id:\d+}/edit/auth_tokens', |
|
184 | pattern='/users/{user_id:\d+}/edit/auth_tokens', | |
186 | user_route=True) |
|
185 | user_route=True) | |
187 | config.add_route( |
|
186 | config.add_route( | |
188 | name='edit_user_auth_tokens_add', |
|
187 | name='edit_user_auth_tokens_add', | |
189 | pattern='/users/{user_id:\d+}/edit/auth_tokens/new', |
|
188 | pattern='/users/{user_id:\d+}/edit/auth_tokens/new', | |
190 | user_route=True) |
|
189 | user_route=True) | |
191 | config.add_route( |
|
190 | config.add_route( | |
192 | name='edit_user_auth_tokens_delete', |
|
191 | name='edit_user_auth_tokens_delete', | |
193 | pattern='/users/{user_id:\d+}/edit/auth_tokens/delete', |
|
192 | pattern='/users/{user_id:\d+}/edit/auth_tokens/delete', | |
194 | user_route=True) |
|
193 | user_route=True) | |
195 |
|
194 | |||
196 | # user ssh keys |
|
195 | # user ssh keys | |
197 | config.add_route( |
|
196 | config.add_route( | |
198 | name='edit_user_ssh_keys', |
|
197 | name='edit_user_ssh_keys', | |
199 | pattern='/users/{user_id:\d+}/edit/ssh_keys', |
|
198 | pattern='/users/{user_id:\d+}/edit/ssh_keys', | |
200 | user_route=True) |
|
199 | user_route=True) | |
201 | config.add_route( |
|
200 | config.add_route( | |
202 | name='edit_user_ssh_keys_generate_keypair', |
|
201 | name='edit_user_ssh_keys_generate_keypair', | |
203 | pattern='/users/{user_id:\d+}/edit/ssh_keys/generate', |
|
202 | pattern='/users/{user_id:\d+}/edit/ssh_keys/generate', | |
204 | user_route=True) |
|
203 | user_route=True) | |
205 | config.add_route( |
|
204 | config.add_route( | |
206 | name='edit_user_ssh_keys_add', |
|
205 | name='edit_user_ssh_keys_add', | |
207 | pattern='/users/{user_id:\d+}/edit/ssh_keys/new', |
|
206 | pattern='/users/{user_id:\d+}/edit/ssh_keys/new', | |
208 | user_route=True) |
|
207 | user_route=True) | |
209 | config.add_route( |
|
208 | config.add_route( | |
210 | name='edit_user_ssh_keys_delete', |
|
209 | name='edit_user_ssh_keys_delete', | |
211 | pattern='/users/{user_id:\d+}/edit/ssh_keys/delete', |
|
210 | pattern='/users/{user_id:\d+}/edit/ssh_keys/delete', | |
212 | user_route=True) |
|
211 | user_route=True) | |
213 |
|
212 | |||
214 | # user emails |
|
213 | # user emails | |
215 | config.add_route( |
|
214 | config.add_route( | |
216 | name='edit_user_emails', |
|
215 | name='edit_user_emails', | |
217 | pattern='/users/{user_id:\d+}/edit/emails', |
|
216 | pattern='/users/{user_id:\d+}/edit/emails', | |
218 | user_route=True) |
|
217 | user_route=True) | |
219 | config.add_route( |
|
218 | config.add_route( | |
220 | name='edit_user_emails_add', |
|
219 | name='edit_user_emails_add', | |
221 | pattern='/users/{user_id:\d+}/edit/emails/new', |
|
220 | pattern='/users/{user_id:\d+}/edit/emails/new', | |
222 | user_route=True) |
|
221 | user_route=True) | |
223 | config.add_route( |
|
222 | config.add_route( | |
224 | name='edit_user_emails_delete', |
|
223 | name='edit_user_emails_delete', | |
225 | pattern='/users/{user_id:\d+}/edit/emails/delete', |
|
224 | pattern='/users/{user_id:\d+}/edit/emails/delete', | |
226 | user_route=True) |
|
225 | user_route=True) | |
227 |
|
226 | |||
228 | # user IPs |
|
227 | # user IPs | |
229 | config.add_route( |
|
228 | config.add_route( | |
230 | name='edit_user_ips', |
|
229 | name='edit_user_ips', | |
231 | pattern='/users/{user_id:\d+}/edit/ips', |
|
230 | pattern='/users/{user_id:\d+}/edit/ips', | |
232 | user_route=True) |
|
231 | user_route=True) | |
233 | config.add_route( |
|
232 | config.add_route( | |
234 | name='edit_user_ips_add', |
|
233 | name='edit_user_ips_add', | |
235 | pattern='/users/{user_id:\d+}/edit/ips/new', |
|
234 | pattern='/users/{user_id:\d+}/edit/ips/new', | |
236 | user_route_with_default=True) # enabled for default user too |
|
235 | user_route_with_default=True) # enabled for default user too | |
237 | config.add_route( |
|
236 | config.add_route( | |
238 | name='edit_user_ips_delete', |
|
237 | name='edit_user_ips_delete', | |
239 | pattern='/users/{user_id:\d+}/edit/ips/delete', |
|
238 | pattern='/users/{user_id:\d+}/edit/ips/delete', | |
240 | user_route_with_default=True) # enabled for default user too |
|
239 | user_route_with_default=True) # enabled for default user too | |
241 |
|
240 | |||
242 | # user perms |
|
241 | # user perms | |
243 | config.add_route( |
|
242 | config.add_route( | |
244 | name='edit_user_perms_summary', |
|
243 | name='edit_user_perms_summary', | |
245 | pattern='/users/{user_id:\d+}/edit/permissions_summary', |
|
244 | pattern='/users/{user_id:\d+}/edit/permissions_summary', | |
246 | user_route=True) |
|
245 | user_route=True) | |
247 | config.add_route( |
|
246 | config.add_route( | |
248 | name='edit_user_perms_summary_json', |
|
247 | name='edit_user_perms_summary_json', | |
249 | pattern='/users/{user_id:\d+}/edit/permissions_summary/json', |
|
248 | pattern='/users/{user_id:\d+}/edit/permissions_summary/json', | |
250 | user_route=True) |
|
249 | user_route=True) | |
251 |
|
250 | |||
252 | # user user groups management |
|
251 | # user user groups management | |
253 | config.add_route( |
|
252 | config.add_route( | |
254 | name='edit_user_groups_management', |
|
253 | name='edit_user_groups_management', | |
255 | pattern='/users/{user_id:\d+}/edit/groups_management', |
|
254 | pattern='/users/{user_id:\d+}/edit/groups_management', | |
256 | user_route=True) |
|
255 | user_route=True) | |
257 |
|
256 | |||
258 | config.add_route( |
|
257 | config.add_route( | |
259 | name='edit_user_groups_management_updates', |
|
258 | name='edit_user_groups_management_updates', | |
260 | pattern='/users/{user_id:\d+}/edit/edit_user_groups_management/updates', |
|
259 | pattern='/users/{user_id:\d+}/edit/edit_user_groups_management/updates', | |
261 | user_route=True) |
|
260 | user_route=True) | |
262 |
|
261 | |||
263 | # user audit logs |
|
262 | # user audit logs | |
264 | config.add_route( |
|
263 | config.add_route( | |
265 | name='edit_user_audit_logs', |
|
264 | name='edit_user_audit_logs', | |
266 | pattern='/users/{user_id:\d+}/edit/audit', user_route=True) |
|
265 | pattern='/users/{user_id:\d+}/edit/audit', user_route=True) | |
267 |
|
266 | |||
268 | # user-groups admin |
|
267 | # user-groups admin | |
269 | config.add_route( |
|
268 | config.add_route( | |
270 | name='user_groups', |
|
269 | name='user_groups', | |
271 | pattern='/user_groups') |
|
270 | pattern='/user_groups') | |
272 |
|
271 | |||
273 | config.add_route( |
|
272 | config.add_route( | |
274 | name='user_groups_data', |
|
273 | name='user_groups_data', | |
275 | pattern='/user_groups_data') |
|
274 | pattern='/user_groups_data') | |
276 |
|
275 | |||
277 | config.add_route( |
|
276 | config.add_route( | |
278 | name='user_groups_new', |
|
277 | name='user_groups_new', | |
279 | pattern='/user_groups/new') |
|
278 | pattern='/user_groups/new') | |
280 |
|
279 | |||
281 | config.add_route( |
|
280 | config.add_route( | |
282 | name='user_groups_create', |
|
281 | name='user_groups_create', | |
283 | pattern='/user_groups/create') |
|
282 | pattern='/user_groups/create') | |
284 |
|
283 | |||
285 | # repos admin |
|
284 | # repos admin | |
286 | config.add_route( |
|
285 | config.add_route( | |
287 | name='repos', |
|
286 | name='repos', | |
288 | pattern='/repos') |
|
287 | pattern='/repos') | |
289 |
|
288 | |||
290 | config.add_route( |
|
289 | config.add_route( | |
291 | name='repo_new', |
|
290 | name='repo_new', | |
292 | pattern='/repos/new') |
|
291 | pattern='/repos/new') | |
293 |
|
292 | |||
294 | config.add_route( |
|
293 | config.add_route( | |
295 | name='repo_create', |
|
294 | name='repo_create', | |
296 | pattern='/repos/create') |
|
295 | pattern='/repos/create') | |
297 |
|
296 | |||
298 | # repo groups admin |
|
297 | # repo groups admin | |
299 | config.add_route( |
|
298 | config.add_route( | |
300 | name='repo_groups', |
|
299 | name='repo_groups', | |
301 | pattern='/repo_groups') |
|
300 | pattern='/repo_groups') | |
302 |
|
301 | |||
303 | config.add_route( |
|
302 | config.add_route( | |
304 | name='repo_group_new', |
|
303 | name='repo_group_new', | |
305 | pattern='/repo_group/new') |
|
304 | pattern='/repo_group/new') | |
306 |
|
305 | |||
307 | config.add_route( |
|
306 | config.add_route( | |
308 | name='repo_group_create', |
|
307 | name='repo_group_create', | |
309 | pattern='/repo_group/create') |
|
308 | pattern='/repo_group/create') | |
310 |
|
309 | |||
311 |
|
310 | |||
312 | def includeme(config): |
|
311 | def includeme(config): | |
313 | settings = config.get_settings() |
|
312 | from rhodecode.apps.admin.navigation import includeme as nav_includeme | |
314 |
|
313 | |||
315 | # Create admin navigation registry and add it to the pyramid registry. |
|
314 | # Create admin navigation registry and add it to the pyramid registry. | |
316 | labs_active = str2bool(settings.get('labs_settings_active', False)) |
|
315 | nav_includeme(config) | |
317 | navigation_registry = NavigationRegistry(labs_active=labs_active) |
|
|||
318 | config.registry.registerUtility(navigation_registry) |
|
|||
319 |
|
316 | |||
320 | # main admin routes |
|
317 | # main admin routes | |
321 | config.add_route(name='admin_home', pattern=ADMIN_PREFIX) |
|
318 | config.add_route(name='admin_home', pattern=ADMIN_PREFIX) | |
322 | config.include(admin_routes, route_prefix=ADMIN_PREFIX) |
|
319 | config.include(admin_routes, route_prefix=ADMIN_PREFIX) | |
323 |
|
320 | |||
324 | # Scan module for configuration decorators. |
|
321 | # Scan module for configuration decorators. | |
325 | config.scan('.views', ignore='.tests') |
|
322 | config.scan('.views', ignore='.tests') |
@@ -1,139 +1,148 b'' | |||||
1 | # -*- coding: utf-8 -*- |
|
1 | # -*- coding: utf-8 -*- | |
2 |
|
2 | |||
3 | # Copyright (C) 2016-2017 RhodeCode GmbH |
|
3 | # Copyright (C) 2016-2017 RhodeCode GmbH | |
4 | # |
|
4 | # | |
5 | # This program is free software: you can redistribute it and/or modify |
|
5 | # This program is free software: you can redistribute it and/or modify | |
6 | # it under the terms of the GNU Affero General Public License, version 3 |
|
6 | # it under the terms of the GNU Affero General Public License, version 3 | |
7 | # (only), as published by the Free Software Foundation. |
|
7 | # (only), as published by the Free Software Foundation. | |
8 | # |
|
8 | # | |
9 | # This program is distributed in the hope that it will be useful, |
|
9 | # This program is distributed in the hope that it will be useful, | |
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | # GNU General Public License for more details. |
|
12 | # GNU General Public License for more details. | |
13 | # |
|
13 | # | |
14 | # You should have received a copy of the GNU Affero General Public License |
|
14 | # You should have received a copy of the GNU Affero General Public License | |
15 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
15 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | |
16 | # |
|
16 | # | |
17 | # This program is dual-licensed. If you wish to learn more about the |
|
17 | # This program is dual-licensed. If you wish to learn more about the | |
18 | # RhodeCode Enterprise Edition, including its added features, Support services, |
|
18 | # RhodeCode Enterprise Edition, including its added features, Support services, | |
19 | # and proprietary license terms, please see https://rhodecode.com/licenses/ |
|
19 | # and proprietary license terms, please see https://rhodecode.com/licenses/ | |
20 |
|
20 | |||
21 |
|
21 | |||
22 | import logging |
|
22 | import logging | |
23 | import collections |
|
23 | import collections | |
24 |
|
24 | |||
25 | from zope.interface import implementer |
|
25 | from zope.interface import implementer | |
26 |
|
26 | |||
27 | from rhodecode.apps.admin.interfaces import IAdminNavigationRegistry |
|
27 | from rhodecode.apps.admin.interfaces import IAdminNavigationRegistry | |
28 | from rhodecode.lib.utils import get_registry |
|
28 | from rhodecode.lib.utils import get_registry | |
|
29 | from rhodecode.lib.utils2 import str2bool | |||
29 | from rhodecode.translation import _ |
|
30 | from rhodecode.translation import _ | |
30 |
|
31 | |||
31 |
|
32 | |||
32 | log = logging.getLogger(__name__) |
|
33 | log = logging.getLogger(__name__) | |
33 |
|
34 | |||
34 | NavListEntry = collections.namedtuple('NavListEntry', ['key', 'name', 'url']) |
|
35 | NavListEntry = collections.namedtuple('NavListEntry', ['key', 'name', 'url']) | |
35 |
|
36 | |||
36 |
|
37 | |||
37 | class NavEntry(object): |
|
38 | class NavEntry(object): | |
38 | """ |
|
39 | """ | |
39 | Represents an entry in the admin navigation. |
|
40 | Represents an entry in the admin navigation. | |
40 |
|
41 | |||
41 | :param key: Unique identifier used to store reference in an OrderedDict. |
|
42 | :param key: Unique identifier used to store reference in an OrderedDict. | |
42 | :param name: Display name, usually a translation string. |
|
43 | :param name: Display name, usually a translation string. | |
43 | :param view_name: Name of the view, used generate the URL. |
|
44 | :param view_name: Name of the view, used generate the URL. | |
44 | :param pyramid: Indicator to use pyramid for URL generation. This should |
|
45 | :param pyramid: Indicator to use pyramid for URL generation. This should | |
45 | be removed as soon as we are fully migrated to pyramid. |
|
46 | be removed as soon as we are fully migrated to pyramid. | |
46 | """ |
|
47 | """ | |
47 |
|
48 | |||
48 | def __init__(self, key, name, view_name, pyramid=False): |
|
49 | def __init__(self, key, name, view_name, pyramid=False): | |
49 | self.key = key |
|
50 | self.key = key | |
50 | self.name = name |
|
51 | self.name = name | |
51 | self.view_name = view_name |
|
52 | self.view_name = view_name | |
52 | self.pyramid = pyramid |
|
53 | self.pyramid = pyramid | |
53 |
|
54 | |||
54 | def generate_url(self, request): |
|
55 | def generate_url(self, request): | |
55 | if self.pyramid: |
|
56 | if self.pyramid: | |
56 | if hasattr(request, 'route_path'): |
|
57 | if hasattr(request, 'route_path'): | |
57 | return request.route_path(self.view_name) |
|
58 | return request.route_path(self.view_name) | |
58 | else: |
|
59 | else: | |
59 | # TODO: johbo: Remove this after migrating to pyramid. |
|
60 | # TODO: johbo: Remove this after migrating to pyramid. | |
60 | # We need the pyramid request here to generate URLs to pyramid |
|
61 | # We need the pyramid request here to generate URLs to pyramid | |
61 | # views from within pylons views. |
|
62 | # views from within pylons views. | |
62 | from pyramid.threadlocal import get_current_request |
|
63 | from pyramid.threadlocal import get_current_request | |
63 | pyramid_request = get_current_request() |
|
64 | pyramid_request = get_current_request() | |
64 | return pyramid_request.route_path(self.view_name) |
|
65 | return pyramid_request.route_path(self.view_name) | |
65 | else: |
|
66 | else: | |
66 | from pylons import url |
|
67 | from pylons import url | |
67 | return url(self.view_name) |
|
68 | return url(self.view_name) | |
68 |
|
69 | |||
69 | def get_localized_name(self, request): |
|
70 | def get_localized_name(self, request): | |
70 | if hasattr(request, 'translate'): |
|
71 | if hasattr(request, 'translate'): | |
71 | return request.translate(self.name) |
|
72 | return request.translate(self.name) | |
72 | else: |
|
73 | else: | |
73 | # TODO(marcink): Remove this after migrating to pyramid |
|
74 | # TODO(marcink): Remove this after migrating to pyramid | |
74 | from pyramid.threadlocal import get_current_request |
|
75 | from pyramid.threadlocal import get_current_request | |
75 | pyramid_request = get_current_request() |
|
76 | pyramid_request = get_current_request() | |
76 | return pyramid_request.translate(self.name) |
|
77 | return pyramid_request.translate(self.name) | |
77 |
|
78 | |||
78 |
|
79 | |||
79 | @implementer(IAdminNavigationRegistry) |
|
80 | @implementer(IAdminNavigationRegistry) | |
80 | class NavigationRegistry(object): |
|
81 | class NavigationRegistry(object): | |
81 |
|
82 | |||
82 | _base_entries = [ |
|
83 | _base_entries = [ | |
83 | NavEntry('global', _('Global'), 'admin_settings_global'), |
|
84 | NavEntry('global', _('Global'), 'admin_settings_global'), | |
84 | NavEntry('vcs', _('VCS'), 'admin_settings_vcs'), |
|
85 | NavEntry('vcs', _('VCS'), 'admin_settings_vcs'), | |
85 | NavEntry('visual', _('Visual'), 'admin_settings_visual'), |
|
86 | NavEntry('visual', _('Visual'), 'admin_settings_visual'), | |
86 | NavEntry('mapping', _('Remap and Rescan'), 'admin_settings_mapping'), |
|
87 | NavEntry('mapping', _('Remap and Rescan'), 'admin_settings_mapping'), | |
87 | NavEntry('issuetracker', _('Issue Tracker'), |
|
88 | NavEntry('issuetracker', _('Issue Tracker'), | |
88 | 'admin_settings_issuetracker'), |
|
89 | 'admin_settings_issuetracker'), | |
89 | NavEntry('email', _('Email'), 'admin_settings_email'), |
|
90 | NavEntry('email', _('Email'), 'admin_settings_email'), | |
90 | NavEntry('hooks', _('Hooks'), 'admin_settings_hooks'), |
|
91 | NavEntry('hooks', _('Hooks'), 'admin_settings_hooks'), | |
91 | NavEntry('search', _('Full Text Search'), 'admin_settings_search'), |
|
92 | NavEntry('search', _('Full Text Search'), 'admin_settings_search'), | |
92 |
|
93 | |||
93 | NavEntry('integrations', _('Integrations'), |
|
94 | NavEntry('integrations', _('Integrations'), | |
94 | 'global_integrations_home', pyramid=True), |
|
95 | 'global_integrations_home', pyramid=True), | |
95 | NavEntry('system', _('System Info'), |
|
96 | NavEntry('system', _('System Info'), | |
96 | 'admin_settings_system', pyramid=True), |
|
97 | 'admin_settings_system', pyramid=True), | |
97 | NavEntry('process_management', _('Processes'), |
|
98 | NavEntry('process_management', _('Processes'), | |
98 | 'admin_settings_process_management', pyramid=True), |
|
99 | 'admin_settings_process_management', pyramid=True), | |
99 | NavEntry('sessions', _('User Sessions'), |
|
100 | NavEntry('sessions', _('User Sessions'), | |
100 | 'admin_settings_sessions', pyramid=True), |
|
101 | 'admin_settings_sessions', pyramid=True), | |
101 | NavEntry('open_source', _('Open Source Licenses'), |
|
102 | NavEntry('open_source', _('Open Source Licenses'), | |
102 | 'admin_settings_open_source', pyramid=True), |
|
103 | 'admin_settings_open_source', pyramid=True), | |
103 |
|
104 | |||
104 | ] |
|
105 | ] | |
105 |
|
106 | |||
106 | _labs_entry = NavEntry('labs', _('Labs'), 'admin_settings_labs') |
|
107 | _labs_entry = NavEntry('labs', _('Labs'), 'admin_settings_labs') | |
107 |
|
108 | |||
108 | def __init__(self, labs_active=False): |
|
109 | def __init__(self, labs_active=False): | |
109 | self._registered_entries = collections.OrderedDict() |
|
110 | self._registered_entries = collections.OrderedDict() | |
110 | for item in self.__class__._base_entries: |
|
111 | for item in self.__class__._base_entries: | |
111 | self._registered_entries[item.key] = item |
|
112 | self._registered_entries[item.key] = item | |
112 |
|
113 | |||
113 | if labs_active: |
|
114 | if labs_active: | |
114 | self.add_entry(self._labs_entry) |
|
115 | self.add_entry(self._labs_entry) | |
115 |
|
116 | |||
116 | def add_entry(self, entry): |
|
117 | def add_entry(self, entry): | |
117 | self._registered_entries[entry.key] = entry |
|
118 | self._registered_entries[entry.key] = entry | |
118 |
|
119 | |||
119 | def get_navlist(self, request): |
|
120 | def get_navlist(self, request): | |
120 | navlist = [NavListEntry(i.key, i.get_localized_name(request), |
|
121 | navlist = [NavListEntry(i.key, i.get_localized_name(request), | |
121 | i.generate_url(request)) |
|
122 | i.generate_url(request)) | |
122 | for i in self._registered_entries.values()] |
|
123 | for i in self._registered_entries.values()] | |
123 | return navlist |
|
124 | return navlist | |
124 |
|
125 | |||
125 |
|
126 | |||
126 | def navigation_registry(request, registry=None): |
|
127 | def navigation_registry(request, registry=None): | |
127 | """ |
|
128 | """ | |
128 | Helper that returns the admin navigation registry. |
|
129 | Helper that returns the admin navigation registry. | |
129 | """ |
|
130 | """ | |
130 | pyramid_registry = registry or get_registry(request) |
|
131 | pyramid_registry = registry or get_registry(request) | |
131 | nav_registry = pyramid_registry.queryUtility(IAdminNavigationRegistry) |
|
132 | nav_registry = pyramid_registry.queryUtility(IAdminNavigationRegistry) | |
132 | return nav_registry |
|
133 | return nav_registry | |
133 |
|
134 | |||
134 |
|
135 | |||
135 | def navigation_list(request): |
|
136 | def navigation_list(request): | |
136 | """ |
|
137 | """ | |
137 | Helper that returns the admin navigation as list of NavListEntry objects. |
|
138 | Helper that returns the admin navigation as list of NavListEntry objects. | |
138 | """ |
|
139 | """ | |
139 | return navigation_registry(request).get_navlist(request) |
|
140 | return navigation_registry(request).get_navlist(request) | |
|
141 | ||||
|
142 | ||||
|
143 | def includeme(config): | |||
|
144 | # Create admin navigation registry and add it to the pyramid registry. | |||
|
145 | settings = config.get_settings() | |||
|
146 | labs_active = str2bool(settings.get('labs_settings_active', False)) | |||
|
147 | navigation_registry = NavigationRegistry(labs_active=labs_active) | |||
|
148 | config.registry.registerUtility(navigation_registry) No newline at end of file |
General Comments 0
You need to be logged in to leave comments.
Login now