]> git.openstreetmap.org Git - rails.git/blob - config/routes.rb
Make api create changeset path resourceful
[rails.git] / config / routes.rb
1 OpenStreetMap::Application.routes.draw do
2   use_doorkeeper :scope => "oauth2" do
3     controllers :authorizations => "oauth2_authorizations",
4                 :applications => "oauth2_applications",
5                 :authorized_applications => "oauth2_authorized_applications"
6   end
7
8   use_doorkeeper_openid_connect :scope => "oauth2" if Settings.key?(:doorkeeper_signing_key)
9
10   # API
11   namespace :api do
12     get "capabilities" => "capabilities#show" # Deprecated, remove when 0.6 support is removed
13     get "versions" => "versions#show"
14   end
15
16   scope "api/0.6", :module => :api do
17     get "capabilities" => "capabilities#show"
18     get "permissions" => "permissions#show"
19
20     post "changeset/:id/upload" => "changesets#upload", :as => :changeset_upload, :id => /\d+/
21     get "changeset/:id/download" => "changesets#download", :as => :changeset_download, :id => /\d+/
22     get "changeset/:id" => "changesets#show", :as => :changeset_show, :id => /\d+/
23     post "changeset/:id/subscribe" => "changesets#subscribe", :as => :api_changeset_subscribe, :id => /\d+/
24     post "changeset/:id/unsubscribe" => "changesets#unsubscribe", :as => :api_changeset_unsubscribe, :id => /\d+/
25     put "changeset/:id" => "changesets#update", :id => /\d+/
26     put "changeset/:id/close" => "changesets#close", :as => :changeset_close, :id => /\d+/
27     get "changesets" => "changesets#index"
28     post "changeset/:id/comment" => "changeset_comments#create", :as => :changeset_comment, :id => /\d+/
29     post "changeset/comment/:id/hide" => "changeset_comments#destroy", :as => :changeset_comment_hide, :id => /\d+/
30     post "changeset/comment/:id/unhide" => "changeset_comments#restore", :as => :changeset_comment_unhide, :id => /\d+/
31   end
32
33   namespace :api, :path => "api/0.6" do
34     resources :changesets, :only => :create
35     put "changeset/create" => "changesets#create", :as => nil
36
37     resources :changeset_comments, :only => :index
38
39     resources :nodes, :only => [:index, :create]
40     resources :nodes, :path => "node", :id => /\d+/, :only => [:show, :update, :destroy] do
41       scope :module => :nodes do
42         resources :ways, :only => :index
43         resources :relations, :only => :index
44       end
45       resources :versions, :path => "history", :controller => :old_nodes, :only => :index
46       resource :version, :path => ":version", :version => /\d+/, :controller => :old_nodes, :only => :show do
47         resource :redaction, :module => :old_nodes, :only => [:create, :destroy]
48       end
49     end
50     put "node/create" => "nodes#create", :as => nil
51     post "node/:node_id/:version/redact" => "old_nodes/redactions#create", :node_id => /\d+/, :version => /\d+/, :allow_delete => true, :as => nil
52
53     resources :ways, :only => [:index, :create]
54     resources :ways, :path => "way", :id => /\d+/, :only => [:show, :update, :destroy] do
55       member do
56         get :full, :action => :show, :full => true, :as => nil
57       end
58       scope :module => :ways do
59         resources :relations, :only => :index
60       end
61       resources :versions, :path => "history", :controller => :old_ways, :only => :index
62       resource :version, :path => ":version", :version => /\d+/, :controller => :old_ways, :only => :show do
63         resource :redaction, :module => :old_ways, :only => [:create, :destroy]
64       end
65     end
66     put "way/create" => "ways#create", :as => nil
67     post "way/:way_id/:version/redact" => "old_ways/redactions#create", :way_id => /\d+/, :version => /\d+/, :allow_delete => true, :as => nil
68
69     resources :relations, :only => [:index, :create]
70     resources :relations, :path => "relation", :id => /\d+/, :only => [:show, :update, :destroy] do
71       member do
72         get :full, :action => :show, :full => true, :as => nil
73       end
74       scope :module => :relations do
75         resources :relations, :only => :index
76       end
77       resources :versions, :path => "history", :controller => :old_relations, :only => :index
78       resource :version, :path => ":version", :version => /\d+/, :controller => :old_relations, :only => :show do
79         resource :redaction, :module => :old_relations, :only => [:create, :destroy]
80       end
81     end
82     put "relation/create" => "relations#create", :as => nil
83     post "relation/:relation_id/:version/redact" => "old_relations/redactions#create", :relation_id => /\d+/, :version => /\d+/, :allow_delete => true, :as => nil
84
85     resource :map, :only => :show
86
87     resources :tracepoints, :path => "trackpoints", :only => :index
88
89     resources :users, :only => :index
90     resources :users, :path => "user", :id => /\d+/, :only => :show
91     resources :user_traces, :path => "user/gpx_files", :module => :users, :controller => :traces, :only => :index
92     get "user/details" => "users#details"
93
94     resources :user_preferences, :except => [:new, :create, :edit], :param => :preference_key, :path => "user/preferences" do
95       collection do
96         put "" => "user_preferences#update_all", :as => ""
97       end
98     end
99
100     resources :messages, :path => "user/messages", :constraints => { :id => /\d+/ }, :only => [:create, :show, :update, :destroy]
101     namespace :messages, :path => "user/messages" do
102       resource :inbox, :only => :show
103       resource :outbox, :only => :show
104     end
105     post "/user/messages/:id" => "messages#update", :as => nil
106
107     resources :traces, :path => "gpx", :only => [:create, :show, :update, :destroy], :id => /\d+/ do
108       scope :module => :traces do
109         resource :data, :only => :show
110       end
111     end
112     post "gpx/create" => "traces#create", :id => /\d+/, :as => :trace_create
113     get "gpx/:id/details" => "traces#show", :id => /\d+/, :as => :trace_details
114
115     # Map notes API
116     resources :notes, :except => [:new, :edit, :update], :id => /\d+/, :controller => "notes" do
117       collection do
118         get "search"
119         get "feed", :defaults => { :format => "rss" }
120       end
121
122       member do
123         post "comment"
124         post "close"
125         post "reopen"
126       end
127
128       resource :subscription, :only => [:create, :destroy], :controller => "note_subscriptions"
129     end
130
131     resources :user_blocks, :only => [:show, :create], :id => /\d+/, :controller => "user_blocks"
132     namespace :user_blocks, :path => "user/blocks" do
133       resource :active_list, :path => "active", :only => :show
134     end
135   end
136
137   # Data browsing
138   get "/way/:id" => "ways#show", :id => /\d+/, :as => :way
139   get "/way/:id/history" => "old_ways#index", :id => /\d+/, :as => :way_history
140   resources :old_ways, :path => "/way/:id/history", :id => /\d+/, :version => /\d+/, :param => :version, :only => :show
141   get "/node/:id" => "nodes#show", :id => /\d+/, :as => :node
142   get "/node/:id/history" => "old_nodes#index", :id => /\d+/, :as => :node_history
143   resources :old_nodes, :path => "/node/:id/history", :id => /\d+/, :version => /\d+/, :param => :version, :only => :show
144   get "/relation/:id" => "relations#show", :id => /\d+/, :as => :relation
145   get "/relation/:id/history" => "old_relations#index", :id => /\d+/, :as => :relation_history
146   resources :old_relations, :path => "/relation/:id/history", :id => /\d+/, :version => /\d+/, :param => :version, :only => :show
147
148   resources :changesets, :path => "changeset", :id => /\d+/, :only => :show do
149     resource :subscription, :controller => :changeset_subscriptions, :only => [:show, :create, :destroy]
150     namespace :changeset_comments, :as => :comments, :path => :comments do
151       resource :feed, :only => :show, :defaults => { :format => "rss" }
152     end
153   end
154   get "/changeset/:id/subscribe", :id => /\d+/, :to => redirect(:path => "/changeset/%{id}/subscription")
155   get "/changeset/:id/unsubscribe", :id => /\d+/, :to => redirect(:path => "/changeset/%{id}/subscription")
156
157   resources :notes, :path => "note", :id => /\d+/, :only => [:show, :new]
158
159   get "/user/:display_name/history" => "changesets#index"
160   get "/user/:display_name/history/feed" => "changesets#feed", :defaults => { :format => :atom }
161   get "/user/:display_name/notes" => "notes#index", :as => :user_notes
162   get "/history/friends" => "changesets#index", :friends => true, :as => "friend_changesets", :defaults => { :format => :html }
163   get "/history/nearby" => "changesets#index", :nearby => true, :as => "nearby_changesets", :defaults => { :format => :html }
164
165   get "/browse/way/:id",                :to => redirect(:path => "/way/%{id}")
166   get "/browse/way/:id/history",        :to => redirect(:path => "/way/%{id}/history")
167   get "/browse/node/:id",               :to => redirect(:path => "/node/%{id}")
168   get "/browse/node/:id/history",       :to => redirect(:path => "/node/%{id}/history")
169   get "/browse/relation/:id",           :to => redirect(:path => "/relation/%{id}")
170   get "/browse/relation/:id/history",   :to => redirect(:path => "/relation/%{id}/history")
171   get "/browse/changeset/:id",          :to => redirect(:path => "/changeset/%{id}")
172   get "/browse/note/:id",               :to => redirect(:path => "/note/%{id}")
173   get "/user/:display_name/edits",      :to => redirect(:path => "/user/%{display_name}/history")
174   get "/user/:display_name/edits/feed", :to => redirect(:path => "/user/%{display_name}/history/feed")
175   get "/browse/friends",                :to => redirect(:path => "/history/friends")
176   get "/browse/nearby",                 :to => redirect(:path => "/history/nearby")
177   get "/browse/changesets/feed",        :to => redirect(:path => "/history/feed")
178   get "/browse/changesets",             :to => redirect(:path => "/history")
179   get "/browse",                        :to => redirect(:path => "/history")
180
181   # web site
182   root :to => "site#index", :via => [:get, :post]
183   get "/edit" => "site#edit"
184   get "/copyright/:copyright_locale" => "site#copyright"
185   get "/copyright" => "site#copyright"
186   get "/welcome" => "site#welcome"
187   get "/fixthemap" => "site#fixthemap"
188   get "/help" => "site#help"
189   get "/about/:about_locale" => "site#about"
190   get "/about" => "site#about"
191   get "/communities" => "site#communities"
192   get "/history" => "changesets#index"
193   get "/history/feed" => "changesets#feed", :defaults => { :format => :atom }
194   scope "/history" do
195     namespace :changeset_comments, :path => :comments, :as => :changesets_comments do
196       resource :feed, :only => :show, :defaults => { :format => "rss" }
197     end
198   end
199   get "/export" => "site#export"
200   get "/login" => "sessions#new"
201   post "/login" => "sessions#create"
202   match "/logout" => "sessions#destroy", :via => [:get, :post]
203   get "/offline" => "site#offline"
204   get "/key" => "site#key"
205   get "/id" => "site#id"
206   get "/query" => "browse#query"
207   post "/user/:display_name/confirm/resend" => "confirmations#confirm_resend", :as => :user_confirm_resend
208   match "/user/:display_name/confirm" => "confirmations#confirm", :via => [:get, :post]
209   match "/user/confirm" => "confirmations#confirm", :via => [:get, :post]
210   match "/user/confirm-email" => "confirmations#confirm_email", :via => [:get, :post]
211   post "/user/go_public" => "users#go_public"
212   scope :user, :as => "user" do
213     get "forgot-password" => "passwords#new"
214     post "forgot-password" => "passwords#create"
215     get "reset-password" => "passwords#edit"
216     post "reset-password" => "passwords#update"
217   end
218   get "/user/suspended" => "users#suspended"
219
220   get "/index.html", :to => redirect(:path => "/")
221   get "/create-account.html", :to => redirect(:path => "/user/new")
222   get "/forgot-password.html", :to => redirect(:path => "/user/forgot-password")
223
224   # omniauth
225   get "/auth/failure" => "users#auth_failure"
226   match "/auth/:provider/callback" => "users#auth_success", :via => [:get, :post], :as => :auth_success
227   match "/auth/:provider" => "users#auth", :via => [:post, :patch], :as => :auth
228
229   # permalink
230   get "/go/:code" => "site#permalink", :code => /[a-zA-Z0-9_@~]+[=-]*/, :as => :permalink
231
232   # rich text preview
233   post "/preview/:type" => "site#preview", :as => :preview
234
235   # traces
236   resources :traces, :id => /\d+/, :except => [:show] do
237     resource :data, :module => :traces, :only => :show
238   end
239   get "/user/:display_name/traces/tag/:tag/page/:page", :page => /[1-9][0-9]*/, :to => redirect(:path => "/user/%{display_name}/traces/tag/%{tag}")
240   get "/user/:display_name/traces/tag/:tag" => "traces#index"
241   get "/user/:display_name/traces/page/:page", :page => /[1-9][0-9]*/, :to => redirect(:path => "/user/%{display_name}/traces")
242   get "/user/:display_name/traces" => "traces#index"
243   get "/user/:display_name/traces/:id" => "traces#show", :id => /\d+/, :as => "show_trace"
244   scope "/user/:display_name/traces/:trace_id", :module => :traces, :trace_id => /\d+/ do
245     get "picture" => "pictures#show", :as => "trace_picture"
246     get "icon" => "icons#show", :as => "trace_icon"
247   end
248   get "/traces/tag/:tag/page/:page", :page => /[1-9][0-9]*/, :to => redirect(:path => "/traces/tag/%{tag}")
249   get "/traces/tag/:tag" => "traces#index"
250   get "/traces/page/:page", :page => /[1-9][0-9]*/, :to => redirect(:path => "/traces")
251   get "/traces/mine/tag/:tag/page/:page", :page => /[1-9][0-9]*/, :to => redirect(:path => "/traces/mine/tag/%{tag}")
252   get "/traces/mine/tag/:tag" => "traces#mine"
253   get "/traces/mine/page/:page", :page => /[1-9][0-9]*/, :to => redirect(:path => "/traces/mine")
254   get "/traces/mine" => "traces#mine"
255   get "/trace/create", :to => redirect(:path => "/traces/new")
256   get "/trace/:id/data", :format => false, :id => /\d+/, :to => redirect(:path => "/traces/%{id}/data")
257   get "/trace/:id/data.:format", :id => /\d+/, :to => redirect(:path => "/traces/%{id}/data.%{format}")
258   get "/trace/:id/edit", :id => /\d+/, :to => redirect(:path => "/traces/%{id}/edit")
259
260   namespace :traces, :path => "" do
261     resource :feed, :path => "(/user/:display_name)/traces(/tag/:tag)/rss", :only => :show, :defaults => { :format => :rss }
262   end
263
264   # diary pages
265   resources :diary_entries, :path => "diary", :only => [:new, :create, :index] do
266     collection do
267       get "friends" => "diary_entries#index", :friends => true
268       get "nearby" => "diary_entries#index", :nearby => true
269     end
270   end
271   get "/user/:display_name/diary/rss" => "diary_entries#rss", :defaults => { :format => :rss }
272   get "/diary/:language/rss" => "diary_entries#rss", :defaults => { :format => :rss }
273   get "/diary/rss" => "diary_entries#rss", :defaults => { :format => :rss }
274   get "/user/:display_name/diary" => "diary_entries#index"
275   get "/diary/:language" => "diary_entries#index"
276   scope "/user/:display_name" do
277     resources :diary_entries, :path => "diary", :only => [:edit, :update, :show], :id => /\d+/ do
278       member do
279         post :hide
280         post :unhide
281       end
282     end
283   end
284   match "/user/:display_name/diary/:id/subscribe" => "diary_entries#subscribe", :via => [:get, :post], :as => :diary_entry_subscribe, :id => /\d+/
285   match "/user/:display_name/diary/:id/unsubscribe" => "diary_entries#unsubscribe", :via => [:get, :post], :as => :diary_entry_unsubscribe, :id => /\d+/
286   post "/user/:display_name/diary/:id/comments" => "diary_comments#create", :id => /\d+/, :as => :comment_diary_entry
287   post "/diary_comments/:comment/hide" => "diary_comments#hide", :comment => /\d+/, :as => :hide_diary_comment
288   post "/diary_comments/:comment/unhide" => "diary_comments#unhide", :comment => /\d+/, :as => :unhide_diary_comment
289
290   # user pages
291   get "/user/terms", :to => redirect(:path => "/account/terms")
292   resources :users, :path => "user", :param => :display_name, :only => [:new, :create, :show] do
293     resource :role, :controller => "user_roles", :path => "roles/:role", :only => [:create, :destroy]
294     scope :module => :users do
295       resources :diary_comments, :only => :index
296       resources :changeset_comments, :only => :index
297       resource :issued_blocks, :path => "blocks_by", :only => :show
298       resource :received_blocks, :path => "blocks", :only => [:show, :edit, :destroy]
299       resource :status, :only => :update
300     end
301   end
302   get "/user/:display_name/account", :to => redirect(:path => "/account")
303   get "/user/:display_name/diary/comments(/:page)", :page => /[1-9][0-9]*/, :to => redirect(:path => "/user/%{display_name}/diary_comments")
304
305   resource :account, :only => [:show, :update, :destroy] do
306     scope :module => :accounts do
307       resource :terms, :only => [:show, :update]
308       resource :pd_declaration, :only => [:show, :create]
309       resource :deletion, :only => :show
310       resource :home, :only => :show
311     end
312   end
313   get "/account/edit", :to => redirect(:path => "/account"), :as => nil
314
315   resource :dashboard, :only => [:show]
316   resource :preferences, :only => [:show, :update]
317   get "/preferences/edit", :to => redirect(:path => "/preferences")
318   resource :profile, :only => [:edit, :update]
319
320   # friendships
321   scope "/user/:display_name" do
322     resource :follow, :only => [:create, :destroy, :show], :path => "follow"
323
324     get "make_friend", :to => redirect("/user/%{display_name}/follow")
325     get "remove_friend", :to => redirect("/user/%{display_name}/follow")
326   end
327
328   # user lists
329   namespace :users do
330     resource :list, :path => "(:status)", :only => [:show, :update]
331   end
332
333   # geocoder
334   get "/search" => "geocoder#search"
335   post "/geocoder/search_latlon" => "geocoder#search_latlon"
336   post "/geocoder/search_osm_nominatim" => "geocoder#search_osm_nominatim"
337   post "/geocoder/search_osm_nominatim_reverse" => "geocoder#search_osm_nominatim_reverse"
338
339   # directions
340   get "/directions" => "directions#search"
341
342   # export
343   post "/export/finish" => "export#finish"
344   get "/export/embed" => "export#embed"
345
346   # messages
347   resources :messages, :path_names => { :new => "new/:display_name" }, :id => /\d+/, :only => [:new, :create, :show, :destroy] do
348     scope :module => :messages do
349       resource :reply, :path_names => { :new => "new" }, :only => :new
350       resource :read_mark, :only => [:create, :destroy]
351       resource :mute, :only => :destroy
352     end
353   end
354   namespace :messages, :path => "/messages" do
355     resource :inbox, :only => :show
356     resource :muted_inbox, :path => "muted", :only => :show
357     resource :outbox, :only => :show
358   end
359   get "/user/:display_name/inbox", :to => redirect(:path => "/messages/inbox")
360   get "/user/:display_name/outbox", :to => redirect(:path => "/messages/outbox")
361   get "/message/new/:display_name", :to => redirect(:path => "/messages/new/%{display_name}")
362   get "/message/read/:message_id", :to => redirect(:path => "/messages/%{message_id}")
363   get "/messages/:message_id/reply", :to => redirect(:path => "/messages/%{message_id}/reply/new")
364
365   # muting users
366   scope "/user/:display_name" do
367     resource :user_mute, :only => [:create, :destroy], :path => "mute"
368   end
369   resources :user_mutes, :only => [:index]
370
371   # banning pages
372   resources :user_blocks, :path_names => { :new => "new/:display_name" }
373
374   # issues and reports
375   resources :issues do
376     resources :comments, :controller => :issue_comments
377     member do
378       post "resolve"
379       post "assign"
380       post "ignore"
381       post "reopen"
382     end
383   end
384
385   resources :reports
386
387   # redactions
388   resources :redactions
389
390   # errors
391   match "/400", :to => "errors#bad_request", :via => :all
392   match "/403", :to => "errors#forbidden", :via => :all
393   match "/404", :to => "errors#not_found", :via => :all
394   match "/500", :to => "errors#internal_server_error", :via => :all
395 end