##// END OF EJS Templates
Use named routes....
Jean-Philippe Lang -
r9757:986ffb243438
parent child
Show More
@@ -1,282 +1,282
1 1 # Redmine - project management software
2 2 # Copyright (C) 2006-2012 Jean-Philippe Lang
3 3 #
4 4 # This program is free software; you can redistribute it and/or
5 5 # modify it under the terms of the GNU General Public License
6 6 # as published by the Free Software Foundation; either version 2
7 7 # of the License, or (at your option) any later version.
8 8 #
9 9 # This program is distributed in the hope that it will be useful,
10 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 12 # GNU General Public License for more details.
13 13 #
14 14 # You should have received a copy of the GNU General Public License
15 15 # along with this program; if not, write to the Free Software
16 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 17
18 18 class AccountController < ApplicationController
19 19 helper :custom_fields
20 20 include CustomFieldsHelper
21 21
22 22 # prevents login action to be filtered by check_if_login_required application scope filter
23 23 skip_before_filter :check_if_login_required
24 24
25 25 # Login request and validation
26 26 def login
27 27 if request.get?
28 28 logout_user
29 29 else
30 30 authenticate_user
31 31 end
32 32 rescue AuthSourceException => e
33 33 logger.error "An error occured when authenticating #{params[:username]}: #{e.message}"
34 34 render_error :message => e.message
35 35 end
36 36
37 37 # Log out current user and redirect to welcome page
38 38 def logout
39 39 logout_user
40 40 redirect_to home_url
41 41 end
42 42
43 43 # Enable user to choose a new password
44 44 def lost_password
45 45 redirect_to(home_url) && return unless Setting.lost_password?
46 46 if params[:token]
47 47 @token = Token.find_by_action_and_value("recovery", params[:token])
48 48 redirect_to(home_url) && return unless @token and !@token.expired?
49 49 @user = @token.user
50 50 if request.post?
51 51 @user.password, @user.password_confirmation = params[:new_password], params[:new_password_confirmation]
52 52 if @user.save
53 53 @token.destroy
54 54 flash[:notice] = l(:notice_account_password_updated)
55 55 redirect_to :action => 'login'
56 56 return
57 57 end
58 58 end
59 59 render :template => "account/password_recovery"
60 60 return
61 61 else
62 62 if request.post?
63 63 user = User.find_by_mail(params[:mail])
64 64 # user not found in db
65 65 (flash.now[:error] = l(:notice_account_unknown_email); return) unless user
66 66 # user uses an external authentification
67 67 (flash.now[:error] = l(:notice_can_t_change_password); return) if user.auth_source_id
68 68 # create a new token for password recovery
69 69 token = Token.new(:user => user, :action => "recovery")
70 70 if token.save
71 71 Mailer.lost_password(token).deliver
72 72 flash[:notice] = l(:notice_account_lost_email_sent)
73 redirect_to :action => 'login'
73 redirect_to signin_path
74 74 return
75 75 end
76 76 end
77 77 end
78 78 end
79 79
80 80 # User self-registration
81 81 def register
82 82 redirect_to(home_url) && return unless Setting.self_registration? || session[:auth_source_registration]
83 83 if request.get?
84 84 session[:auth_source_registration] = nil
85 85 @user = User.new(:language => Setting.default_language)
86 86 else
87 87 user_params = params[:user] || {}
88 88 @user = User.new
89 89 @user.safe_attributes = user_params
90 90 @user.admin = false
91 91 @user.register
92 92 if session[:auth_source_registration]
93 93 @user.activate
94 94 @user.login = session[:auth_source_registration][:login]
95 95 @user.auth_source_id = session[:auth_source_registration][:auth_source_id]
96 96 if @user.save
97 97 session[:auth_source_registration] = nil
98 98 self.logged_user = @user
99 99 flash[:notice] = l(:notice_account_activated)
100 100 redirect_to :controller => 'my', :action => 'account'
101 101 end
102 102 else
103 103 @user.login = params[:user][:login]
104 104 unless user_params[:identity_url].present? && user_params[:password].blank? && user_params[:password_confirmation].blank?
105 105 @user.password, @user.password_confirmation = user_params[:password], user_params[:password_confirmation]
106 106 end
107 107
108 108 case Setting.self_registration
109 109 when '1'
110 110 register_by_email_activation(@user)
111 111 when '3'
112 112 register_automatically(@user)
113 113 else
114 114 register_manually_by_administrator(@user)
115 115 end
116 116 end
117 117 end
118 118 end
119 119
120 120 # Token based account activation
121 121 def activate
122 122 redirect_to(home_url) && return unless Setting.self_registration? && params[:token]
123 123 token = Token.find_by_action_and_value('register', params[:token])
124 124 redirect_to(home_url) && return unless token and !token.expired?
125 125 user = token.user
126 126 redirect_to(home_url) && return unless user.registered?
127 127 user.activate
128 128 if user.save
129 129 token.destroy
130 130 flash[:notice] = l(:notice_account_activated)
131 131 end
132 redirect_to :action => 'login'
132 redirect_to signin_path
133 133 end
134 134
135 135 private
136 136
137 137 def authenticate_user
138 138 if Setting.openid? && using_open_id?
139 139 open_id_authenticate(params[:openid_url])
140 140 else
141 141 password_authentication
142 142 end
143 143 end
144 144
145 145 def password_authentication
146 146 user = User.try_to_login(params[:username], params[:password])
147 147
148 148 if user.nil?
149 149 invalid_credentials
150 150 elsif user.new_record?
151 151 onthefly_creation_failed(user, {:login => user.login, :auth_source_id => user.auth_source_id })
152 152 else
153 153 # Valid user
154 154 successful_authentication(user)
155 155 end
156 156 end
157 157
158 158 def open_id_authenticate(openid_url)
159 159 authenticate_with_open_id(openid_url, :required => [:nickname, :fullname, :email], :return_to => signin_url, :method => :post) do |result, identity_url, registration|
160 160 if result.successful?
161 161 user = User.find_or_initialize_by_identity_url(identity_url)
162 162 if user.new_record?
163 163 # Self-registration off
164 164 redirect_to(home_url) && return unless Setting.self_registration?
165 165
166 166 # Create on the fly
167 167 user.login = registration['nickname'] unless registration['nickname'].nil?
168 168 user.mail = registration['email'] unless registration['email'].nil?
169 169 user.firstname, user.lastname = registration['fullname'].split(' ') unless registration['fullname'].nil?
170 170 user.random_password
171 171 user.register
172 172
173 173 case Setting.self_registration
174 174 when '1'
175 175 register_by_email_activation(user) do
176 176 onthefly_creation_failed(user)
177 177 end
178 178 when '3'
179 179 register_automatically(user) do
180 180 onthefly_creation_failed(user)
181 181 end
182 182 else
183 183 register_manually_by_administrator(user) do
184 184 onthefly_creation_failed(user)
185 185 end
186 186 end
187 187 else
188 188 # Existing record
189 189 if user.active?
190 190 successful_authentication(user)
191 191 else
192 192 account_pending
193 193 end
194 194 end
195 195 end
196 196 end
197 197 end
198 198
199 199 def successful_authentication(user)
200 200 # Valid user
201 201 self.logged_user = user
202 202 # generate a key and set cookie if autologin
203 203 if params[:autologin] && Setting.autologin?
204 204 set_autologin_cookie(user)
205 205 end
206 206 call_hook(:controller_account_success_authentication_after, {:user => user })
207 207 redirect_back_or_default :controller => 'my', :action => 'page'
208 208 end
209 209
210 210 def set_autologin_cookie(user)
211 211 token = Token.create(:user => user, :action => 'autologin')
212 212 cookie_name = Redmine::Configuration['autologin_cookie_name'] || 'autologin'
213 213 cookie_options = {
214 214 :value => token.value,
215 215 :expires => 1.year.from_now,
216 216 :path => (Redmine::Configuration['autologin_cookie_path'] || '/'),
217 217 :secure => (Redmine::Configuration['autologin_cookie_secure'] ? true : false),
218 218 :httponly => true
219 219 }
220 220 cookies[cookie_name] = cookie_options
221 221 end
222 222
223 223 # Onthefly creation failed, display the registration form to fill/fix attributes
224 224 def onthefly_creation_failed(user, auth_source_options = { })
225 225 @user = user
226 226 session[:auth_source_registration] = auth_source_options unless auth_source_options.empty?
227 render :action => 'register'
227 render register_path
228 228 end
229 229
230 230 def invalid_credentials
231 231 logger.warn "Failed login for '#{params[:username]}' from #{request.remote_ip} at #{Time.now.utc}"
232 232 flash.now[:error] = l(:notice_account_invalid_creditentials)
233 233 end
234 234
235 235 # Register a user for email activation.
236 236 #
237 237 # Pass a block for behavior when a user fails to save
238 238 def register_by_email_activation(user, &block)
239 239 token = Token.new(:user => user, :action => "register")
240 240 if user.save and token.save
241 241 Mailer.register(token).deliver
242 242 flash[:notice] = l(:notice_account_register_done)
243 redirect_to :action => 'login'
243 redirect_to signin_path
244 244 else
245 245 yield if block_given?
246 246 end
247 247 end
248 248
249 249 # Automatically register a user
250 250 #
251 251 # Pass a block for behavior when a user fails to save
252 252 def register_automatically(user, &block)
253 253 # Automatic activation
254 254 user.activate
255 255 user.last_login_on = Time.now
256 256 if user.save
257 257 self.logged_user = user
258 258 flash[:notice] = l(:notice_account_activated)
259 259 redirect_to :controller => 'my', :action => 'account'
260 260 else
261 261 yield if block_given?
262 262 end
263 263 end
264 264
265 265 # Manual activation by the administrator
266 266 #
267 267 # Pass a block for behavior when a user fails to save
268 268 def register_manually_by_administrator(user, &block)
269 269 if user.save
270 270 # Sends an email to the administrators
271 271 Mailer.account_activation_request(user).deliver
272 272 account_pending
273 273 else
274 274 yield if block_given?
275 275 end
276 276 end
277 277
278 278 def account_pending
279 279 flash[:notice] = l(:notice_account_pending)
280 redirect_to :action => 'login'
280 redirect_to signin_path
281 281 end
282 282 end
@@ -1,42 +1,42
1 1 <%= call_hook :view_account_login_top %>
2 2 <div id="login-form">
3 <%= form_tag({:action=> "login"}) do %>
3 <%= form_tag(signin_path) do %>
4 4 <%= back_url_hidden_field_tag %>
5 5 <table>
6 6 <tr>
7 7 <td align="right"><label for="username"><%=l(:field_login)%>:</label></td>
8 8 <td align="left"><%= text_field_tag 'username', nil, :tabindex => '1' %></td>
9 9 </tr>
10 10 <tr>
11 11 <td align="right"><label for="password"><%=l(:field_password)%>:</label></td>
12 12 <td align="left"><%= password_field_tag 'password', nil, :tabindex => '2' %></td>
13 13 </tr>
14 14 <% if Setting.openid? %>
15 15 <tr>
16 16 <td align="right"><label for="openid_url"><%=l(:field_identity_url)%></label></td>
17 17 <td align="left"><%= text_field_tag "openid_url", nil, :tabindex => '3' %></td>
18 18 </tr>
19 19 <% end %>
20 20 <tr>
21 21 <td></td>
22 22 <td align="left">
23 23 <% if Setting.autologin? %>
24 24 <label for="autologin"><%= check_box_tag 'autologin', 1, false, :tabindex => 4 %> <%= l(:label_stay_logged_in) %></label>
25 25 <% end %>
26 26 </td>
27 27 </tr>
28 28 <tr>
29 29 <td align="left">
30 30 <% if Setting.lost_password? %>
31 <%= link_to l(:label_password_lost), :controller => 'account', :action => 'lost_password' %>
31 <%= link_to l(:label_password_lost), lost_password_path %>
32 32 <% end %>
33 33 </td>
34 34 <td align="right">
35 35 <input type="submit" name="login" value="<%=l(:button_login)%> &#187;" tabindex="5"/>
36 36 </td>
37 37 </tr>
38 38 </table>
39 39 <%= javascript_tag "Form.Element.focus('username');" %>
40 40 <% end %>
41 41 </div>
42 42 <%= call_hook :view_account_login_bottom %>
@@ -1,11 +1,11
1 1 <h2><%=l(:label_password_lost)%></h2>
2 2
3 <div class="box">
4 <%= form_tag({:action=> "lost_password"}, :class => "tabular") do %>
5
6 <p><label for="mail"><%=l(:field_mail)%> <span class="required">*</span></label>
7 <%= text_field_tag 'mail', nil, :size => 40 %>
8 <%= submit_tag l(:button_submit) %></p>
9
3 <%= form_tag(lost_password_path) do %>
4 <div class="box tabular">
5 <p>
6 <label for="mail"><%=l(:field_mail)%> <span class="required">*</span></label>
7 <%= text_field_tag 'mail', nil, :size => 40 %>
8 <%= submit_tag l(:button_submit) %>
9 </p>
10 </div>
10 11 <% end %>
11 </div>
@@ -1,31 +1,31
1 1 <h2><%=l(:label_register)%> <%=link_to l(:label_login_with_open_id_option), signin_url if Setting.openid? %></h2>
2 2
3 <%= labelled_form_for @user, :url => {:action => 'register'} do |f| %>
3 <%= labelled_form_for @user, :url => register_path do |f| %>
4 4 <%= error_messages_for 'user' %>
5 5
6 6 <div class="box tabular">
7 7 <% if @user.auth_source_id.nil? %>
8 8 <p><%= f.text_field :login, :size => 25, :required => true %></p>
9 9
10 10 <p><%= f.password_field :password, :size => 25, :required => true %>
11 11 <em class="info"><%= l(:text_caracters_minimum, :count => Setting.password_min_length) %></em></p>
12 12
13 13 <p><%= f.password_field :password_confirmation, :size => 25, :required => true %></p>
14 14 <% end %>
15 15
16 16 <p><%= f.text_field :firstname, :required => true %></p>
17 17 <p><%= f.text_field :lastname, :required => true %></p>
18 18 <p><%= f.text_field :mail, :required => true %></p>
19 19 <p><%= f.select :language, lang_options_for_select %></p>
20 20
21 21 <% if Setting.openid? %>
22 22 <p><%= f.text_field :identity_url %></p>
23 23 <% end %>
24 24
25 25 <% @user.custom_field_values.select {|v| v.editable? || v.required?}.each do |value| %>
26 26 <p><%= custom_field_tag_with_label :user, value %></p>
27 27 <% end %>
28 28 </div>
29 29
30 30 <%= submit_tag l(:button_submit) %>
31 31 <% end %>
@@ -1,339 +1,339
1 1 # Redmine - project management software
2 2 # Copyright (C) 2006-2012 Jean-Philippe Lang
3 3 #
4 4 # This program is free software; you can redistribute it and/or
5 5 # modify it under the terms of the GNU General Public License
6 6 # as published by the Free Software Foundation; either version 2
7 7 # of the License, or (at your option) any later version.
8 8 #
9 9 # This program is distributed in the hope that it will be useful,
10 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 12 # GNU General Public License for more details.
13 13 #
14 14 # You should have received a copy of the GNU General Public License
15 15 # along with this program; if not, write to the Free Software
16 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 17
18 18 RedmineApp::Application.routes.draw do
19 19 root :to => 'welcome#index', :as => 'home'
20 20
21 21 match 'login', :to => 'account#login', :as => 'signin'
22 22 match 'logout', :to => 'account#logout', :as => 'signout'
23 match 'account/register', :to => 'account#register', :via => [:get, :post]
24 match 'account/lost_password', :to => 'account#lost_password', :via => [:get, :post]
23 match 'account/register', :to => 'account#register', :via => [:get, :post], :as => 'register'
24 match 'account/lost_password', :to => 'account#lost_password', :via => [:get, :post], :as => 'lost_password'
25 25 match 'account/activate', :to => 'account#activate', :via => :get
26 26
27 27 match '/news/preview', :controller => 'previews', :action => 'news', :as => 'preview_news'
28 28 match '/issues/preview/new/:project_id', :to => 'previews#issue', :as => 'preview_new_issue'
29 29 match '/issues/preview/edit/:id', :to => 'previews#issue', :as => 'preview_edit_issue'
30 30 match '/issues/preview', :to => 'previews#issue', :as => 'preview_issue'
31 31
32 32 match 'projects/:id/wiki', :to => 'wikis#edit', :via => :post
33 33 match 'projects/:id/wiki/destroy', :to => 'wikis#destroy', :via => [:get, :post]
34 34
35 35 match 'boards/:board_id/topics/new', :to => 'messages#new', :via => [:get, :post]
36 36 get 'boards/:board_id/topics/:id', :to => 'messages#show'
37 37 match 'boards/:board_id/topics/quote/:id', :to => 'messages#quote', :via => [:get, :post]
38 38 get 'boards/:board_id/topics/:id/edit', :to => 'messages#edit'
39 39
40 40 post 'boards/:board_id/topics/preview', :to => 'messages#preview'
41 41 post 'boards/:board_id/topics/:id/replies', :to => 'messages#reply'
42 42 post 'boards/:board_id/topics/:id/edit', :to => 'messages#edit'
43 43 post 'boards/:board_id/topics/:id/destroy', :to => 'messages#destroy'
44 44
45 45 # Misc issue routes. TODO: move into resources
46 46 match '/issues/auto_complete', :to => 'auto_completes#issues', :via => :get, :as => 'auto_complete_issues'
47 47 match '/issues/context_menu', :to => 'context_menus#issues', :as => 'issues_context_menu'
48 48 match '/issues/changes', :to => 'journals#index', :as => 'issue_changes'
49 49 match '/issues/:id/quoted', :to => 'journals#new', :id => /\d+/, :via => :post, :as => 'quoted_issue'
50 50
51 51 match '/journals/diff/:id', :to => 'journals#diff', :id => /\d+/, :via => :get
52 52 match '/journals/edit/:id', :to => 'journals#edit', :id => /\d+/, :via => [:get, :post]
53 53
54 54 match '/projects/:project_id/issues/gantt', :to => 'gantts#show'
55 55 match '/issues/gantt', :to => 'gantts#show'
56 56
57 57 match '/projects/:project_id/issues/calendar', :to => 'calendars#show'
58 58 match '/issues/calendar', :to => 'calendars#show'
59 59
60 60 match 'projects/:id/issues/report', :to => 'reports#issue_report', :via => :get
61 61 match 'projects/:id/issues/report/:detail', :to => 'reports#issue_report_details', :via => :get
62 62
63 63 match 'my/account', :controller => 'my', :action => 'account', :via => [:get, :post]
64 64 match 'my/account/destroy', :controller => 'my', :action => 'destroy', :via => [:get, :post]
65 65 match 'my/page', :controller => 'my', :action => 'page', :via => :get
66 66 match 'my', :controller => 'my', :action => 'index', :via => :get # Redirects to my/page
67 67 match 'my/reset_rss_key', :controller => 'my', :action => 'reset_rss_key', :via => :post
68 68 match 'my/reset_api_key', :controller => 'my', :action => 'reset_api_key', :via => :post
69 69 match 'my/password', :controller => 'my', :action => 'password', :via => [:get, :post]
70 70 match 'my/page_layout', :controller => 'my', :action => 'page_layout', :via => :get
71 71 match 'my/add_block', :controller => 'my', :action => 'add_block', :via => :post
72 72 match 'my/remove_block', :controller => 'my', :action => 'remove_block', :via => :post
73 73 match 'my/order_blocks', :controller => 'my', :action => 'order_blocks', :via => :post
74 74
75 75 resources :users
76 76 match 'users/:id/memberships/:membership_id', :to => 'users#edit_membership', :via => :put, :as => 'user_membership'
77 77 match 'users/:id/memberships/:membership_id', :to => 'users#destroy_membership', :via => :delete
78 78 match 'users/:id/memberships', :to => 'users#edit_membership', :via => :post, :as => 'user_memberships'
79 79
80 80 match 'watchers/new', :controller=> 'watchers', :action => 'new', :via => :get
81 81 match 'watchers', :controller=> 'watchers', :action => 'create', :via => :post
82 82 match 'watchers/append', :controller=> 'watchers', :action => 'append', :via => :post
83 83 match 'watchers/destroy', :controller=> 'watchers', :action => 'destroy', :via => :post
84 84 match 'watchers/watch', :controller=> 'watchers', :action => 'watch', :via => :post
85 85 match 'watchers/unwatch', :controller=> 'watchers', :action => 'unwatch', :via => :post
86 86 match 'watchers/autocomplete_for_user', :controller=> 'watchers', :action => 'autocomplete_for_user', :via => :get
87 87
88 88 match 'projects/:id/settings/:tab', :to => "projects#settings"
89 89
90 90 resources :projects do
91 91 member do
92 92 get 'settings'
93 93 post 'modules'
94 94 post 'archive'
95 95 post 'unarchive'
96 96 post 'close'
97 97 post 'reopen'
98 98 match 'copy', :via => [:get, :post]
99 99 end
100 100
101 101 resources :memberships, :shallow => true, :controller => 'members', :only => [:index, :show, :create, :update, :destroy] do
102 102 collection do
103 103 get 'autocomplete'
104 104 end
105 105 end
106 106
107 107 resource :enumerations, :controller => 'project_enumerations', :only => [:update, :destroy]
108 108
109 109 match 'issues/:copy_from/copy', :to => 'issues#new'
110 110 resources :issues, :only => [:index, :new, :create] do
111 111 resources :time_entries, :controller => 'timelog' do
112 112 collection do
113 113 get 'report'
114 114 end
115 115 end
116 116 end
117 117 # issue form update
118 118 match 'issues/new', :controller => 'issues', :action => 'new', :via => [:put, :post], :as => 'issue_form'
119 119
120 120 resources :files, :only => [:index, :new, :create]
121 121
122 122 resources :versions, :except => [:index, :show, :edit, :update, :destroy] do
123 123 collection do
124 124 put 'close_completed'
125 125 end
126 126 end
127 127 match 'versions.:format', :to => 'versions#index'
128 128 match 'roadmap', :to => 'versions#index', :format => false
129 129 match 'versions', :to => 'versions#index'
130 130
131 131 resources :news, :except => [:show, :edit, :update, :destroy]
132 132 resources :time_entries, :controller => 'timelog' do
133 133 get 'report', :on => :collection
134 134 end
135 135 resources :queries, :only => [:new, :create]
136 136 resources :issue_categories, :shallow => true
137 137 resources :documents, :except => [:show, :edit, :update, :destroy]
138 138 resources :boards
139 139 resources :repositories, :shallow => true, :except => [:index, :show] do
140 140 member do
141 141 match 'committers', :via => [:get, :post]
142 142 end
143 143 end
144 144
145 145 match 'wiki/index', :controller => 'wiki', :action => 'index', :via => :get
146 146 match 'wiki/:id/diff/:version/vs/:version_from', :controller => 'wiki', :action => 'diff'
147 147 match 'wiki/:id/diff/:version', :controller => 'wiki', :action => 'diff'
148 148 resources :wiki, :except => [:index, :new, :create] do
149 149 member do
150 150 get 'rename'
151 151 post 'rename'
152 152 get 'history'
153 153 get 'diff'
154 154 match 'preview', :via => [:post, :put]
155 155 post 'protect'
156 156 post 'add_attachment'
157 157 end
158 158 collection do
159 159 get 'export'
160 160 get 'date_index'
161 161 end
162 162 end
163 163 match 'wiki', :controller => 'wiki', :action => 'show', :via => :get
164 164 match 'wiki/:id/annotate/:version', :controller => 'wiki', :action => 'annotate'
165 165 end
166 166
167 167 resources :issues do
168 168 collection do
169 169 match 'bulk_edit', :via => [:get, :post]
170 170 post 'bulk_update'
171 171 end
172 172 resources :time_entries, :controller => 'timelog' do
173 173 collection do
174 174 get 'report'
175 175 end
176 176 end
177 177 resources :relations, :shallow => true, :controller => 'issue_relations', :only => [:index, :show, :create, :destroy]
178 178 end
179 179 match '/issues', :controller => 'issues', :action => 'destroy', :via => :delete
180 180
181 181 resources :queries, :except => [:show]
182 182
183 183 resources :news, :only => [:index, :show, :edit, :update, :destroy]
184 184 match '/news/:id/comments', :to => 'comments#create', :via => :post
185 185 match '/news/:id/comments/:comment_id', :to => 'comments#destroy', :via => :delete
186 186
187 187 resources :versions, :only => [:show, :edit, :update, :destroy] do
188 188 post 'status_by', :on => :member
189 189 end
190 190
191 191 resources :documents, :only => [:show, :edit, :update, :destroy] do
192 192 post 'add_attachment', :on => :member
193 193 end
194 194
195 195 match '/time_entries/context_menu', :to => 'context_menus#time_entries', :as => :time_entries_context_menu
196 196
197 197 resources :time_entries, :controller => 'timelog', :except => :destroy do
198 198 collection do
199 199 get 'report'
200 200 get 'bulk_edit'
201 201 post 'bulk_update'
202 202 end
203 203 end
204 204 match '/time_entries/:id', :to => 'timelog#destroy', :via => :delete, :id => /\d+/
205 205 # TODO: delete /time_entries for bulk deletion
206 206 match '/time_entries/destroy', :to => 'timelog#destroy', :via => :delete
207 207
208 208 # TODO: port to be part of the resources route(s)
209 209 match 'projects/:id/settings/:tab', :to => 'projects#settings', :via => :get
210 210
211 211 get 'projects/:id/activity', :to => 'activities#index'
212 212 get 'projects/:id/activity.:format', :to => 'activities#index'
213 213 get 'activity', :to => 'activities#index'
214 214
215 215 # repositories routes
216 216 get 'projects/:id/repository/:repository_id/statistics', :to => 'repositories#stats'
217 217 get 'projects/:id/repository/:repository_id/graph', :to => 'repositories#graph'
218 218
219 219 get 'projects/:id/repository/:repository_id/changes(/*path(.:ext))',
220 220 :to => 'repositories#changes'
221 221
222 222 get 'projects/:id/repository/:repository_id/revisions/:rev', :to => 'repositories#revision'
223 223 get 'projects/:id/repository/:repository_id/revision', :to => 'repositories#revision'
224 224 post 'projects/:id/repository/:repository_id/revisions/:rev/issues', :to => 'repositories#add_related_issue'
225 225 delete 'projects/:id/repository/:repository_id/revisions/:rev/issues/:issue_id', :to => 'repositories#remove_related_issue'
226 226 get 'projects/:id/repository/:repository_id/revisions', :to => 'repositories#revisions'
227 227 get 'projects/:id/repository/:repository_id/revisions/:rev/:action(/*path(.:ext))',
228 228 :controller => 'repositories',
229 229 :format => false,
230 230 :constraints => {
231 231 :action => /(browse|show|entry|raw|annotate|diff)/,
232 232 :rev => /[a-z0-9\.\-_]+/
233 233 }
234 234
235 235 get 'projects/:id/repository/statistics', :to => 'repositories#stats'
236 236 get 'projects/:id/repository/graph', :to => 'repositories#graph'
237 237
238 238 get 'projects/:id/repository/changes(/*path(.:ext))',
239 239 :to => 'repositories#changes'
240 240
241 241 get 'projects/:id/repository/revisions', :to => 'repositories#revisions'
242 242 get 'projects/:id/repository/revisions/:rev', :to => 'repositories#revision'
243 243 get 'projects/:id/repository/revision', :to => 'repositories#revision'
244 244 post 'projects/:id/repository/revisions/:rev/issues', :to => 'repositories#add_related_issue'
245 245 delete 'projects/:id/repository/revisions/:rev/issues/:issue_id', :to => 'repositories#remove_related_issue'
246 246 get 'projects/:id/repository/revisions/:rev/:action(/*path(.:ext))',
247 247 :controller => 'repositories',
248 248 :format => false,
249 249 :constraints => {
250 250 :action => /(browse|show|entry|raw|annotate|diff)/,
251 251 :rev => /[a-z0-9\.\-_]+/
252 252 }
253 253 get 'projects/:id/repository/:repository_id/:action(/*path(.:ext))',
254 254 :controller => 'repositories',
255 255 :action => /(browse|show|entry|raw|changes|annotate|diff)/
256 256 get 'projects/:id/repository/:action(/*path(.:ext))',
257 257 :controller => 'repositories',
258 258 :action => /(browse|show|entry|raw|changes|annotate|diff)/
259 259
260 260 get 'projects/:id/repository/:repository_id', :to => 'repositories#show', :path => nil
261 261 get 'projects/:id/repository', :to => 'repositories#show', :path => nil
262 262
263 263 # additional routes for having the file name at the end of url
264 264 match 'attachments/:id/:filename', :controller => 'attachments', :action => 'show', :id => /\d+/, :filename => /.*/, :via => :get
265 265 match 'attachments/download/:id/:filename', :controller => 'attachments', :action => 'download', :id => /\d+/, :filename => /.*/, :via => :get
266 266 match 'attachments/download/:id', :controller => 'attachments', :action => 'download', :id => /\d+/, :via => :get
267 267 match 'attachments/thumbnail/:id', :controller => 'attachments', :action => 'thumbnail', :id => /\d+/, :via => :get
268 268 resources :attachments, :only => [:show, :destroy]
269 269
270 270 resources :groups do
271 271 member do
272 272 get 'autocomplete_for_user'
273 273 end
274 274 end
275 275
276 276 match 'groups/:id/users', :controller => 'groups', :action => 'add_users', :id => /\d+/, :via => :post, :as => 'group_users'
277 277 match 'groups/:id/users/:user_id', :controller => 'groups', :action => 'remove_user', :id => /\d+/, :via => :delete, :as => 'group_user'
278 278 match 'groups/destroy_membership/:id', :controller => 'groups', :action => 'destroy_membership', :id => /\d+/, :via => :post
279 279 match 'groups/edit_membership/:id', :controller => 'groups', :action => 'edit_membership', :id => /\d+/, :via => :post
280 280
281 281 resources :trackers, :except => :show
282 282 resources :issue_statuses, :except => :show do
283 283 collection do
284 284 post 'update_issue_done_ratio'
285 285 end
286 286 end
287 287 resources :custom_fields, :except => :show
288 288 resources :roles, :except => :show do
289 289 collection do
290 290 match 'permissions', :via => [:get, :post]
291 291 end
292 292 end
293 293 resources :enumerations, :except => :show
294 294
295 295 get 'projects/:id/search', :controller => 'search', :action => 'index'
296 296 get 'search', :controller => 'search', :action => 'index'
297 297
298 298 match 'mail_handler', :controller => 'mail_handler', :action => 'index', :via => :post
299 299
300 300 match 'admin', :controller => 'admin', :action => 'index', :via => :get
301 301 match 'admin/projects', :controller => 'admin', :action => 'projects', :via => :get
302 302 match 'admin/plugins', :controller => 'admin', :action => 'plugins', :via => :get
303 303 match 'admin/info', :controller => 'admin', :action => 'info', :via => :get
304 304 match 'admin/test_email', :controller => 'admin', :action => 'test_email', :via => :get
305 305 match 'admin/default_configuration', :controller => 'admin', :action => 'default_configuration', :via => :post
306 306
307 307 resources :auth_sources do
308 308 member do
309 309 get 'test_connection'
310 310 end
311 311 end
312 312
313 313 match 'workflows', :controller => 'workflows', :action => 'index', :via => :get
314 314 match 'workflows/edit', :controller => 'workflows', :action => 'edit', :via => [:get, :post]
315 315 match 'workflows/copy', :controller => 'workflows', :action => 'copy', :via => [:get, :post]
316 316 match 'settings', :controller => 'settings', :action => 'index', :via => :get
317 317 match 'settings/edit', :controller => 'settings', :action => 'edit', :via => [:get, :post]
318 318 match 'settings/plugin/:id', :controller => 'settings', :action => 'plugin', :via => [:get, :post]
319 319
320 320 match 'sys/projects', :to => 'sys#projects', :via => :get
321 321 match 'sys/projects/:id/repository', :to => 'sys#create_project_repository', :via => :post
322 322 match 'sys/fetch_changesets', :to => 'sys#fetch_changesets', :via => :get
323 323
324 324 match 'uploads', :to => 'attachments#upload', :via => :post
325 325
326 326 get 'robots.txt', :to => 'welcome#robots'
327 327
328 328 Dir.glob File.expand_path("plugins/*", Rails.root) do |plugin_dir|
329 329 file = File.join(plugin_dir, "config/routes.rb")
330 330 if File.exists?(file)
331 331 begin
332 332 instance_eval File.read(file)
333 333 rescue Exception => e
334 334 puts "An error occurred while loading the routes definition of #{File.basename(plugin_dir)} plugin (#{file}): #{e.message}."
335 335 exit 1
336 336 end
337 337 end
338 338 end
339 339 end
@@ -1,240 +1,240
1 1 require 'redmine/access_control'
2 2 require 'redmine/menu_manager'
3 3 require 'redmine/activity'
4 4 require 'redmine/search'
5 5 require 'redmine/custom_field_format'
6 6 require 'redmine/mime_type'
7 7 require 'redmine/core_ext'
8 8 require 'redmine/themes'
9 9 require 'redmine/hook'
10 10 require 'redmine/plugin'
11 11 require 'redmine/notifiable'
12 12 require 'redmine/wiki_formatting'
13 13 require 'redmine/scm/base'
14 14
15 15 begin
16 16 require 'RMagick' unless Object.const_defined?(:Magick)
17 17 rescue LoadError
18 18 # RMagick is not available
19 19 end
20 20
21 21 if RUBY_VERSION < '1.9'
22 22 require 'fastercsv'
23 23 else
24 24 require 'csv'
25 25 FCSV = CSV
26 26 end
27 27
28 28 Redmine::Scm::Base.add "Subversion"
29 29 Redmine::Scm::Base.add "Darcs"
30 30 Redmine::Scm::Base.add "Mercurial"
31 31 Redmine::Scm::Base.add "Cvs"
32 32 Redmine::Scm::Base.add "Bazaar"
33 33 Redmine::Scm::Base.add "Git"
34 34 Redmine::Scm::Base.add "Filesystem"
35 35
36 36 Redmine::CustomFieldFormat.map do |fields|
37 37 fields.register 'string'
38 38 fields.register 'text'
39 39 fields.register 'int', :label => :label_integer
40 40 fields.register 'float'
41 41 fields.register 'list'
42 42 fields.register 'date'
43 43 fields.register 'bool', :label => :label_boolean
44 44 fields.register 'user', :only => %w(Issue TimeEntry Version Project), :edit_as => 'list'
45 45 fields.register 'version', :only => %w(Issue TimeEntry Version Project), :edit_as => 'list'
46 46 end
47 47
48 48 # Permissions
49 49 Redmine::AccessControl.map do |map|
50 50 map.permission :view_project, {:projects => [:show], :activities => [:index]}, :public => true, :read => true
51 51 map.permission :search_project, {:search => :index}, :public => true, :read => true
52 52 map.permission :add_project, {:projects => [:new, :create]}, :require => :loggedin
53 53 map.permission :edit_project, {:projects => [:settings, :edit, :update]}, :require => :member
54 54 map.permission :close_project, {:projects => [:close, :reopen]}, :require => :member, :read => true
55 55 map.permission :select_project_modules, {:projects => :modules}, :require => :member
56 56 map.permission :manage_members, {:projects => :settings, :members => [:index, :show, :create, :update, :destroy, :autocomplete]}, :require => :member
57 57 map.permission :manage_versions, {:projects => :settings, :versions => [:new, :create, :edit, :update, :close_completed, :destroy]}, :require => :member
58 58 map.permission :add_subprojects, {:projects => [:new, :create]}, :require => :member
59 59
60 60 map.project_module :issue_tracking do |map|
61 61 # Issue categories
62 62 map.permission :manage_categories, {:projects => :settings, :issue_categories => [:index, :show, :new, :create, :edit, :update, :destroy]}, :require => :member
63 63 # Issues
64 64 map.permission :view_issues, {:issues => [:index, :show],
65 65 :auto_complete => [:issues],
66 66 :context_menus => [:issues],
67 67 :versions => [:index, :show, :status_by],
68 68 :journals => [:index, :diff],
69 69 :queries => :index,
70 70 :reports => [:issue_report, :issue_report_details]},
71 71 :read => true
72 72 map.permission :add_issues, {:issues => [:new, :create, :update_form], :attachments => :upload}
73 73 map.permission :edit_issues, {:issues => [:edit, :update, :bulk_edit, :bulk_update, :update_form], :journals => [:new], :attachments => :upload}
74 74 map.permission :manage_issue_relations, {:issue_relations => [:index, :show, :create, :destroy]}
75 75 map.permission :manage_subtasks, {}
76 76 map.permission :set_issues_private, {}
77 77 map.permission :set_own_issues_private, {}, :require => :loggedin
78 78 map.permission :add_issue_notes, {:issues => [:edit, :update], :journals => [:new], :attachments => :upload}
79 79 map.permission :edit_issue_notes, {:journals => :edit}, :require => :loggedin
80 80 map.permission :edit_own_issue_notes, {:journals => :edit}, :require => :loggedin
81 81 map.permission :move_issues, {:issues => [:bulk_edit, :bulk_update]}, :require => :loggedin
82 82 map.permission :delete_issues, {:issues => :destroy}, :require => :member
83 83 # Queries
84 84 map.permission :manage_public_queries, {:queries => [:new, :create, :edit, :update, :destroy]}, :require => :member
85 85 map.permission :save_queries, {:queries => [:new, :create, :edit, :update, :destroy]}, :require => :loggedin
86 86 # Watchers
87 87 map.permission :view_issue_watchers, {}, :read => true
88 88 map.permission :add_issue_watchers, {:watchers => :new}
89 89 map.permission :delete_issue_watchers, {:watchers => :destroy}
90 90 end
91 91
92 92 map.project_module :time_tracking do |map|
93 93 map.permission :log_time, {:timelog => [:new, :create]}, :require => :loggedin
94 94 map.permission :view_time_entries, {:timelog => [:index, :report, :show]}, :read => true
95 95 map.permission :edit_time_entries, {:timelog => [:edit, :update, :destroy, :bulk_edit, :bulk_update]}, :require => :member
96 96 map.permission :edit_own_time_entries, {:timelog => [:edit, :update, :destroy,:bulk_edit, :bulk_update]}, :require => :loggedin
97 97 map.permission :manage_project_activities, {:project_enumerations => [:update, :destroy]}, :require => :member
98 98 end
99 99
100 100 map.project_module :news do |map|
101 101 map.permission :manage_news, {:news => [:new, :create, :edit, :update, :destroy], :comments => [:destroy]}, :require => :member
102 102 map.permission :view_news, {:news => [:index, :show]}, :public => true, :read => true
103 103 map.permission :comment_news, {:comments => :create}
104 104 end
105 105
106 106 map.project_module :documents do |map|
107 107 map.permission :manage_documents, {:documents => [:new, :create, :edit, :update, :destroy, :add_attachment]}, :require => :loggedin
108 108 map.permission :view_documents, {:documents => [:index, :show, :download]}, :read => true
109 109 end
110 110
111 111 map.project_module :files do |map|
112 112 map.permission :manage_files, {:files => [:new, :create]}, :require => :loggedin
113 113 map.permission :view_files, {:files => :index, :versions => :download}, :read => true
114 114 end
115 115
116 116 map.project_module :wiki do |map|
117 117 map.permission :manage_wiki, {:wikis => [:edit, :destroy]}, :require => :member
118 118 map.permission :rename_wiki_pages, {:wiki => :rename}, :require => :member
119 119 map.permission :delete_wiki_pages, {:wiki => :destroy}, :require => :member
120 120 map.permission :view_wiki_pages, {:wiki => [:index, :show, :special, :date_index]}, :read => true
121 121 map.permission :export_wiki_pages, {:wiki => [:export]}, :read => true
122 122 map.permission :view_wiki_edits, {:wiki => [:history, :diff, :annotate]}, :read => true
123 123 map.permission :edit_wiki_pages, :wiki => [:edit, :update, :preview, :add_attachment]
124 124 map.permission :delete_wiki_pages_attachments, {}
125 125 map.permission :protect_wiki_pages, {:wiki => :protect}, :require => :member
126 126 end
127 127
128 128 map.project_module :repository do |map|
129 129 map.permission :manage_repository, {:repositories => [:new, :create, :edit, :update, :committers, :destroy]}, :require => :member
130 130 map.permission :browse_repository, {:repositories => [:show, :browse, :entry, :raw, :annotate, :changes, :diff, :stats, :graph]}, :read => true
131 131 map.permission :view_changesets, {:repositories => [:show, :revisions, :revision]}, :read => true
132 132 map.permission :commit_access, {}
133 133 map.permission :manage_related_issues, {:repositories => [:add_related_issue, :remove_related_issue]}
134 134 end
135 135
136 136 map.project_module :boards do |map|
137 137 map.permission :manage_boards, {:boards => [:new, :create, :edit, :update, :destroy]}, :require => :member
138 138 map.permission :view_messages, {:boards => [:index, :show], :messages => [:show]}, :public => true, :read => true
139 139 map.permission :add_messages, {:messages => [:new, :reply, :quote]}
140 140 map.permission :edit_messages, {:messages => :edit}, :require => :member
141 141 map.permission :edit_own_messages, {:messages => :edit}, :require => :loggedin
142 142 map.permission :delete_messages, {:messages => :destroy}, :require => :member
143 143 map.permission :delete_own_messages, {:messages => :destroy}, :require => :loggedin
144 144 end
145 145
146 146 map.project_module :calendar do |map|
147 147 map.permission :view_calendar, {:calendars => [:show, :update]}, :read => true
148 148 end
149 149
150 150 map.project_module :gantt do |map|
151 151 map.permission :view_gantt, {:gantts => [:show, :update]}, :read => true
152 152 end
153 153 end
154 154
155 155 Redmine::MenuManager.map :top_menu do |menu|
156 156 menu.push :home, :home_path
157 157 menu.push :my_page, { :controller => 'my', :action => 'page' }, :if => Proc.new { User.current.logged? }
158 158 menu.push :projects, { :controller => 'projects', :action => 'index' }, :caption => :label_project_plural
159 159 menu.push :administration, { :controller => 'admin', :action => 'index' }, :if => Proc.new { User.current.admin? }, :last => true
160 160 menu.push :help, Redmine::Info.help_url, :last => true
161 161 end
162 162
163 163 Redmine::MenuManager.map :account_menu do |menu|
164 164 menu.push :login, :signin_path, :if => Proc.new { !User.current.logged? }
165 menu.push :register, { :controller => 'account', :action => 'register' }, :if => Proc.new { !User.current.logged? && Setting.self_registration? }
165 menu.push :register, :register_path, :if => Proc.new { !User.current.logged? && Setting.self_registration? }
166 166 menu.push :my_account, { :controller => 'my', :action => 'account' }, :if => Proc.new { User.current.logged? }
167 167 menu.push :logout, :signout_path, :if => Proc.new { User.current.logged? }
168 168 end
169 169
170 170 Redmine::MenuManager.map :application_menu do |menu|
171 171 # Empty
172 172 end
173 173
174 174 Redmine::MenuManager.map :admin_menu do |menu|
175 175 menu.push :projects, {:controller => 'admin', :action => 'projects'}, :caption => :label_project_plural
176 176 menu.push :users, {:controller => 'users'}, :caption => :label_user_plural
177 177 menu.push :groups, {:controller => 'groups'}, :caption => :label_group_plural
178 178 menu.push :roles, {:controller => 'roles'}, :caption => :label_role_and_permissions
179 179 menu.push :trackers, {:controller => 'trackers'}, :caption => :label_tracker_plural
180 180 menu.push :issue_statuses, {:controller => 'issue_statuses'}, :caption => :label_issue_status_plural,
181 181 :html => {:class => 'issue_statuses'}
182 182 menu.push :workflows, {:controller => 'workflows', :action => 'edit'}, :caption => :label_workflow
183 183 menu.push :custom_fields, {:controller => 'custom_fields'}, :caption => :label_custom_field_plural,
184 184 :html => {:class => 'custom_fields'}
185 185 menu.push :enumerations, {:controller => 'enumerations'}
186 186 menu.push :settings, {:controller => 'settings'}
187 187 menu.push :ldap_authentication, {:controller => 'auth_sources', :action => 'index'},
188 188 :html => {:class => 'server_authentication'}
189 189 menu.push :plugins, {:controller => 'admin', :action => 'plugins'}, :last => true
190 190 menu.push :info, {:controller => 'admin', :action => 'info'}, :caption => :label_information_plural, :last => true
191 191 end
192 192
193 193 Redmine::MenuManager.map :project_menu do |menu|
194 194 menu.push :overview, { :controller => 'projects', :action => 'show' }
195 195 menu.push :activity, { :controller => 'activities', :action => 'index' }
196 196 menu.push :roadmap, { :controller => 'versions', :action => 'index' }, :param => :project_id,
197 197 :if => Proc.new { |p| p.shared_versions.any? }
198 198 menu.push :issues, { :controller => 'issues', :action => 'index' }, :param => :project_id, :caption => :label_issue_plural
199 199 menu.push :new_issue, { :controller => 'issues', :action => 'new' }, :param => :project_id, :caption => :label_issue_new,
200 200 :html => { :accesskey => Redmine::AccessKeys.key_for(:new_issue) }
201 201 menu.push :gantt, { :controller => 'gantts', :action => 'show' }, :param => :project_id, :caption => :label_gantt
202 202 menu.push :calendar, { :controller => 'calendars', :action => 'show' }, :param => :project_id, :caption => :label_calendar
203 203 menu.push :news, { :controller => 'news', :action => 'index' }, :param => :project_id, :caption => :label_news_plural
204 204 menu.push :documents, { :controller => 'documents', :action => 'index' }, :param => :project_id, :caption => :label_document_plural
205 205 menu.push :wiki, { :controller => 'wiki', :action => 'show', :id => nil }, :param => :project_id,
206 206 :if => Proc.new { |p| p.wiki && !p.wiki.new_record? }
207 207 menu.push :boards, { :controller => 'boards', :action => 'index', :id => nil }, :param => :project_id,
208 208 :if => Proc.new { |p| p.boards.any? }, :caption => :label_board_plural
209 209 menu.push :files, { :controller => 'files', :action => 'index' }, :caption => :label_file_plural, :param => :project_id
210 210 menu.push :repository, { :controller => 'repositories', :action => 'show', :repository_id => nil, :path => nil, :rev => nil },
211 211 :if => Proc.new { |p| p.repository && !p.repository.new_record? }
212 212 menu.push :settings, { :controller => 'projects', :action => 'settings' }, :last => true
213 213 end
214 214
215 215 Redmine::Activity.map do |activity|
216 216 activity.register :issues, :class_name => %w(Issue Journal)
217 217 activity.register :changesets
218 218 activity.register :news
219 219 activity.register :documents, :class_name => %w(Document Attachment)
220 220 activity.register :files, :class_name => 'Attachment'
221 221 activity.register :wiki_edits, :class_name => 'WikiContent::Version', :default => false
222 222 activity.register :messages, :default => false
223 223 activity.register :time_entries, :default => false
224 224 end
225 225
226 226 Redmine::Search.map do |search|
227 227 search.register :issues
228 228 search.register :news
229 229 search.register :documents
230 230 search.register :changesets
231 231 search.register :wiki_pages
232 232 search.register :messages
233 233 search.register :projects
234 234 end
235 235
236 236 Redmine::WikiFormatting.map do |format|
237 237 format.register :textile, Redmine::WikiFormatting::Textile::Formatter, Redmine::WikiFormatting::Textile::Helper
238 238 end
239 239
240 240 ActionView::Template.register_template_handler :rsb, Redmine::Views::ApiTemplateHandler
General Comments 0
You need to be logged in to leave comments. Login now