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