comparison rhodecode/config/routing.py @ 2031:82a88013a3fd

merge 1.3 into stable
author Marcin Kuzminski <marcin@python-works.com>
date Sun, 26 Feb 2012 17:25:09 +0200
parents 752b0a7b7679 87f0800abc7b
children a437a986d399
comparison
equal deleted inserted replaced
2005:ab0e122b38a7 2031:82a88013a3fd
6 refer to the routes manual at http://routes.groovie.org/docs/ 6 refer to the routes manual at http://routes.groovie.org/docs/
7 """ 7 """
8 from __future__ import with_statement 8 from __future__ import with_statement
9 from routes import Mapper 9 from routes import Mapper
10 10
11
12 # prefix for non repository related links needs to be prefixed with `/` 11 # prefix for non repository related links needs to be prefixed with `/`
13 ADMIN_PREFIX = '/_admin' 12 ADMIN_PREFIX = '/_admin'
14 13
15 14
16 def make_map(config): 15 def make_map(config):
24 from rhodecode.lib.utils import is_valid_repos_group 23 from rhodecode.lib.utils import is_valid_repos_group
25 24
26 def check_repo(environ, match_dict): 25 def check_repo(environ, match_dict):
27 """ 26 """
28 check for valid repository for proper 404 handling 27 check for valid repository for proper 404 handling
29 28
30 :param environ: 29 :param environ:
31 :param match_dict: 30 :param match_dict:
32 """ 31 """
33 32 from rhodecode.model.db import Repository
34 repo_name = match_dict.get('repo_name') 33 repo_name = match_dict.get('repo_name')
34
35 try:
36 by_id = repo_name.split('_')
37 if len(by_id) == 2 and by_id[1].isdigit():
38 repo_name = Repository.get(by_id[1]).repo_name
39 match_dict['repo_name'] = repo_name
40 except:
41 pass
42
35 return is_valid_repo(repo_name, config['base_path']) 43 return is_valid_repo(repo_name, config['base_path'])
36 44
37 def check_group(environ, match_dict): 45 def check_group(environ, match_dict):
38 """ 46 """
39 check for valid repositories group for proper 404 handling 47 check for valid repositories group for proper 404 handling
40 48
41 :param environ: 49 :param environ:
42 :param match_dict: 50 :param match_dict:
43 """ 51 """
44 repos_group_name = match_dict.get('group_name') 52 repos_group_name = match_dict.get('group_name')
45 53
46 return is_valid_repos_group(repos_group_name, config['base_path']) 54 return is_valid_repos_group(repos_group_name, config['base_path'])
47 55
48
49 def check_int(environ, match_dict): 56 def check_int(environ, match_dict):
50 return match_dict.get('id').isdigit() 57 return match_dict.get('id').isdigit()
51 58
52 # The ErrorController route (handles 404/500 error pages); it should 59 # The ErrorController route (handles 404/500 error pages); it should
53 # likely stay at the top, ensuring it can always be resolved 60 # likely stay at the top, ensuring it can always be resolved
60 67
61 #MAIN PAGE 68 #MAIN PAGE
62 rmap.connect('home', '/', controller='home', action='index') 69 rmap.connect('home', '/', controller='home', action='index')
63 rmap.connect('repo_switcher', '/repos', controller='home', 70 rmap.connect('repo_switcher', '/repos', controller='home',
64 action='repo_switcher') 71 action='repo_switcher')
72 rmap.connect('branch_tag_switcher', '/branches-tags/{repo_name:.*}',
73 controller='home', action='branch_tag_switcher')
65 rmap.connect('bugtracker', 74 rmap.connect('bugtracker',
66 "http://bitbucket.org/marcinkuzminski/rhodecode/issues", 75 "http://bitbucket.org/marcinkuzminski/rhodecode/issues",
76 _static=True)
77 rmap.connect('rst_help',
78 "http://docutils.sourceforge.net/docs/user/rst/quickref.html",
67 _static=True) 79 _static=True)
68 rmap.connect('rhodecode_official', "http://rhodecode.org", _static=True) 80 rmap.connect('rhodecode_official', "http://rhodecode.org", _static=True)
69 81
70 #ADMIN REPOSITORY REST ROUTES 82 #ADMIN REPOSITORY REST ROUTES
71 with rmap.submapper(path_prefix=ADMIN_PREFIX, 83 with rmap.submapper(path_prefix=ADMIN_PREFIX,
99 m.connect("formatted_repo", "/repos/{repo_name:.*}.{format}", 111 m.connect("formatted_repo", "/repos/{repo_name:.*}.{format}",
100 action="show", conditions=dict(method=["GET"], 112 action="show", conditions=dict(method=["GET"],
101 function=check_repo)) 113 function=check_repo))
102 #ajax delete repo perm user 114 #ajax delete repo perm user
103 m.connect('delete_repo_user', "/repos_delete_user/{repo_name:.*}", 115 m.connect('delete_repo_user', "/repos_delete_user/{repo_name:.*}",
104 action="delete_perm_user", conditions=dict(method=["DELETE"], 116 action="delete_perm_user",
105 function=check_repo)) 117 conditions=dict(method=["DELETE"], function=check_repo))
118
106 #ajax delete repo perm users_group 119 #ajax delete repo perm users_group
107 m.connect('delete_repo_users_group', 120 m.connect('delete_repo_users_group',
108 "/repos_delete_users_group/{repo_name:.*}", 121 "/repos_delete_users_group/{repo_name:.*}",
109 action="delete_perm_users_group", 122 action="delete_perm_users_group",
110 conditions=dict(method=["DELETE"], function=check_repo)) 123 conditions=dict(method=["DELETE"], function=check_repo))
111 124
112 #settings actions 125 #settings actions
113 m.connect('repo_stats', "/repos_stats/{repo_name:.*}", 126 m.connect('repo_stats', "/repos_stats/{repo_name:.*}",
114 action="repo_stats", conditions=dict(method=["DELETE"], 127 action="repo_stats", conditions=dict(method=["DELETE"],
128 function=check_repo))
129 m.connect('repo_cache', "/repos_cache/{repo_name:.*}",
130 action="repo_cache", conditions=dict(method=["DELETE"],
131 function=check_repo))
132 m.connect('repo_public_journal', "/repos_public_journal/{repo_name:.*}",
133 action="repo_public_journal", conditions=dict(method=["PUT"],
115 function=check_repo)) 134 function=check_repo))
116 m.connect('repo_cache', "/repos_cache/{repo_name:.*}",
117 action="repo_cache", conditions=dict(method=["DELETE"],
118 function=check_repo))
119 m.connect('repo_public_journal',
120 "/repos_public_journal/{repo_name:.*}",
121 action="repo_public_journal", conditions=dict(method=["PUT"],
122 function=check_repo))
123 m.connect('repo_pull', "/repo_pull/{repo_name:.*}", 135 m.connect('repo_pull', "/repo_pull/{repo_name:.*}",
124 action="repo_pull", conditions=dict(method=["PUT"], 136 action="repo_pull", conditions=dict(method=["PUT"],
125 function=check_repo)) 137 function=check_repo))
138 m.connect('repo_as_fork', "/repo_as_fork/{repo_name:.*}",
139 action="repo_as_fork", conditions=dict(method=["PUT"],
140 function=check_repo))
126 141
127 with rmap.submapper(path_prefix=ADMIN_PREFIX, 142 with rmap.submapper(path_prefix=ADMIN_PREFIX,
128 controller='admin/repos_groups') as m: 143 controller='admin/repos_groups') as m:
129 m.connect("repos_groups", "/repos_groups", 144 m.connect("repos_groups", "/repos_groups",
130 action="create", conditions=dict(method=["POST"])) 145 action="create", conditions=dict(method=["POST"]))
153 action="show", conditions=dict(method=["GET"], 168 action="show", conditions=dict(method=["GET"],
154 function=check_int)) 169 function=check_int))
155 m.connect("formatted_repos_group", "/repos_groups/{id}.{format}", 170 m.connect("formatted_repos_group", "/repos_groups/{id}.{format}",
156 action="show", conditions=dict(method=["GET"], 171 action="show", conditions=dict(method=["GET"],
157 function=check_int)) 172 function=check_int))
173 # ajax delete repos group perm user
174 m.connect('delete_repos_group_user_perm',
175 "/delete_repos_group_user_perm/{group_name:.*}",
176 action="delete_repos_group_user_perm",
177 conditions=dict(method=["DELETE"], function=check_group))
178
179 # ajax delete repos group perm users_group
180 m.connect('delete_repos_group_users_group_perm',
181 "/delete_repos_group_users_group_perm/{group_name:.*}",
182 action="delete_repos_group_users_group_perm",
183 conditions=dict(method=["DELETE"], function=check_group))
158 184
159 #ADMIN USER REST ROUTES 185 #ADMIN USER REST ROUTES
160 with rmap.submapper(path_prefix=ADMIN_PREFIX, 186 with rmap.submapper(path_prefix=ADMIN_PREFIX,
161 controller='admin/users') as m: 187 controller='admin/users') as m:
162 m.connect("users", "/users", 188 m.connect("users", "/users",
265 m.connect("admin_settings_my_account_update", "/my_account_update", 291 m.connect("admin_settings_my_account_update", "/my_account_update",
266 action="my_account_update", conditions=dict(method=["PUT"])) 292 action="my_account_update", conditions=dict(method=["PUT"]))
267 m.connect("admin_settings_create_repository", "/create_repository", 293 m.connect("admin_settings_create_repository", "/create_repository",
268 action="create_repository", conditions=dict(method=["GET"])) 294 action="create_repository", conditions=dict(method=["GET"]))
269 295
296 #NOTIFICATION REST ROUTES
297 with rmap.submapper(path_prefix=ADMIN_PREFIX,
298 controller='admin/notifications') as m:
299 m.connect("notifications", "/notifications",
300 action="create", conditions=dict(method=["POST"]))
301 m.connect("notifications", "/notifications",
302 action="index", conditions=dict(method=["GET"]))
303 m.connect("notifications_mark_all_read", "/notifications/mark_all_read",
304 action="mark_all_read", conditions=dict(method=["GET"]))
305 m.connect("formatted_notifications", "/notifications.{format}",
306 action="index", conditions=dict(method=["GET"]))
307 m.connect("new_notification", "/notifications/new",
308 action="new", conditions=dict(method=["GET"]))
309 m.connect("formatted_new_notification", "/notifications/new.{format}",
310 action="new", conditions=dict(method=["GET"]))
311 m.connect("/notification/{notification_id}",
312 action="update", conditions=dict(method=["PUT"]))
313 m.connect("/notification/{notification_id}",
314 action="delete", conditions=dict(method=["DELETE"]))
315 m.connect("edit_notification", "/notification/{notification_id}/edit",
316 action="edit", conditions=dict(method=["GET"]))
317 m.connect("formatted_edit_notification",
318 "/notification/{notification_id}.{format}/edit",
319 action="edit", conditions=dict(method=["GET"]))
320 m.connect("notification", "/notification/{notification_id}",
321 action="show", conditions=dict(method=["GET"]))
322 m.connect("formatted_notification", "/notifications/{notification_id}.{format}",
323 action="show", conditions=dict(method=["GET"]))
270 324
271 #ADMIN MAIN PAGES 325 #ADMIN MAIN PAGES
272 with rmap.submapper(path_prefix=ADMIN_PREFIX, 326 with rmap.submapper(path_prefix=ADMIN_PREFIX,
273 controller='admin/admin') as m: 327 controller='admin/admin') as m:
274 m.connect('admin_home', '', action='index') 328 m.connect('admin_home', '', action='index')
275 m.connect('admin_add_repo', '/add_repo/{new_repo:[a-z0-9\. _-]*}', 329 m.connect('admin_add_repo', '/add_repo/{new_repo:[a-z0-9\. _-]*}',
276 action='add_repo') 330 action='add_repo')
277 331
278 #========================================================================== 332 #==========================================================================
279 # API V1 333 # API V2
280 #========================================================================== 334 #==========================================================================
281 with rmap.submapper(path_prefix=ADMIN_PREFIX, 335 with rmap.submapper(path_prefix=ADMIN_PREFIX,
282 controller='api/api') as m: 336 controller='api/api') as m:
283 m.connect('api', '/api') 337 m.connect('api', '/api')
284
285 338
286 #USER JOURNAL 339 #USER JOURNAL
287 rmap.connect('journal', '%s/journal' % ADMIN_PREFIX, controller='journal') 340 rmap.connect('journal', '%s/journal' % ADMIN_PREFIX, controller='journal')
288 341
289 rmap.connect('public_journal', '%s/public_journal' % ADMIN_PREFIX, 342 rmap.connect('public_journal', '%s/public_journal' % ADMIN_PREFIX,
342 395
343 rmap.connect('changeset_home', '/{repo_name:.*}/changeset/{revision}', 396 rmap.connect('changeset_home', '/{repo_name:.*}/changeset/{revision}',
344 controller='changeset', revision='tip', 397 controller='changeset', revision='tip',
345 conditions=dict(function=check_repo)) 398 conditions=dict(function=check_repo))
346 399
400 rmap.connect('changeset_comment',
401 '/{repo_name:.*}/changeset/{revision}/comment',
402 controller='changeset', revision='tip', action='comment',
403 conditions=dict(function=check_repo))
404
405 rmap.connect('changeset_comment_delete',
406 '/{repo_name:.*}/changeset/comment/{comment_id}/delete',
407 controller='changeset', action='delete_comment',
408 conditions=dict(function=check_repo, method=["DELETE"]))
409
347 rmap.connect('raw_changeset_home', 410 rmap.connect('raw_changeset_home',
348 '/{repo_name:.*}/raw-changeset/{revision}', 411 '/{repo_name:.*}/raw-changeset/{revision}',
349 controller='changeset', action='raw_changeset', 412 controller='changeset', action='raw_changeset',
350 revision='tip', conditions=dict(function=check_repo)) 413 revision='tip', conditions=dict(function=check_repo))
351 414
359 controller='branches', conditions=dict(function=check_repo)) 422 controller='branches', conditions=dict(function=check_repo))
360 423
361 rmap.connect('tags_home', '/{repo_name:.*}/tags', 424 rmap.connect('tags_home', '/{repo_name:.*}/tags',
362 controller='tags', conditions=dict(function=check_repo)) 425 controller='tags', conditions=dict(function=check_repo))
363 426
427 rmap.connect('bookmarks_home', '/{repo_name:.*}/bookmarks',
428 controller='bookmarks', conditions=dict(function=check_repo))
429
364 rmap.connect('changelog_home', '/{repo_name:.*}/changelog', 430 rmap.connect('changelog_home', '/{repo_name:.*}/changelog',
365 controller='changelog', conditions=dict(function=check_repo)) 431 controller='changelog', conditions=dict(function=check_repo))
366 432
367 rmap.connect('changelog_details', '/{repo_name:.*}/changelog_details/{cs}', 433 rmap.connect('changelog_details', '/{repo_name:.*}/changelog_details/{cs}',
368 controller='changelog', action='changelog_details', 434 controller='changelog', action='changelog_details',
421 rmap.connect('repo_settings_home', '/{repo_name:.*}/settings', 487 rmap.connect('repo_settings_home', '/{repo_name:.*}/settings',
422 controller='settings', action='index', 488 controller='settings', action='index',
423 conditions=dict(function=check_repo)) 489 conditions=dict(function=check_repo))
424 490
425 rmap.connect('repo_fork_create_home', '/{repo_name:.*}/fork', 491 rmap.connect('repo_fork_create_home', '/{repo_name:.*}/fork',
426 controller='settings', action='fork_create', 492 controller='forks', action='fork_create',
427 conditions=dict(function=check_repo, method=["POST"])) 493 conditions=dict(function=check_repo, method=["POST"]))
428 494
429 rmap.connect('repo_fork_home', '/{repo_name:.*}/fork', 495 rmap.connect('repo_fork_home', '/{repo_name:.*}/fork',
430 controller='settings', action='fork', 496 controller='forks', action='fork',
431 conditions=dict(function=check_repo)) 497 conditions=dict(function=check_repo))
498
499 rmap.connect('repo_forks_home', '/{repo_name:.*}/forks',
500 controller='forks', action='forks',
501 conditions=dict(function=check_repo))
432 502
433 rmap.connect('repo_followers_home', '/{repo_name:.*}/followers', 503 rmap.connect('repo_followers_home', '/{repo_name:.*}/followers',
434 controller='followers', action='followers', 504 controller='followers', action='followers',
435 conditions=dict(function=check_repo)) 505 conditions=dict(function=check_repo))
436 506
437 rmap.connect('repo_forks_home', '/{repo_name:.*}/forks',
438 controller='forks', action='forks',
439 conditions=dict(function=check_repo))
440
441 return rmap 507 return rmap