##// END OF EJS Templates
added global fix for stripping multiple slashes from f_path variable
marcink -
r3040:ec483ce6 beta
parent child Browse files
Show More
@@ -1,616 +1,620 b''
1 1 """
2 2 Routes configuration
3 3
4 4 The more specific and detailed routes should be defined first so they
5 5 may take precedent over the more generic routes. For more information
6 6 refer to the routes manual at http://routes.groovie.org/docs/
7 7 """
8 8 from __future__ import with_statement
9 9 from routes import Mapper
10 10
11 11 # prefix for non repository related links needs to be prefixed with `/`
12 12 ADMIN_PREFIX = '/_admin'
13 13
14 14
15 15 def make_map(config):
16 16 """Create, configure and return the routes Mapper"""
17 17 rmap = Mapper(directory=config['pylons.paths']['controllers'],
18 18 always_scan=config['debug'])
19 19 rmap.minimization = False
20 20 rmap.explicit = False
21 21
22 22 from rhodecode.lib.utils import is_valid_repo
23 23 from rhodecode.lib.utils import is_valid_repos_group
24 24
25 25 def check_repo(environ, match_dict):
26 26 """
27 27 check for valid repository for proper 404 handling
28 28
29 29 :param environ:
30 30 :param match_dict:
31 31 """
32 32 from rhodecode.model.db import Repository
33 33 repo_name = match_dict.get('repo_name')
34 34
35 if match_dict.get('f_path'):
36 #fix for multiple initial slashes that causes errors
37 match_dict['f_path'] = match_dict['f_path'].lstrip('/')
38
35 39 try:
36 40 by_id = repo_name.split('_')
37 41 if len(by_id) == 2 and by_id[1].isdigit() and by_id[0] == '':
38 42 repo_name = Repository.get(by_id[1]).repo_name
39 43 match_dict['repo_name'] = repo_name
40 44 except:
41 45 pass
42 46
43 47 return is_valid_repo(repo_name, config['base_path'])
44 48
45 49 def check_group(environ, match_dict):
46 50 """
47 51 check for valid repositories group for proper 404 handling
48 52
49 53 :param environ:
50 54 :param match_dict:
51 55 """
52 56 repos_group_name = match_dict.get('group_name')
53 57
54 58 return is_valid_repos_group(repos_group_name, config['base_path'])
55 59
56 60 def check_int(environ, match_dict):
57 61 return match_dict.get('id').isdigit()
58 62
59 63 # The ErrorController route (handles 404/500 error pages); it should
60 64 # likely stay at the top, ensuring it can always be resolved
61 65 rmap.connect('/error/{action}', controller='error')
62 66 rmap.connect('/error/{action}/{id}', controller='error')
63 67
64 68 #==========================================================================
65 69 # CUSTOM ROUTES HERE
66 70 #==========================================================================
67 71
68 72 #MAIN PAGE
69 73 rmap.connect('home', '/', controller='home', action='index')
70 74 rmap.connect('repo_switcher', '/repos', controller='home',
71 75 action='repo_switcher')
72 76 rmap.connect('branch_tag_switcher', '/branches-tags/{repo_name:.*?}',
73 77 controller='home', action='branch_tag_switcher')
74 78 rmap.connect('bugtracker',
75 79 "http://bitbucket.org/marcinkuzminski/rhodecode/issues",
76 80 _static=True)
77 81 rmap.connect('rst_help',
78 82 "http://docutils.sourceforge.net/docs/user/rst/quickref.html",
79 83 _static=True)
80 84 rmap.connect('rhodecode_official', "http://rhodecode.org", _static=True)
81 85
82 86 #ADMIN REPOSITORY REST ROUTES
83 87 with rmap.submapper(path_prefix=ADMIN_PREFIX,
84 88 controller='admin/repos') as m:
85 89 m.connect("repos", "/repos",
86 90 action="create", conditions=dict(method=["POST"]))
87 91 m.connect("repos", "/repos",
88 92 action="index", conditions=dict(method=["GET"]))
89 93 m.connect("formatted_repos", "/repos.{format}",
90 94 action="index",
91 95 conditions=dict(method=["GET"]))
92 96 m.connect("new_repo", "/repos/new",
93 97 action="new", conditions=dict(method=["GET"]))
94 98 m.connect("formatted_new_repo", "/repos/new.{format}",
95 99 action="new", conditions=dict(method=["GET"]))
96 100 m.connect("/repos/{repo_name:.*?}",
97 101 action="update", conditions=dict(method=["PUT"],
98 102 function=check_repo))
99 103 m.connect("/repos/{repo_name:.*?}",
100 104 action="delete", conditions=dict(method=["DELETE"],
101 105 function=check_repo))
102 106 m.connect("edit_repo", "/repos/{repo_name:.*?}/edit",
103 107 action="edit", conditions=dict(method=["GET"],
104 108 function=check_repo))
105 109 m.connect("formatted_edit_repo", "/repos/{repo_name:.*?}.{format}/edit",
106 110 action="edit", conditions=dict(method=["GET"],
107 111 function=check_repo))
108 112 m.connect("repo", "/repos/{repo_name:.*?}",
109 113 action="show", conditions=dict(method=["GET"],
110 114 function=check_repo))
111 115 m.connect("formatted_repo", "/repos/{repo_name:.*?}.{format}",
112 116 action="show", conditions=dict(method=["GET"],
113 117 function=check_repo))
114 118 #ajax delete repo perm user
115 119 m.connect('delete_repo_user', "/repos_delete_user/{repo_name:.*?}",
116 120 action="delete_perm_user",
117 121 conditions=dict(method=["DELETE"], function=check_repo))
118 122
119 123 #ajax delete repo perm users_group
120 124 m.connect('delete_repo_users_group',
121 125 "/repos_delete_users_group/{repo_name:.*?}",
122 126 action="delete_perm_users_group",
123 127 conditions=dict(method=["DELETE"], function=check_repo))
124 128
125 129 #settings actions
126 130 m.connect('repo_stats', "/repos_stats/{repo_name:.*?}",
127 131 action="repo_stats", conditions=dict(method=["DELETE"],
128 132 function=check_repo))
129 133 m.connect('repo_cache', "/repos_cache/{repo_name:.*?}",
130 134 action="repo_cache", conditions=dict(method=["DELETE"],
131 135 function=check_repo))
132 136 m.connect('repo_public_journal', "/repos_public_journal/{repo_name:.*?}",
133 137 action="repo_public_journal", conditions=dict(method=["PUT"],
134 138 function=check_repo))
135 139 m.connect('repo_pull', "/repo_pull/{repo_name:.*?}",
136 140 action="repo_pull", conditions=dict(method=["PUT"],
137 141 function=check_repo))
138 142 m.connect('repo_as_fork', "/repo_as_fork/{repo_name:.*?}",
139 143 action="repo_as_fork", conditions=dict(method=["PUT"],
140 144 function=check_repo))
141 145 m.connect('repo_locking', "/repo_locking/{repo_name:.*?}",
142 146 action="repo_locking", conditions=dict(method=["PUT"],
143 147 function=check_repo))
144 148
145 149 with rmap.submapper(path_prefix=ADMIN_PREFIX,
146 150 controller='admin/repos_groups') as m:
147 151 m.connect("repos_groups", "/repos_groups",
148 152 action="create", conditions=dict(method=["POST"]))
149 153 m.connect("repos_groups", "/repos_groups",
150 154 action="index", conditions=dict(method=["GET"]))
151 155 m.connect("formatted_repos_groups", "/repos_groups.{format}",
152 156 action="index", conditions=dict(method=["GET"]))
153 157 m.connect("new_repos_group", "/repos_groups/new",
154 158 action="new", conditions=dict(method=["GET"]))
155 159 m.connect("formatted_new_repos_group", "/repos_groups/new.{format}",
156 160 action="new", conditions=dict(method=["GET"]))
157 161 m.connect("update_repos_group", "/repos_groups/{id}",
158 162 action="update", conditions=dict(method=["PUT"],
159 163 function=check_int))
160 164 m.connect("delete_repos_group", "/repos_groups/{id}",
161 165 action="delete", conditions=dict(method=["DELETE"],
162 166 function=check_int))
163 167 m.connect("edit_repos_group", "/repos_groups/{id:.*?}/edit",
164 168 action="edit", conditions=dict(method=["GET"],))
165 169 m.connect("formatted_edit_repos_group",
166 170 "/repos_groups/{id}.{format}/edit",
167 171 action="edit", conditions=dict(method=["GET"],
168 172 function=check_int))
169 173 m.connect("repos_group", "/repos_groups/{id}",
170 174 action="show", conditions=dict(method=["GET"],
171 175 function=check_int))
172 176 m.connect("formatted_repos_group", "/repos_groups/{id}.{format}",
173 177 action="show", conditions=dict(method=["GET"],
174 178 function=check_int))
175 179 # ajax delete repos group perm user
176 180 m.connect('delete_repos_group_user_perm',
177 181 "/delete_repos_group_user_perm/{group_name:.*}",
178 182 action="delete_repos_group_user_perm",
179 183 conditions=dict(method=["DELETE"], function=check_group))
180 184
181 185 # ajax delete repos group perm users_group
182 186 m.connect('delete_repos_group_users_group_perm',
183 187 "/delete_repos_group_users_group_perm/{group_name:.*}",
184 188 action="delete_repos_group_users_group_perm",
185 189 conditions=dict(method=["DELETE"], function=check_group))
186 190
187 191 #ADMIN USER REST ROUTES
188 192 with rmap.submapper(path_prefix=ADMIN_PREFIX,
189 193 controller='admin/users') as m:
190 194 m.connect("users", "/users",
191 195 action="create", conditions=dict(method=["POST"]))
192 196 m.connect("users", "/users",
193 197 action="index", conditions=dict(method=["GET"]))
194 198 m.connect("formatted_users", "/users.{format}",
195 199 action="index", conditions=dict(method=["GET"]))
196 200 m.connect("new_user", "/users/new",
197 201 action="new", conditions=dict(method=["GET"]))
198 202 m.connect("formatted_new_user", "/users/new.{format}",
199 203 action="new", conditions=dict(method=["GET"]))
200 204 m.connect("update_user", "/users/{id}",
201 205 action="update", conditions=dict(method=["PUT"]))
202 206 m.connect("delete_user", "/users/{id}",
203 207 action="delete", conditions=dict(method=["DELETE"]))
204 208 m.connect("edit_user", "/users/{id}/edit",
205 209 action="edit", conditions=dict(method=["GET"]))
206 210 m.connect("formatted_edit_user",
207 211 "/users/{id}.{format}/edit",
208 212 action="edit", conditions=dict(method=["GET"]))
209 213 m.connect("user", "/users/{id}",
210 214 action="show", conditions=dict(method=["GET"]))
211 215 m.connect("formatted_user", "/users/{id}.{format}",
212 216 action="show", conditions=dict(method=["GET"]))
213 217
214 218 #EXTRAS USER ROUTES
215 219 m.connect("user_perm", "/users_perm/{id}",
216 220 action="update_perm", conditions=dict(method=["PUT"]))
217 221 m.connect("user_emails", "/users_emails/{id}",
218 222 action="add_email", conditions=dict(method=["PUT"]))
219 223 m.connect("user_emails_delete", "/users_emails/{id}",
220 224 action="delete_email", conditions=dict(method=["DELETE"]))
221 225
222 226 #ADMIN USERS GROUPS REST ROUTES
223 227 with rmap.submapper(path_prefix=ADMIN_PREFIX,
224 228 controller='admin/users_groups') as m:
225 229 m.connect("users_groups", "/users_groups",
226 230 action="create", conditions=dict(method=["POST"]))
227 231 m.connect("users_groups", "/users_groups",
228 232 action="index", conditions=dict(method=["GET"]))
229 233 m.connect("formatted_users_groups", "/users_groups.{format}",
230 234 action="index", conditions=dict(method=["GET"]))
231 235 m.connect("new_users_group", "/users_groups/new",
232 236 action="new", conditions=dict(method=["GET"]))
233 237 m.connect("formatted_new_users_group", "/users_groups/new.{format}",
234 238 action="new", conditions=dict(method=["GET"]))
235 239 m.connect("update_users_group", "/users_groups/{id}",
236 240 action="update", conditions=dict(method=["PUT"]))
237 241 m.connect("delete_users_group", "/users_groups/{id}",
238 242 action="delete", conditions=dict(method=["DELETE"]))
239 243 m.connect("edit_users_group", "/users_groups/{id}/edit",
240 244 action="edit", conditions=dict(method=["GET"]))
241 245 m.connect("formatted_edit_users_group",
242 246 "/users_groups/{id}.{format}/edit",
243 247 action="edit", conditions=dict(method=["GET"]))
244 248 m.connect("users_group", "/users_groups/{id}",
245 249 action="show", conditions=dict(method=["GET"]))
246 250 m.connect("formatted_users_group", "/users_groups/{id}.{format}",
247 251 action="show", conditions=dict(method=["GET"]))
248 252
249 253 #EXTRAS USER ROUTES
250 254 m.connect("users_group_perm", "/users_groups_perm/{id}",
251 255 action="update_perm", conditions=dict(method=["PUT"]))
252 256
253 257 #ADMIN GROUP REST ROUTES
254 258 rmap.resource('group', 'groups',
255 259 controller='admin/groups', path_prefix=ADMIN_PREFIX)
256 260
257 261 #ADMIN PERMISSIONS REST ROUTES
258 262 rmap.resource('permission', 'permissions',
259 263 controller='admin/permissions', path_prefix=ADMIN_PREFIX)
260 264
261 265 ##ADMIN LDAP SETTINGS
262 266 rmap.connect('ldap_settings', '%s/ldap' % ADMIN_PREFIX,
263 267 controller='admin/ldap_settings', action='ldap_settings',
264 268 conditions=dict(method=["POST"]))
265 269
266 270 rmap.connect('ldap_home', '%s/ldap' % ADMIN_PREFIX,
267 271 controller='admin/ldap_settings')
268 272
269 273 #ADMIN SETTINGS REST ROUTES
270 274 with rmap.submapper(path_prefix=ADMIN_PREFIX,
271 275 controller='admin/settings') as m:
272 276 m.connect("admin_settings", "/settings",
273 277 action="create", conditions=dict(method=["POST"]))
274 278 m.connect("admin_settings", "/settings",
275 279 action="index", conditions=dict(method=["GET"]))
276 280 m.connect("formatted_admin_settings", "/settings.{format}",
277 281 action="index", conditions=dict(method=["GET"]))
278 282 m.connect("admin_new_setting", "/settings/new",
279 283 action="new", conditions=dict(method=["GET"]))
280 284 m.connect("formatted_admin_new_setting", "/settings/new.{format}",
281 285 action="new", conditions=dict(method=["GET"]))
282 286 m.connect("/settings/{setting_id}",
283 287 action="update", conditions=dict(method=["PUT"]))
284 288 m.connect("/settings/{setting_id}",
285 289 action="delete", conditions=dict(method=["DELETE"]))
286 290 m.connect("admin_edit_setting", "/settings/{setting_id}/edit",
287 291 action="edit", conditions=dict(method=["GET"]))
288 292 m.connect("formatted_admin_edit_setting",
289 293 "/settings/{setting_id}.{format}/edit",
290 294 action="edit", conditions=dict(method=["GET"]))
291 295 m.connect("admin_setting", "/settings/{setting_id}",
292 296 action="show", conditions=dict(method=["GET"]))
293 297 m.connect("formatted_admin_setting", "/settings/{setting_id}.{format}",
294 298 action="show", conditions=dict(method=["GET"]))
295 299 m.connect("admin_settings_my_account", "/my_account",
296 300 action="my_account", conditions=dict(method=["GET"]))
297 301 m.connect("admin_settings_my_account_update", "/my_account_update",
298 302 action="my_account_update", conditions=dict(method=["PUT"]))
299 303 m.connect("admin_settings_create_repository", "/create_repository",
300 304 action="create_repository", conditions=dict(method=["GET"]))
301 305 m.connect("admin_settings_my_repos", "/my_account/repos",
302 306 action="my_account_my_repos", conditions=dict(method=["GET"]))
303 307 m.connect("admin_settings_my_pullrequests", "/my_account/pull_requests",
304 308 action="my_account_my_pullrequests", conditions=dict(method=["GET"]))
305 309
306 310 #NOTIFICATION REST ROUTES
307 311 with rmap.submapper(path_prefix=ADMIN_PREFIX,
308 312 controller='admin/notifications') as m:
309 313 m.connect("notifications", "/notifications",
310 314 action="create", conditions=dict(method=["POST"]))
311 315 m.connect("notifications", "/notifications",
312 316 action="index", conditions=dict(method=["GET"]))
313 317 m.connect("notifications_mark_all_read", "/notifications/mark_all_read",
314 318 action="mark_all_read", conditions=dict(method=["GET"]))
315 319 m.connect("formatted_notifications", "/notifications.{format}",
316 320 action="index", conditions=dict(method=["GET"]))
317 321 m.connect("new_notification", "/notifications/new",
318 322 action="new", conditions=dict(method=["GET"]))
319 323 m.connect("formatted_new_notification", "/notifications/new.{format}",
320 324 action="new", conditions=dict(method=["GET"]))
321 325 m.connect("/notification/{notification_id}",
322 326 action="update", conditions=dict(method=["PUT"]))
323 327 m.connect("/notification/{notification_id}",
324 328 action="delete", conditions=dict(method=["DELETE"]))
325 329 m.connect("edit_notification", "/notification/{notification_id}/edit",
326 330 action="edit", conditions=dict(method=["GET"]))
327 331 m.connect("formatted_edit_notification",
328 332 "/notification/{notification_id}.{format}/edit",
329 333 action="edit", conditions=dict(method=["GET"]))
330 334 m.connect("notification", "/notification/{notification_id}",
331 335 action="show", conditions=dict(method=["GET"]))
332 336 m.connect("formatted_notification", "/notifications/{notification_id}.{format}",
333 337 action="show", conditions=dict(method=["GET"]))
334 338
335 339 #ADMIN MAIN PAGES
336 340 with rmap.submapper(path_prefix=ADMIN_PREFIX,
337 341 controller='admin/admin') as m:
338 342 m.connect('admin_home', '', action='index')
339 343 m.connect('admin_add_repo', '/add_repo/{new_repo:[a-z0-9\. _-]*}',
340 344 action='add_repo')
341 345
342 346 #==========================================================================
343 347 # API V2
344 348 #==========================================================================
345 349 with rmap.submapper(path_prefix=ADMIN_PREFIX,
346 350 controller='api/api') as m:
347 351 m.connect('api', '/api')
348 352
349 353 #USER JOURNAL
350 354 rmap.connect('journal_my_repos', '%s/journal_my_repos' % ADMIN_PREFIX,
351 355 controller='journal', action='index_my_repos')
352 356 rmap.connect('journal', '%s/journal' % ADMIN_PREFIX,
353 357 controller='journal', action='index')
354 358 rmap.connect('journal_rss', '%s/journal/rss' % ADMIN_PREFIX,
355 359 controller='journal', action='journal_rss')
356 360 rmap.connect('journal_atom', '%s/journal/atom' % ADMIN_PREFIX,
357 361 controller='journal', action='journal_atom')
358 362
359 363 rmap.connect('public_journal', '%s/public_journal' % ADMIN_PREFIX,
360 364 controller='journal', action="public_journal")
361 365
362 366 rmap.connect('public_journal_rss', '%s/public_journal/rss' % ADMIN_PREFIX,
363 367 controller='journal', action="public_journal_rss")
364 368
365 369 rmap.connect('public_journal_rss_old', '%s/public_journal_rss' % ADMIN_PREFIX,
366 370 controller='journal', action="public_journal_rss")
367 371
368 372 rmap.connect('public_journal_atom',
369 373 '%s/public_journal/atom' % ADMIN_PREFIX, controller='journal',
370 374 action="public_journal_atom")
371 375
372 376 rmap.connect('public_journal_atom_old',
373 377 '%s/public_journal_atom' % ADMIN_PREFIX, controller='journal',
374 378 action="public_journal_atom")
375 379
376 380 rmap.connect('toggle_following', '%s/toggle_following' % ADMIN_PREFIX,
377 381 controller='journal', action='toggle_following',
378 382 conditions=dict(method=["POST"]))
379 383
380 384 #SEARCH
381 385 rmap.connect('search', '%s/search' % ADMIN_PREFIX, controller='search',)
382 386 rmap.connect('search_repo', '%s/search/{search_repo:.*}' % ADMIN_PREFIX,
383 387 controller='search')
384 388
385 389 #LOGIN/LOGOUT/REGISTER/SIGN IN
386 390 rmap.connect('login_home', '%s/login' % ADMIN_PREFIX, controller='login')
387 391 rmap.connect('logout_home', '%s/logout' % ADMIN_PREFIX, controller='login',
388 392 action='logout')
389 393
390 394 rmap.connect('register', '%s/register' % ADMIN_PREFIX, controller='login',
391 395 action='register')
392 396
393 397 rmap.connect('reset_password', '%s/password_reset' % ADMIN_PREFIX,
394 398 controller='login', action='password_reset')
395 399
396 400 rmap.connect('reset_password_confirmation',
397 401 '%s/password_reset_confirmation' % ADMIN_PREFIX,
398 402 controller='login', action='password_reset_confirmation')
399 403
400 404 #FEEDS
401 405 rmap.connect('rss_feed_home', '/{repo_name:.*?}/feed/rss',
402 406 controller='feed', action='rss',
403 407 conditions=dict(function=check_repo))
404 408
405 409 rmap.connect('atom_feed_home', '/{repo_name:.*?}/feed/atom',
406 410 controller='feed', action='atom',
407 411 conditions=dict(function=check_repo))
408 412
409 413 #==========================================================================
410 414 # REPOSITORY ROUTES
411 415 #==========================================================================
412 416 rmap.connect('summary_home', '/{repo_name:.*?}',
413 417 controller='summary',
414 418 conditions=dict(function=check_repo))
415 419
416 420 rmap.connect('repos_group_home', '/{group_name:.*}',
417 421 controller='admin/repos_groups', action="show_by_name",
418 422 conditions=dict(function=check_group))
419 423
420 424 rmap.connect('changeset_home', '/{repo_name:.*?}/changeset/{revision}',
421 425 controller='changeset', revision='tip',
422 426 conditions=dict(function=check_repo))
423 427
424 428 #still working url for backward compat.
425 429 rmap.connect('raw_changeset_home_depraced',
426 430 '/{repo_name:.*?}/raw-changeset/{revision}',
427 431 controller='changeset', action='changeset_raw',
428 432 revision='tip', conditions=dict(function=check_repo))
429 433
430 434 ## new URLs
431 435 rmap.connect('changeset_raw_home',
432 436 '/{repo_name:.*?}/changeset-diff/{revision}',
433 437 controller='changeset', action='changeset_raw',
434 438 revision='tip', conditions=dict(function=check_repo))
435 439
436 440 rmap.connect('changeset_patch_home',
437 441 '/{repo_name:.*?}/changeset-patch/{revision}',
438 442 controller='changeset', action='changeset_patch',
439 443 revision='tip', conditions=dict(function=check_repo))
440 444
441 445 rmap.connect('changeset_download_home',
442 446 '/{repo_name:.*?}/changeset-download/{revision}',
443 447 controller='changeset', action='changeset_download',
444 448 revision='tip', conditions=dict(function=check_repo))
445 449
446 450 rmap.connect('changeset_comment',
447 451 '/{repo_name:.*?}/changeset/{revision}/comment',
448 452 controller='changeset', revision='tip', action='comment',
449 453 conditions=dict(function=check_repo))
450 454
451 455 rmap.connect('changeset_comment_delete',
452 456 '/{repo_name:.*?}/changeset/comment/{comment_id}/delete',
453 457 controller='changeset', action='delete_comment',
454 458 conditions=dict(function=check_repo, method=["DELETE"]))
455 459
456 460 rmap.connect('changeset_info', '/changeset_info/{repo_name:.*?}/{revision}',
457 461 controller='changeset', action='changeset_info')
458 462
459 463 rmap.connect('compare_url',
460 464 '/{repo_name:.*?}/compare/{org_ref_type}@{org_ref:.*?}...{other_ref_type}@{other_ref:.*?}',
461 465 controller='compare', action='index',
462 466 conditions=dict(function=check_repo),
463 467 requirements=dict(
464 468 org_ref_type='(branch|book|tag|rev|org_ref_type)',
465 469 other_ref_type='(branch|book|tag|rev|other_ref_type)')
466 470 )
467 471
468 472 rmap.connect('pullrequest_home',
469 473 '/{repo_name:.*?}/pull-request/new', controller='pullrequests',
470 474 action='index', conditions=dict(function=check_repo,
471 475 method=["GET"]))
472 476
473 477 rmap.connect('pullrequest',
474 478 '/{repo_name:.*?}/pull-request/new', controller='pullrequests',
475 479 action='create', conditions=dict(function=check_repo,
476 480 method=["POST"]))
477 481
478 482 rmap.connect('pullrequest_show',
479 483 '/{repo_name:.*?}/pull-request/{pull_request_id}',
480 484 controller='pullrequests',
481 485 action='show', conditions=dict(function=check_repo,
482 486 method=["GET"]))
483 487 rmap.connect('pullrequest_update',
484 488 '/{repo_name:.*?}/pull-request/{pull_request_id}',
485 489 controller='pullrequests',
486 490 action='update', conditions=dict(function=check_repo,
487 491 method=["PUT"]))
488 492 rmap.connect('pullrequest_delete',
489 493 '/{repo_name:.*?}/pull-request/{pull_request_id}',
490 494 controller='pullrequests',
491 495 action='delete', conditions=dict(function=check_repo,
492 496 method=["DELETE"]))
493 497
494 498 rmap.connect('pullrequest_show_all',
495 499 '/{repo_name:.*?}/pull-request',
496 500 controller='pullrequests',
497 501 action='show_all', conditions=dict(function=check_repo,
498 502 method=["GET"]))
499 503
500 504 rmap.connect('pullrequest_comment',
501 505 '/{repo_name:.*?}/pull-request-comment/{pull_request_id}',
502 506 controller='pullrequests',
503 507 action='comment', conditions=dict(function=check_repo,
504 508 method=["POST"]))
505 509
506 510 rmap.connect('pullrequest_comment_delete',
507 511 '/{repo_name:.*?}/pull-request-comment/{comment_id}/delete',
508 512 controller='pullrequests', action='delete_comment',
509 513 conditions=dict(function=check_repo, method=["DELETE"]))
510 514
511 515 rmap.connect('summary_home', '/{repo_name:.*?}/summary',
512 516 controller='summary', conditions=dict(function=check_repo))
513 517
514 518 rmap.connect('shortlog_home', '/{repo_name:.*?}/shortlog',
515 519 controller='shortlog', conditions=dict(function=check_repo))
516 520
517 521 rmap.connect('shortlog_file_home', '/{repo_name:.*?}/shortlog/{revision}/{f_path:.*}',
518 522 controller='shortlog', f_path=None,
519 523 conditions=dict(function=check_repo))
520 524
521 525 rmap.connect('branches_home', '/{repo_name:.*?}/branches',
522 526 controller='branches', conditions=dict(function=check_repo))
523 527
524 528 rmap.connect('tags_home', '/{repo_name:.*?}/tags',
525 529 controller='tags', conditions=dict(function=check_repo))
526 530
527 531 rmap.connect('bookmarks_home', '/{repo_name:.*?}/bookmarks',
528 532 controller='bookmarks', conditions=dict(function=check_repo))
529 533
530 534 rmap.connect('changelog_home', '/{repo_name:.*?}/changelog',
531 535 controller='changelog', conditions=dict(function=check_repo))
532 536
533 537 rmap.connect('changelog_details', '/{repo_name:.*?}/changelog_details/{cs}',
534 538 controller='changelog', action='changelog_details',
535 539 conditions=dict(function=check_repo))
536 540
537 541 rmap.connect('files_home', '/{repo_name:.*?}/files/{revision}/{f_path:.*}',
538 542 controller='files', revision='tip', f_path='',
539 543 conditions=dict(function=check_repo))
540 544
541 545 rmap.connect('files_history_home',
542 546 '/{repo_name:.*?}/history/{revision}/{f_path:.*}',
543 547 controller='files', action='history', revision='tip', f_path='',
544 548 conditions=dict(function=check_repo))
545 549
546 550 rmap.connect('files_diff_home', '/{repo_name:.*?}/diff/{f_path:.*}',
547 551 controller='files', action='diff', revision='tip', f_path='',
548 552 conditions=dict(function=check_repo))
549 553
550 554 rmap.connect('files_rawfile_home',
551 555 '/{repo_name:.*?}/rawfile/{revision}/{f_path:.*}',
552 556 controller='files', action='rawfile', revision='tip',
553 557 f_path='', conditions=dict(function=check_repo))
554 558
555 559 rmap.connect('files_raw_home',
556 560 '/{repo_name:.*?}/raw/{revision}/{f_path:.*}',
557 561 controller='files', action='raw', revision='tip', f_path='',
558 562 conditions=dict(function=check_repo))
559 563
560 564 rmap.connect('files_annotate_home',
561 565 '/{repo_name:.*?}/annotate/{revision}/{f_path:.*}',
562 566 controller='files', action='index', revision='tip',
563 567 f_path='', annotate=True, conditions=dict(function=check_repo))
564 568
565 569 rmap.connect('files_edit_home',
566 570 '/{repo_name:.*?}/edit/{revision}/{f_path:.*}',
567 571 controller='files', action='edit', revision='tip',
568 572 f_path='', conditions=dict(function=check_repo))
569 573
570 574 rmap.connect('files_add_home',
571 575 '/{repo_name:.*?}/add/{revision}/{f_path:.*}',
572 576 controller='files', action='add', revision='tip',
573 577 f_path='', conditions=dict(function=check_repo))
574 578
575 579 rmap.connect('files_archive_home', '/{repo_name:.*?}/archive/{fname}',
576 580 controller='files', action='archivefile',
577 581 conditions=dict(function=check_repo))
578 582
579 583 rmap.connect('files_nodelist_home',
580 584 '/{repo_name:.*?}/nodelist/{revision}/{f_path:.*}',
581 585 controller='files', action='nodelist',
582 586 conditions=dict(function=check_repo))
583 587
584 588 rmap.connect('repo_settings_delete', '/{repo_name:.*?}/settings',
585 589 controller='settings', action="delete",
586 590 conditions=dict(method=["DELETE"], function=check_repo))
587 591
588 592 rmap.connect('repo_settings_update', '/{repo_name:.*?}/settings',
589 593 controller='settings', action="update",
590 594 conditions=dict(method=["PUT"], function=check_repo))
591 595
592 596 rmap.connect('repo_settings_home', '/{repo_name:.*?}/settings',
593 597 controller='settings', action='index',
594 598 conditions=dict(function=check_repo))
595 599
596 600 rmap.connect('toggle_locking', "/{repo_name:.*?}/locking_toggle",
597 601 controller='settings', action="toggle_locking",
598 602 conditions=dict(method=["GET"], function=check_repo))
599 603
600 604 rmap.connect('repo_fork_create_home', '/{repo_name:.*?}/fork',
601 605 controller='forks', action='fork_create',
602 606 conditions=dict(function=check_repo, method=["POST"]))
603 607
604 608 rmap.connect('repo_fork_home', '/{repo_name:.*?}/fork',
605 609 controller='forks', action='fork',
606 610 conditions=dict(function=check_repo))
607 611
608 612 rmap.connect('repo_forks_home', '/{repo_name:.*?}/forks',
609 613 controller='forks', action='forks',
610 614 conditions=dict(function=check_repo))
611 615
612 616 rmap.connect('repo_followers_home', '/{repo_name:.*?}/followers',
613 617 controller='followers', action='followers',
614 618 conditions=dict(function=check_repo))
615 619
616 620 return rmap
@@ -1,104 +1,103 b''
1 1 # -*- coding: utf-8 -*-
2 2 """
3 3 rhodecode.controllers.shortlog
4 4 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
5 5
6 6 Shortlog controller for rhodecode
7 7
8 8 :created_on: Apr 18, 2010
9 9 :author: marcink
10 10 :copyright: (C) 2010-2012 Marcin Kuzminski <marcin@python-works.com>
11 11 :license: GPLv3, see COPYING for more details.
12 12 """
13 13 # This program is free software: you can redistribute it and/or modify
14 14 # it under the terms of the GNU General Public License as published by
15 15 # the Free Software Foundation, either version 3 of the License, or
16 16 # (at your option) any later version.
17 17 #
18 18 # This program is distributed in the hope that it will be useful,
19 19 # but WITHOUT ANY WARRANTY; without even the implied warranty of
20 20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 21 # GNU General Public License for more details.
22 22 #
23 23 # You should have received a copy of the GNU General Public License
24 24 # along with this program. If not, see <http://www.gnu.org/licenses/>.
25 25
26 26 import logging
27 27
28 28 from pylons import tmpl_context as c, request, url
29 29 from pylons.i18n.translation import _
30 30
31 31 from rhodecode.lib import helpers as h
32 32 from rhodecode.lib.auth import LoginRequired, HasRepoPermissionAnyDecorator
33 33 from rhodecode.lib.base import BaseRepoController, render
34 34 from rhodecode.lib.helpers import RepoPage
35 35 from pylons.controllers.util import redirect
36 36 from rhodecode.lib.utils2 import safe_int
37 37 from rhodecode.lib.vcs.exceptions import NodeDoesNotExistError, ChangesetError,\
38 38 RepositoryError
39 39
40 40 log = logging.getLogger(__name__)
41 41
42 42
43 43 class ShortlogController(BaseRepoController):
44 44
45 45 @LoginRequired()
46 46 @HasRepoPermissionAnyDecorator('repository.read', 'repository.write',
47 47 'repository.admin')
48 48 def __before__(self):
49 49 super(ShortlogController, self).__before__()
50 50
51 51 def __get_cs_or_redirect(self, rev, repo_name, redirect_after=True):
52 52 """
53 53 Safe way to get changeset if error occur it redirects to tip with
54 54 proper message
55 55
56 56 :param rev: revision to fetch
57 57 :param repo_name: repo name to redirect after
58 58 """
59 59
60 60 try:
61 61 return c.rhodecode_repo.get_changeset(rev)
62 62 except RepositoryError, e:
63 63 h.flash(str(e), category='warning')
64 64 redirect(h.url('shortlog_home', repo_name=repo_name))
65 65
66 66 def index(self, repo_name, revision=None, f_path=None):
67 67 p = safe_int(request.params.get('page', 1), 1)
68 68 size = safe_int(request.params.get('size', 20), 20)
69 69
70 70 def url_generator(**kw):
71 71 return url('shortlog_home', repo_name=repo_name, size=size, **kw)
72 72
73 73 collection = c.rhodecode_repo
74 74 c.file_history = f_path
75 75 if f_path:
76 f_path = f_path.lstrip('/')
77 76 # get the history for the file !
78 77 tip_cs = c.rhodecode_repo.get_changeset()
79 78 try:
80 79 collection = tip_cs.get_file_history(f_path)
81 80 except (NodeDoesNotExistError, ChangesetError):
82 81 #this node is not present at tip !
83 82 try:
84 83 cs = self.__get_cs_or_redirect(revision, repo_name)
85 84 collection = cs.get_file_history(f_path)
86 85 except RepositoryError, e:
87 86 h.flash(str(e), category='warning')
88 87 redirect(h.url('shortlog_home', repo_name=repo_name))
89 88 collection = list(reversed(collection))
90 89
91 90 c.repo_changesets = RepoPage(collection, page=p,
92 91 items_per_page=size, url=url_generator)
93 92 page_revisions = [x.raw_id for x in list(collection)]
94 93 c.statuses = c.rhodecode_db_repo.statuses(page_revisions)
95 94
96 95 if not c.repo_changesets:
97 96 h.flash(_('There are no changesets yet'), category='warning')
98 97 return redirect(url('summary_home', repo_name=repo_name))
99 98
100 99 c.shortlog_data = render('shortlog/shortlog_data.html')
101 100 if request.environ.get('HTTP_X_PARTIAL_XHR'):
102 101 return c.shortlog_data
103 102 r = render('shortlog/shortlog.html')
104 103 return r
General Comments 0
You need to be logged in to leave comments. Login now