3 # Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies)
4 # Copyright (C) 2007, 2008, 2009 Johan Sørensen <johan@johansorensen.com>
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU Affero General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU Affero General Public License for more details.
16 # You should have received a copy of the GNU Affero General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
21 # == ROUTING NOTE =========================================================
23 # Note that all routes are getting pre and post processed by the filter class
24 # in RAILS_ROOT/lib/route_filters/repository_owner_namespacing.rb and that
25 # you should be EXTRA CAREFUL when adding a route that doesn't map directly
26 # by name to an existing controller or action. In such case the same string
27 # should be added to Gitorious::Reservations::unaccounted_root_names
29 # =========================================================================
31 ActionController::Routing::Routes.draw do |map|
32 VALID_REF = /[a-zA-Z0-9~\{\}\+\^\.\-_\/]+/
34 # Builds up the common repository sub-routes that's shared between projects
35 # and user+team namespaced repositories
36 def build_repository_routes(repository, options = {})
37 repository.with_options(options) do |repo|
38 repo.resources :comments
39 repo.commit_comment "comments/commit/:sha", :controller => "comments",
40 :action => "commit", :conditions => { :method => :get }
41 repo.comments_preview 'comments/preview', :controller => 'comments',
42 :action => 'preview'#, :conditions => {:method => :put}
43 repo.resources :merge_requests, :member => {
44 :terms_accepted => :get,
46 :commit_status => :get
49 :commit_list => :post,
50 :target_branches => :post,
52 merge_request.resources :comments, :collection => {:preview => :post}
53 merge_request.resources :merge_request_versions do |v|
54 v.resources :comments, :collection => {:preview => :post}
57 repo.resources :committerships, :collection => {
58 :auto_complete_for_group_name => :get,
59 :auto_complete_for_user_login => :get
62 repo.formatted_commits_feed("commits/*branch/feed.:format",
63 :controller => "commits", :action => "feed", :conditions => { :feed => :get })
64 repo.commits "commits", :controller => "commits", :action => "index"
65 repo.commits_in_ref "commits/*branch", :controller => "commits", :action => "index"
66 repo.graph "graph", :controller => "graphs", :action => "index"
67 repo.graph_in_ref "graph/*branch", :controller => "graphs", :action => "index"
68 repo.commit_comments "commit/:id/comments", :controller => "commit_comments", :action => "index", :id => /[^\/]+/
69 repo.commit_diffs "commit/:id/diffs", :controller => "commit_diffs", :action => "index", :id => /[^\/]+/
70 repo.commit_compare "commit/:from_id/diffs/:id", :controller => "commit_diffs", :action => "compare"
71 repo.commit "commit/:id", :controller => "commits", :action => "show", :id => /.*/
72 repo.trees "trees/", :controller => "trees", :action => "index"
73 repo.tree "trees/*branch_and_path", :controller => "trees", :action => "show"
74 repo.formatted_tree "trees/*branch_and_path.:format", :controller => "trees", :action => "show"
75 repo.archive_tar "archive-tarball/*branch", :controller => "trees", :action => "archive", :archive_format => "tar.gz"
76 #repo.archive_zip "archive-zip/*branch", :controller => "trees", :action => "archive", :archive_format => "zip"
77 repo.raw_blob "blobs/raw/*branch_and_path", :controller => "blobs", :action => "raw"
78 repo.blob_history "blobs/history/*branch_and_path", :controller => "blobs", :action => "history"
79 repo.blame "blobs/blame/*branch_and_path", :controller => "blobs", :action => "blame"
80 repo.blob "blobs/*branch_and_path", :controller => "blobs", :action => "show"
84 repository_options = {
86 :clone => :get, :create_clone => :post,
89 :confirm_delete => :get,
91 :search_clones => :get
95 map.root :controller => "site", :action => "index"
97 map.connect "users/activate/:activation_code", :controller => "users", :action => "activate"
98 map.connect "users/pending_activation", :controller => "users", :action => "pending_activation"
99 map.reset_password "users/reset_password/:token", :controller => "users", :action => "reset_password"
100 map.resources(:users, :requirements => {:id => /#{User::USERNAME_FORMAT}/i }, :collection => {
101 :forgot_password => :get,
102 :forgot_password_create => :post,
103 :openid_build => :get,
104 :openid_create => :post
108 :update_password => :put,
112 user.with_options({:requirements => {:user_id => /#{User::USERNAME_FORMAT}/i}}) do |user_req|
113 user_req.resources :keys
114 user_req.resources :aliases, :member => { :confirm => :get }
115 user_req.resource :license
116 user_req.resources(:repositories, repository_options){|r| build_repository_routes(r) }
117 user_req.resources :projects do |p|
118 p.resources(:repositories, repository_options.merge({
119 :requirements => {:user_id => /#{User::USERNAME_FORMAT}/i}
121 build_repository_routes(repo, {:requirements => {:user_id => /#{User::USERNAME_FORMAT}/i}})
127 map.resources :events, :member => {:commits => :get}
129 map.open_id_complete '/sessions', :controller => "sessions", :action=> "create",:requirements => { :method => :get }
131 map.resource :sessions
132 map.with_options(:controller => "projects", :action => "category") do |project_cat|
133 project_cat.projects_category "projects/category/:id"
134 project_cat.formatted_projects_category "projects/category/:id.:format"
136 map.resources :groups, :as => "teams", :member => {:avatar => :delete} do |grp|
137 grp.resources :memberships, :collection => {:auto_complete_for_user_login => :get}
138 grp.resources(:repositories, repository_options){|r| build_repository_routes(r) }
139 grp.resources :projects do |p|
140 p.resources(:repositories, repository_options){|r| build_repository_routes(r) }
144 map.resources :projects, :member => {
145 :confirm_delete => :get,
150 projects.resources :pages, :member => { :history => :get,:preview => :put}, :collection => { :git_access => :get }
151 projects.resources(:repositories, repository_options){|r| build_repository_routes(r) }
156 map.resources :messages,
157 :member => {:reply => :post, :read => :put},
158 :collection => {:auto_complete_for_message_recipients => :get, :sent => :get, :bulk_update => :put, :all => :get}
160 map.with_options :controller => 'sessions' do |session|
161 session.login '/login', :action => 'new'
162 session.logout '/logout', :action => 'destroy'
165 map.dashboard "dashboard", :controller => "site", :action => "dashboard"
166 map.about "about", :controller => "site", :action => "about"
167 map.faq "about/faq", :controller => "site", :action => "faq"
168 map.contact "contact", :controller => "site", :action => "contact"
170 map.namespace :api do |api|
171 api.connect ':project_id/:repository_id/log/graph', :controller => 'graphs', :action => 'show', :branch => 'master'
172 api.connect ':project_id/:repository_id/log/graph/*branch', :controller => 'graphs', :action => 'show'
175 map.namespace :admin do |admin|
176 admin.resources :users, :member => { :suspend => :put, :unsuspend => :put, :reset_password => :put }
177 admin.resource :oauth_settings, :path_prefix => "/admin/projects/:project_id"
178 admin.resources :repositories, :member => {:recreate => :put}
181 map.resources :favorites
183 map.activity "/activities", :controller => "site", :action => "public_timeline"
185 map.merge_request_landing_page '/merge_request_landing_page', :controller => 'merge_requests', :action => 'oauth_return'
187 map.merge_request_direct_access '/merge_requests/:id', :controller => 'merge_requests', :action => 'direct_access'
189 # Install the default route as the lowest priority.
190 map.connect ':controller/:action/:id.:format'
191 map.connect ':controller/:action/:id'
193 # See the routing_filter plugin and lib/route_filters/*
194 map.filter "repository_owner_namespacing", :file => "route_filters/repository_owner_namespacing"