OSDN Git Service

Refactor: use :id instead of :page when linking to Wiki Pages
[redminele/redmine.git] / config / routes.rb
1 ActionController::Routing::Routes.draw do |map|
2   # Add your own custom routes here.
3   # The priority is based upon order of creation: first created -> highest priority.
4   
5   # Here's a sample route:
6   # map.connect 'products/:id', :controller => 'catalog', :action => 'view'
7   # Keep in mind you can assign values other than :controller and :action
8
9   map.home '', :controller => 'welcome'
10   
11   map.signin 'login', :controller => 'account', :action => 'login'
12   map.signout 'logout', :controller => 'account', :action => 'logout'
13   
14   map.connect 'roles/workflow/:id/:role_id/:tracker_id', :controller => 'roles', :action => 'workflow'
15   map.connect 'help/:ctrl/:page', :controller => 'help'
16
17   map.connect 'projects/:project_id/time_entries/report', :controller => 'time_entry_reports', :action => 'report'
18   map.with_options :controller => 'time_entry_reports', :action => 'report',:conditions => {:method => :get} do |time_report|
19     time_report.connect 'time_entries/report'
20     time_report.connect 'time_entries/report.:format'
21     time_report.connect 'projects/:project_id/time_entries/report.:format'
22   end
23
24   # TODO: wasteful since this is also nested under issues, projects, and projects/issues
25   map.resources :time_entries, :controller => 'timelog'
26   
27   map.connect 'projects/:id/wiki', :controller => 'wikis', :action => 'edit', :conditions => {:method => :post}
28   map.connect 'projects/:id/wiki/destroy', :controller => 'wikis', :action => 'destroy', :conditions => {:method => :get}
29   map.connect 'projects/:id/wiki/destroy', :controller => 'wikis', :action => 'destroy', :conditions => {:method => :post}
30   map.with_options :controller => 'wiki' do |wiki_routes|
31     wiki_routes.with_options :conditions => {:method => :get} do |wiki_views|
32       wiki_views.connect 'projects/:project_id/wiki/export', :action => 'export'
33       wiki_views.connect 'projects/:project_id/wiki/index', :action => 'index'
34       wiki_views.connect 'projects/:project_id/wiki/date_index', :action => 'date_index'
35       wiki_views.connect 'projects/:project_id/wiki/:id', :action => 'show', :id => nil
36       wiki_views.connect 'projects/:project_id/wiki/:id/edit', :action => 'edit'
37       wiki_views.connect 'projects/:project_id/wiki/:id/rename', :action => 'rename'
38       wiki_views.connect 'projects/:project_id/wiki/:id/history', :action => 'history'
39       wiki_views.connect 'projects/:project_id/wiki/:id/diff/:version/vs/:version_from', :action => 'diff'
40       wiki_views.connect 'projects/:project_id/wiki/:id/annotate/:version', :action => 'annotate'
41     end
42     
43     wiki_routes.connect 'projects/:project_id/wiki/:id/:action', 
44       :action => /rename|preview|protect|add_attachment/,
45       :conditions => {:method => :post}
46
47     wiki_routes.connect 'projects/:project_id/wiki/:id/edit', :action => 'update', :conditions => {:method => :post}
48
49     wiki_routes.connect 'projects/:project_id/wiki/:id', :action => 'destroy', :conditions => {:method => :delete}
50   end
51   
52   map.with_options :controller => 'messages' do |messages_routes|
53     messages_routes.with_options :conditions => {:method => :get} do |messages_views|
54       messages_views.connect 'boards/:board_id/topics/new', :action => 'new'
55       messages_views.connect 'boards/:board_id/topics/:id', :action => 'show'
56       messages_views.connect 'boards/:board_id/topics/:id/edit', :action => 'edit'
57     end
58     messages_routes.with_options :conditions => {:method => :post} do |messages_actions|
59       messages_actions.connect 'boards/:board_id/topics/new', :action => 'new'
60       messages_actions.connect 'boards/:board_id/topics/:id/replies', :action => 'reply'
61       messages_actions.connect 'boards/:board_id/topics/:id/:action', :action => /edit|destroy/
62     end
63   end
64   
65   map.with_options :controller => 'boards' do |board_routes|
66     board_routes.with_options :conditions => {:method => :get} do |board_views|
67       board_views.connect 'projects/:project_id/boards', :action => 'index'
68       board_views.connect 'projects/:project_id/boards/new', :action => 'new'
69       board_views.connect 'projects/:project_id/boards/:id', :action => 'show'
70       board_views.connect 'projects/:project_id/boards/:id.:format', :action => 'show'
71       board_views.connect 'projects/:project_id/boards/:id/edit', :action => 'edit'
72     end
73     board_routes.with_options :conditions => {:method => :post} do |board_actions|
74       board_actions.connect 'projects/:project_id/boards', :action => 'new'
75       board_actions.connect 'projects/:project_id/boards/:id/:action', :action => /edit|destroy/
76     end
77   end
78   
79   map.with_options :controller => 'documents' do |document_routes|
80     document_routes.with_options :conditions => {:method => :get} do |document_views|
81       document_views.connect 'projects/:project_id/documents', :action => 'index'
82       document_views.connect 'projects/:project_id/documents/new', :action => 'new'
83       document_views.connect 'documents/:id', :action => 'show'
84       document_views.connect 'documents/:id/edit', :action => 'edit'
85     end
86     document_routes.with_options :conditions => {:method => :post} do |document_actions|
87       document_actions.connect 'projects/:project_id/documents', :action => 'new'
88       document_actions.connect 'documents/:id/:action', :action => /destroy|edit/
89     end
90   end
91
92   map.resources :issue_moves, :only => [:new, :create], :path_prefix => '/issues', :as => 'move'
93
94   # Misc issue routes. TODO: move into resources
95   map.auto_complete_issues '/issues/auto_complete', :controller => 'auto_completes', :action => 'issues'
96   map.preview_issue '/issues/preview/:id', :controller => 'previews', :action => 'issue' # TODO: would look nicer as /issues/:id/preview
97   map.issues_context_menu '/issues/context_menu', :controller => 'context_menus', :action => 'issues'
98   map.issue_changes '/issues/changes', :controller => 'journals', :action => 'index'
99   map.bulk_edit_issue 'issues/bulk_edit', :controller => 'issues', :action => 'bulk_edit', :conditions => { :method => :get }
100   map.bulk_update_issue 'issues/bulk_edit', :controller => 'issues', :action => 'bulk_update', :conditions => { :method => :post }
101   map.quoted_issue '/issues/:id/quoted', :controller => 'journals', :action => 'new', :id => /\d+/, :conditions => { :method => :post }
102   map.connect '/issues/:id/destroy', :controller => 'issues', :action => 'destroy', :conditions => { :method => :post } # legacy
103
104   map.resource :gantt, :path_prefix => '/issues', :controller => 'gantts', :only => [:show, :update]
105   map.resource :gantt, :path_prefix => '/projects/:project_id/issues', :controller => 'gantts', :only => [:show, :update]
106   map.resource :calendar, :path_prefix => '/issues', :controller => 'calendars', :only => [:show, :update]
107   map.resource :calendar, :path_prefix => '/projects/:project_id/issues', :controller => 'calendars', :only => [:show, :update]
108
109   map.with_options :controller => 'reports', :conditions => {:method => :get} do |reports|
110     reports.connect 'projects/:id/issues/report', :action => 'issue_report'
111     reports.connect 'projects/:id/issues/report/:detail', :action => 'issue_report_details'
112   end
113
114   # Following two routes conflict with the resources because #index allows POST
115   map.connect '/issues', :controller => 'issues', :action => 'index', :conditions => { :method => :post }
116   map.connect '/issues/create', :controller => 'issues', :action => 'index', :conditions => { :method => :post }
117   
118   map.resources :issues, :member => { :edit => :post }, :collection => {} do |issues|
119     issues.resources :time_entries, :controller => 'timelog'
120   end
121   
122   map.resources :issues, :path_prefix => '/projects/:project_id', :collection => { :create => :post } do |issues|
123     issues.resources :time_entries, :controller => 'timelog'
124   end
125
126   map.with_options  :controller => 'issue_relations', :conditions => {:method => :post} do |relations|
127     relations.connect 'issues/:issue_id/relations/:id', :action => 'new'
128     relations.connect 'issues/:issue_id/relations/:id/destroy', :action => 'destroy'
129   end
130
131   map.connect 'projects/:id/members/new', :controller => 'members', :action => 'new'
132
133   map.with_options :controller => 'users' do |users|
134     users.connect 'users/:id/edit/:tab', :action => 'edit', :tab => nil, :conditions => {:method => :get}
135     
136     users.with_options :conditions => {:method => :post} do |user_actions|
137       user_actions.connect 'users/:id/memberships', :action => 'edit_membership'
138       user_actions.connect 'users/:id/memberships/:membership_id', :action => 'edit_membership'
139       user_actions.connect 'users/:id/memberships/:membership_id/destroy', :action => 'destroy_membership'
140     end
141   end
142
143   map.resources :users, :member => {
144     :edit_membership => :post,
145     :destroy_membership => :post
146   },
147   :except => [:destroy]
148
149   # For nice "roadmap" in the url for the index action
150   map.connect 'projects/:project_id/roadmap', :controller => 'versions', :action => 'index'
151
152   map.all_news 'news', :controller => 'news', :action => 'index'
153   map.formatted_all_news 'news.:format', :controller => 'news', :action => 'index'
154   map.preview_news '/news/preview', :controller => 'previews', :action => 'news'
155   map.connect 'news/:id/comments', :controller => 'comments', :action => 'create', :conditions => {:method => :post}
156   map.connect 'news/:id/comments/:comment_id', :controller => 'comments', :action => 'destroy', :conditions => {:method => :delete}
157
158   map.resources :projects, :member => {
159     :copy => [:get, :post],
160     :settings => :get,
161     :modules => :post,
162     :archive => :post,
163     :unarchive => :post
164   } do |project|
165     project.resource :project_enumerations, :as => 'enumerations', :only => [:update, :destroy]
166     project.resources :files, :only => [:index, :new, :create]
167     project.resources :versions, :collection => {:close_completed => :put}, :member => {:status_by => :post}
168     project.resources :news, :shallow => true
169     project.resources :time_entries, :controller => 'timelog', :path_prefix => 'projects/:project_id'
170
171     
172   end
173
174   # Destroy uses a get request to prompt the user before the actual DELETE request
175   map.project_destroy_confirm 'projects/:id/destroy', :controller => 'projects', :action => 'destroy', :conditions => {:method => :get}
176
177   # TODO: port to be part of the resources route(s)
178   map.with_options :controller => 'projects' do |project_mapper|
179     project_mapper.with_options :conditions => {:method => :get} do |project_views|
180       project_views.connect 'projects/:id/settings/:tab', :controller => 'projects', :action => 'settings'
181       project_views.connect 'projects/:project_id/issues/:copy_from/copy', :controller => 'issues', :action => 'new'
182     end
183   end
184   
185   map.with_options :controller => 'activities', :action => 'index', :conditions => {:method => :get} do |activity|
186     activity.connect 'projects/:id/activity'
187     activity.connect 'projects/:id/activity.:format'
188     activity.connect 'activity', :id => nil
189     activity.connect 'activity.:format', :id => nil
190   end
191
192     
193   map.with_options :controller => 'issue_categories' do |categories|
194     categories.connect 'projects/:project_id/issue_categories/new', :action => 'new'
195   end
196   
197   map.with_options :controller => 'repositories' do |repositories|
198     repositories.with_options :conditions => {:method => :get} do |repository_views|
199       repository_views.connect 'projects/:id/repository', :action => 'show'
200       repository_views.connect 'projects/:id/repository/edit', :action => 'edit'
201       repository_views.connect 'projects/:id/repository/statistics', :action => 'stats'
202       repository_views.connect 'projects/:id/repository/revisions', :action => 'revisions'
203       repository_views.connect 'projects/:id/repository/revisions.:format', :action => 'revisions'
204       repository_views.connect 'projects/:id/repository/revisions/:rev', :action => 'revision'
205       repository_views.connect 'projects/:id/repository/revisions/:rev/diff', :action => 'diff'
206       repository_views.connect 'projects/:id/repository/revisions/:rev/diff.:format', :action => 'diff'
207       repository_views.connect 'projects/:id/repository/revisions/:rev/raw/*path', :action => 'entry', :format => 'raw', :requirements => { :rev => /[a-z0-9\.\-_]+/ }
208       repository_views.connect 'projects/:id/repository/revisions/:rev/:action/*path', :requirements => { :rev => /[a-z0-9\.\-_]+/ }
209       repository_views.connect 'projects/:id/repository/raw/*path', :action => 'entry', :format => 'raw'
210       # TODO: why the following route is required?
211       repository_views.connect 'projects/:id/repository/entry/*path', :action => 'entry'
212       repository_views.connect 'projects/:id/repository/:action/*path'
213     end
214     
215     repositories.connect 'projects/:id/repository/:action', :conditions => {:method => :post}
216   end
217   
218   map.connect 'attachments/:id', :controller => 'attachments', :action => 'show', :id => /\d+/
219   map.connect 'attachments/:id/:filename', :controller => 'attachments', :action => 'show', :id => /\d+/, :filename => /.*/
220   map.connect 'attachments/download/:id/:filename', :controller => 'attachments', :action => 'download', :id => /\d+/, :filename => /.*/
221    
222   map.resources :groups
223   
224   #left old routes at the bottom for backwards compat
225   map.connect 'projects/:project_id/issues/:action', :controller => 'issues'
226   map.connect 'projects/:project_id/documents/:action', :controller => 'documents'
227   map.connect 'projects/:project_id/boards/:action/:id', :controller => 'boards'
228   map.connect 'boards/:board_id/topics/:action/:id', :controller => 'messages'
229   map.connect 'wiki/:id/:page/:action', :page => nil, :controller => 'wiki'
230   map.connect 'issues/:issue_id/relations/:action/:id', :controller => 'issue_relations'
231   map.connect 'projects/:project_id/news/:action', :controller => 'news'  
232   map.connect 'projects/:project_id/timelog/:action/:id', :controller => 'timelog', :project_id => /.+/
233   map.with_options :controller => 'repositories' do |omap|
234     omap.repositories_show 'repositories/browse/:id/*path', :action => 'browse'
235     omap.repositories_changes 'repositories/changes/:id/*path', :action => 'changes'
236     omap.repositories_diff 'repositories/diff/:id/*path', :action => 'diff'
237     omap.repositories_entry 'repositories/entry/:id/*path', :action => 'entry'
238     omap.repositories_entry 'repositories/annotate/:id/*path', :action => 'annotate'
239     omap.connect 'repositories/revision/:id/:rev', :action => 'revision'
240   end
241   
242   map.with_options :controller => 'sys' do |sys|
243     sys.connect 'sys/projects.:format', :action => 'projects', :conditions => {:method => :get}
244     sys.connect 'sys/projects/:id/repository.:format', :action => 'create_project_repository', :conditions => {:method => :post}
245   end
246  
247   # Install the default route as the lowest priority.
248   map.connect ':controller/:action/:id'
249   map.connect 'robots.txt', :controller => 'welcome', :action => 'robots'
250   # Used for OpenID
251   map.root :controller => 'account', :action => 'login'
252 end