##// END OF EJS Templates
Use the base layout for all 403, 404, and 500 pages. #6172...
Eric Davis -
r3835:73ba49a7154a
parent child
Show More
@@ -0,0 +1,26
1 require "#{File.dirname(__FILE__)}/../test_helper"
2
3 class LayoutTest < ActionController::IntegrationTest
4 fixtures :all
5
6 test "browsing to a missing page should render the base layout" do
7 get "/users/100000000"
8
9 assert_response :not_found
10
11 # UsersController uses the admin layout by default
12 assert_select "#admin-menu", :count => 0
13 end
14
15 test "browsing to an unauthorized page should render the base layout" do
16 user = User.find(9)
17 user.password, user.password_confirmation = 'test', 'test'
18 user.save!
19
20 log_user('miscuser9','test')
21
22 get "/admin"
23 assert_response :forbidden
24 assert_select "#admin-menu", :count => 0
25 end
26 end
@@ -1,398 +1,405
1 # redMine - project management software
1 # redMine - project management software
2 # Copyright (C) 2006-2007 Jean-Philippe Lang
2 # Copyright (C) 2006-2007 Jean-Philippe Lang
3 #
3 #
4 # This program is free software; you can redistribute it and/or
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
7 # of the License, or (at your option) any later version.
8 #
8 #
9 # This program is distributed in the hope that it will be useful,
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
12 # GNU General Public License for more details.
13 #
13 #
14 # You should have received a copy of the GNU General Public License
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
17
18 require 'uri'
18 require 'uri'
19 require 'cgi'
19 require 'cgi'
20
20
21 class ApplicationController < ActionController::Base
21 class ApplicationController < ActionController::Base
22 include Redmine::I18n
22 include Redmine::I18n
23
23
24 layout 'base'
24 layout 'base'
25 exempt_from_layout 'builder'
25 exempt_from_layout 'builder'
26
26
27 # Remove broken cookie after upgrade from 0.8.x (#4292)
27 # Remove broken cookie after upgrade from 0.8.x (#4292)
28 # See https://rails.lighthouseapp.com/projects/8994/tickets/3360
28 # See https://rails.lighthouseapp.com/projects/8994/tickets/3360
29 # TODO: remove it when Rails is fixed
29 # TODO: remove it when Rails is fixed
30 before_filter :delete_broken_cookies
30 before_filter :delete_broken_cookies
31 def delete_broken_cookies
31 def delete_broken_cookies
32 if cookies['_redmine_session'] && cookies['_redmine_session'] !~ /--/
32 if cookies['_redmine_session'] && cookies['_redmine_session'] !~ /--/
33 cookies.delete '_redmine_session'
33 cookies.delete '_redmine_session'
34 redirect_to home_path
34 redirect_to home_path
35 return false
35 return false
36 end
36 end
37 end
37 end
38
38
39 before_filter :user_setup, :check_if_login_required, :set_localization
39 before_filter :user_setup, :check_if_login_required, :set_localization
40 filter_parameter_logging :password
40 filter_parameter_logging :password
41 protect_from_forgery
41 protect_from_forgery
42
42
43 rescue_from ActionController::InvalidAuthenticityToken, :with => :invalid_authenticity_token
43 rescue_from ActionController::InvalidAuthenticityToken, :with => :invalid_authenticity_token
44
44
45 include Redmine::Search::Controller
45 include Redmine::Search::Controller
46 include Redmine::MenuManager::MenuController
46 include Redmine::MenuManager::MenuController
47 helper Redmine::MenuManager::MenuHelper
47 helper Redmine::MenuManager::MenuHelper
48
48
49 Redmine::Scm::Base.all.each do |scm|
49 Redmine::Scm::Base.all.each do |scm|
50 require_dependency "repository/#{scm.underscore}"
50 require_dependency "repository/#{scm.underscore}"
51 end
51 end
52
52
53 def user_setup
53 def user_setup
54 # Check the settings cache for each request
54 # Check the settings cache for each request
55 Setting.check_cache
55 Setting.check_cache
56 # Find the current user
56 # Find the current user
57 User.current = find_current_user
57 User.current = find_current_user
58 end
58 end
59
59
60 # Returns the current user or nil if no user is logged in
60 # Returns the current user or nil if no user is logged in
61 # and starts a session if needed
61 # and starts a session if needed
62 def find_current_user
62 def find_current_user
63 if session[:user_id]
63 if session[:user_id]
64 # existing session
64 # existing session
65 (User.active.find(session[:user_id]) rescue nil)
65 (User.active.find(session[:user_id]) rescue nil)
66 elsif cookies[:autologin] && Setting.autologin?
66 elsif cookies[:autologin] && Setting.autologin?
67 # auto-login feature starts a new session
67 # auto-login feature starts a new session
68 user = User.try_to_autologin(cookies[:autologin])
68 user = User.try_to_autologin(cookies[:autologin])
69 session[:user_id] = user.id if user
69 session[:user_id] = user.id if user
70 user
70 user
71 elsif params[:format] == 'atom' && params[:key] && accept_key_auth_actions.include?(params[:action])
71 elsif params[:format] == 'atom' && params[:key] && accept_key_auth_actions.include?(params[:action])
72 # RSS key authentication does not start a session
72 # RSS key authentication does not start a session
73 User.find_by_rss_key(params[:key])
73 User.find_by_rss_key(params[:key])
74 elsif Setting.rest_api_enabled? && ['xml', 'json'].include?(params[:format])
74 elsif Setting.rest_api_enabled? && ['xml', 'json'].include?(params[:format])
75 if params[:key].present? && accept_key_auth_actions.include?(params[:action])
75 if params[:key].present? && accept_key_auth_actions.include?(params[:action])
76 # Use API key
76 # Use API key
77 User.find_by_api_key(params[:key])
77 User.find_by_api_key(params[:key])
78 else
78 else
79 # HTTP Basic, either username/password or API key/random
79 # HTTP Basic, either username/password or API key/random
80 authenticate_with_http_basic do |username, password|
80 authenticate_with_http_basic do |username, password|
81 User.try_to_login(username, password) || User.find_by_api_key(username)
81 User.try_to_login(username, password) || User.find_by_api_key(username)
82 end
82 end
83 end
83 end
84 end
84 end
85 end
85 end
86
86
87 # Sets the logged in user
87 # Sets the logged in user
88 def logged_user=(user)
88 def logged_user=(user)
89 reset_session
89 reset_session
90 if user && user.is_a?(User)
90 if user && user.is_a?(User)
91 User.current = user
91 User.current = user
92 session[:user_id] = user.id
92 session[:user_id] = user.id
93 else
93 else
94 User.current = User.anonymous
94 User.current = User.anonymous
95 end
95 end
96 end
96 end
97
97
98 # check if login is globally required to access the application
98 # check if login is globally required to access the application
99 def check_if_login_required
99 def check_if_login_required
100 # no check needed if user is already logged in
100 # no check needed if user is already logged in
101 return true if User.current.logged?
101 return true if User.current.logged?
102 require_login if Setting.login_required?
102 require_login if Setting.login_required?
103 end
103 end
104
104
105 def set_localization
105 def set_localization
106 lang = nil
106 lang = nil
107 if User.current.logged?
107 if User.current.logged?
108 lang = find_language(User.current.language)
108 lang = find_language(User.current.language)
109 end
109 end
110 if lang.nil? && request.env['HTTP_ACCEPT_LANGUAGE']
110 if lang.nil? && request.env['HTTP_ACCEPT_LANGUAGE']
111 accept_lang = parse_qvalues(request.env['HTTP_ACCEPT_LANGUAGE']).first
111 accept_lang = parse_qvalues(request.env['HTTP_ACCEPT_LANGUAGE']).first
112 if !accept_lang.blank?
112 if !accept_lang.blank?
113 accept_lang = accept_lang.downcase
113 accept_lang = accept_lang.downcase
114 lang = find_language(accept_lang) || find_language(accept_lang.split('-').first)
114 lang = find_language(accept_lang) || find_language(accept_lang.split('-').first)
115 end
115 end
116 end
116 end
117 lang ||= Setting.default_language
117 lang ||= Setting.default_language
118 set_language_if_valid(lang)
118 set_language_if_valid(lang)
119 end
119 end
120
120
121 def require_login
121 def require_login
122 if !User.current.logged?
122 if !User.current.logged?
123 # Extract only the basic url parameters on non-GET requests
123 # Extract only the basic url parameters on non-GET requests
124 if request.get?
124 if request.get?
125 url = url_for(params)
125 url = url_for(params)
126 else
126 else
127 url = url_for(:controller => params[:controller], :action => params[:action], :id => params[:id], :project_id => params[:project_id])
127 url = url_for(:controller => params[:controller], :action => params[:action], :id => params[:id], :project_id => params[:project_id])
128 end
128 end
129 respond_to do |format|
129 respond_to do |format|
130 format.html { redirect_to :controller => "account", :action => "login", :back_url => url }
130 format.html { redirect_to :controller => "account", :action => "login", :back_url => url }
131 format.atom { redirect_to :controller => "account", :action => "login", :back_url => url }
131 format.atom { redirect_to :controller => "account", :action => "login", :back_url => url }
132 format.xml { head :unauthorized, 'WWW-Authenticate' => 'Basic realm="Redmine API"' }
132 format.xml { head :unauthorized, 'WWW-Authenticate' => 'Basic realm="Redmine API"' }
133 format.js { head :unauthorized, 'WWW-Authenticate' => 'Basic realm="Redmine API"' }
133 format.js { head :unauthorized, 'WWW-Authenticate' => 'Basic realm="Redmine API"' }
134 format.json { head :unauthorized, 'WWW-Authenticate' => 'Basic realm="Redmine API"' }
134 format.json { head :unauthorized, 'WWW-Authenticate' => 'Basic realm="Redmine API"' }
135 end
135 end
136 return false
136 return false
137 end
137 end
138 true
138 true
139 end
139 end
140
140
141 def require_admin
141 def require_admin
142 return unless require_login
142 return unless require_login
143 if !User.current.admin?
143 if !User.current.admin?
144 render_403
144 render_403
145 return false
145 return false
146 end
146 end
147 true
147 true
148 end
148 end
149
149
150 def deny_access
150 def deny_access
151 User.current.logged? ? render_403 : require_login
151 User.current.logged? ? render_403 : require_login
152 end
152 end
153
153
154 # Authorize the user for the requested action
154 # Authorize the user for the requested action
155 def authorize(ctrl = params[:controller], action = params[:action], global = false)
155 def authorize(ctrl = params[:controller], action = params[:action], global = false)
156 allowed = User.current.allowed_to?({:controller => ctrl, :action => action}, @project, :global => global)
156 allowed = User.current.allowed_to?({:controller => ctrl, :action => action}, @project, :global => global)
157 allowed ? true : deny_access
157 allowed ? true : deny_access
158 end
158 end
159
159
160 # Authorize the user for the requested action outside a project
160 # Authorize the user for the requested action outside a project
161 def authorize_global(ctrl = params[:controller], action = params[:action], global = true)
161 def authorize_global(ctrl = params[:controller], action = params[:action], global = true)
162 authorize(ctrl, action, global)
162 authorize(ctrl, action, global)
163 end
163 end
164
164
165 # Find project of id params[:id]
165 # Find project of id params[:id]
166 def find_project
166 def find_project
167 @project = Project.find(params[:id])
167 @project = Project.find(params[:id])
168 rescue ActiveRecord::RecordNotFound
168 rescue ActiveRecord::RecordNotFound
169 render_404
169 render_404
170 end
170 end
171
171
172 # Find a project based on params[:project_id]
172 # Find a project based on params[:project_id]
173 # TODO: some subclasses override this, see about merging their logic
173 # TODO: some subclasses override this, see about merging their logic
174 def find_optional_project
174 def find_optional_project
175 @project = Project.find(params[:project_id]) unless params[:project_id].blank?
175 @project = Project.find(params[:project_id]) unless params[:project_id].blank?
176 allowed = User.current.allowed_to?({:controller => params[:controller], :action => params[:action]}, @project, :global => true)
176 allowed = User.current.allowed_to?({:controller => params[:controller], :action => params[:action]}, @project, :global => true)
177 allowed ? true : deny_access
177 allowed ? true : deny_access
178 rescue ActiveRecord::RecordNotFound
178 rescue ActiveRecord::RecordNotFound
179 render_404
179 render_404
180 end
180 end
181
181
182 # Finds and sets @project based on @object.project
182 # Finds and sets @project based on @object.project
183 def find_project_from_association
183 def find_project_from_association
184 render_404 unless @object.present?
184 render_404 unless @object.present?
185
185
186 @project = @object.project
186 @project = @object.project
187 rescue ActiveRecord::RecordNotFound
187 rescue ActiveRecord::RecordNotFound
188 render_404
188 render_404
189 end
189 end
190
190
191 def find_model_object
191 def find_model_object
192 model = self.class.read_inheritable_attribute('model_object')
192 model = self.class.read_inheritable_attribute('model_object')
193 if model
193 if model
194 @object = model.find(params[:id])
194 @object = model.find(params[:id])
195 self.instance_variable_set('@' + controller_name.singularize, @object) if @object
195 self.instance_variable_set('@' + controller_name.singularize, @object) if @object
196 end
196 end
197 rescue ActiveRecord::RecordNotFound
197 rescue ActiveRecord::RecordNotFound
198 render_404
198 render_404
199 end
199 end
200
200
201 def self.model_object(model)
201 def self.model_object(model)
202 write_inheritable_attribute('model_object', model)
202 write_inheritable_attribute('model_object', model)
203 end
203 end
204
204
205 # Filter for bulk issue operations
205 # Filter for bulk issue operations
206 def find_issues
206 def find_issues
207 @issues = Issue.find_all_by_id(params[:id] || params[:ids])
207 @issues = Issue.find_all_by_id(params[:id] || params[:ids])
208 raise ActiveRecord::RecordNotFound if @issues.empty?
208 raise ActiveRecord::RecordNotFound if @issues.empty?
209 projects = @issues.collect(&:project).compact.uniq
209 projects = @issues.collect(&:project).compact.uniq
210 if projects.size == 1
210 if projects.size == 1
211 @project = projects.first
211 @project = projects.first
212 else
212 else
213 # TODO: let users bulk edit/move/destroy issues from different projects
213 # TODO: let users bulk edit/move/destroy issues from different projects
214 render_error 'Can not bulk edit/move/destroy issues from different projects'
214 render_error 'Can not bulk edit/move/destroy issues from different projects'
215 return false
215 return false
216 end
216 end
217 rescue ActiveRecord::RecordNotFound
217 rescue ActiveRecord::RecordNotFound
218 render_404
218 render_404
219 end
219 end
220
220
221 # make sure that the user is a member of the project (or admin) if project is private
221 # make sure that the user is a member of the project (or admin) if project is private
222 # used as a before_filter for actions that do not require any particular permission on the project
222 # used as a before_filter for actions that do not require any particular permission on the project
223 def check_project_privacy
223 def check_project_privacy
224 if @project && @project.active?
224 if @project && @project.active?
225 if @project.is_public? || User.current.member_of?(@project) || User.current.admin?
225 if @project.is_public? || User.current.member_of?(@project) || User.current.admin?
226 true
226 true
227 else
227 else
228 User.current.logged? ? render_403 : require_login
228 User.current.logged? ? render_403 : require_login
229 end
229 end
230 else
230 else
231 @project = nil
231 @project = nil
232 render_404
232 render_404
233 false
233 false
234 end
234 end
235 end
235 end
236
236
237 def back_url
237 def back_url
238 params[:back_url] || request.env['HTTP_REFERER']
238 params[:back_url] || request.env['HTTP_REFERER']
239 end
239 end
240
240
241 def redirect_back_or_default(default)
241 def redirect_back_or_default(default)
242 back_url = CGI.unescape(params[:back_url].to_s)
242 back_url = CGI.unescape(params[:back_url].to_s)
243 if !back_url.blank?
243 if !back_url.blank?
244 begin
244 begin
245 uri = URI.parse(back_url)
245 uri = URI.parse(back_url)
246 # do not redirect user to another host or to the login or register page
246 # do not redirect user to another host or to the login or register page
247 if (uri.relative? || (uri.host == request.host)) && !uri.path.match(%r{/(login|account/register)})
247 if (uri.relative? || (uri.host == request.host)) && !uri.path.match(%r{/(login|account/register)})
248 redirect_to(back_url)
248 redirect_to(back_url)
249 return
249 return
250 end
250 end
251 rescue URI::InvalidURIError
251 rescue URI::InvalidURIError
252 # redirect to default
252 # redirect to default
253 end
253 end
254 end
254 end
255 redirect_to default
255 redirect_to default
256 end
256 end
257
257
258 def render_403
258 def render_403
259 @project = nil
259 @project = nil
260 respond_to do |format|
260 respond_to do |format|
261 format.html { render :template => "common/403", :layout => (request.xhr? ? false : 'base'), :status => 403 }
261 format.html { render :template => "common/403", :layout => use_layout, :status => 403 }
262 format.atom { head 403 }
262 format.atom { head 403 }
263 format.xml { head 403 }
263 format.xml { head 403 }
264 format.js { head 403 }
264 format.js { head 403 }
265 format.json { head 403 }
265 format.json { head 403 }
266 end
266 end
267 return false
267 return false
268 end
268 end
269
269
270 def render_404
270 def render_404
271 respond_to do |format|
271 respond_to do |format|
272 format.html { render :template => "common/404", :layout => !request.xhr?, :status => 404 }
272 format.html { render :template => "common/404", :layout => use_layout, :status => 404 }
273 format.atom { head 404 }
273 format.atom { head 404 }
274 format.xml { head 404 }
274 format.xml { head 404 }
275 format.js { head 404 }
275 format.js { head 404 }
276 format.json { head 404 }
276 format.json { head 404 }
277 end
277 end
278 return false
278 return false
279 end
279 end
280
280
281 def render_error(msg)
281 def render_error(msg)
282 respond_to do |format|
282 respond_to do |format|
283 format.html {
283 format.html {
284 flash.now[:error] = msg
284 flash.now[:error] = msg
285 render :text => '', :layout => !request.xhr?, :status => 500
285 render :text => '', :layout => use_layout, :status => 500
286 }
286 }
287 format.atom { head 500 }
287 format.atom { head 500 }
288 format.xml { head 500 }
288 format.xml { head 500 }
289 format.js { head 500 }
289 format.js { head 500 }
290 format.json { head 500 }
290 format.json { head 500 }
291 end
291 end
292 end
292 end
293
294 # Picks which layout to use based on the request
295 #
296 # @return [boolean, string] name of the layout to use or false for no layout
297 def use_layout
298 request.xhr? ? false : 'base'
299 end
293
300
294 def invalid_authenticity_token
301 def invalid_authenticity_token
295 if api_request?
302 if api_request?
296 logger.error "Form authenticity token is missing or is invalid. API calls must include a proper Content-type header (text/xml or text/json)."
303 logger.error "Form authenticity token is missing or is invalid. API calls must include a proper Content-type header (text/xml or text/json)."
297 end
304 end
298 render_error "Invalid form authenticity token."
305 render_error "Invalid form authenticity token."
299 end
306 end
300
307
301 def render_feed(items, options={})
308 def render_feed(items, options={})
302 @items = items || []
309 @items = items || []
303 @items.sort! {|x,y| y.event_datetime <=> x.event_datetime }
310 @items.sort! {|x,y| y.event_datetime <=> x.event_datetime }
304 @items = @items.slice(0, Setting.feeds_limit.to_i)
311 @items = @items.slice(0, Setting.feeds_limit.to_i)
305 @title = options[:title] || Setting.app_title
312 @title = options[:title] || Setting.app_title
306 render :template => "common/feed.atom.rxml", :layout => false, :content_type => 'application/atom+xml'
313 render :template => "common/feed.atom.rxml", :layout => false, :content_type => 'application/atom+xml'
307 end
314 end
308
315
309 def self.accept_key_auth(*actions)
316 def self.accept_key_auth(*actions)
310 actions = actions.flatten.map(&:to_s)
317 actions = actions.flatten.map(&:to_s)
311 write_inheritable_attribute('accept_key_auth_actions', actions)
318 write_inheritable_attribute('accept_key_auth_actions', actions)
312 end
319 end
313
320
314 def accept_key_auth_actions
321 def accept_key_auth_actions
315 self.class.read_inheritable_attribute('accept_key_auth_actions') || []
322 self.class.read_inheritable_attribute('accept_key_auth_actions') || []
316 end
323 end
317
324
318 # Returns the number of objects that should be displayed
325 # Returns the number of objects that should be displayed
319 # on the paginated list
326 # on the paginated list
320 def per_page_option
327 def per_page_option
321 per_page = nil
328 per_page = nil
322 if params[:per_page] && Setting.per_page_options_array.include?(params[:per_page].to_s.to_i)
329 if params[:per_page] && Setting.per_page_options_array.include?(params[:per_page].to_s.to_i)
323 per_page = params[:per_page].to_s.to_i
330 per_page = params[:per_page].to_s.to_i
324 session[:per_page] = per_page
331 session[:per_page] = per_page
325 elsif session[:per_page]
332 elsif session[:per_page]
326 per_page = session[:per_page]
333 per_page = session[:per_page]
327 else
334 else
328 per_page = Setting.per_page_options_array.first || 25
335 per_page = Setting.per_page_options_array.first || 25
329 end
336 end
330 per_page
337 per_page
331 end
338 end
332
339
333 # qvalues http header parser
340 # qvalues http header parser
334 # code taken from webrick
341 # code taken from webrick
335 def parse_qvalues(value)
342 def parse_qvalues(value)
336 tmp = []
343 tmp = []
337 if value
344 if value
338 parts = value.split(/,\s*/)
345 parts = value.split(/,\s*/)
339 parts.each {|part|
346 parts.each {|part|
340 if m = %r{^([^\s,]+?)(?:;\s*q=(\d+(?:\.\d+)?))?$}.match(part)
347 if m = %r{^([^\s,]+?)(?:;\s*q=(\d+(?:\.\d+)?))?$}.match(part)
341 val = m[1]
348 val = m[1]
342 q = (m[2] or 1).to_f
349 q = (m[2] or 1).to_f
343 tmp.push([val, q])
350 tmp.push([val, q])
344 end
351 end
345 }
352 }
346 tmp = tmp.sort_by{|val, q| -q}
353 tmp = tmp.sort_by{|val, q| -q}
347 tmp.collect!{|val, q| val}
354 tmp.collect!{|val, q| val}
348 end
355 end
349 return tmp
356 return tmp
350 rescue
357 rescue
351 nil
358 nil
352 end
359 end
353
360
354 # Returns a string that can be used as filename value in Content-Disposition header
361 # Returns a string that can be used as filename value in Content-Disposition header
355 def filename_for_content_disposition(name)
362 def filename_for_content_disposition(name)
356 request.env['HTTP_USER_AGENT'] =~ %r{MSIE} ? ERB::Util.url_encode(name) : name
363 request.env['HTTP_USER_AGENT'] =~ %r{MSIE} ? ERB::Util.url_encode(name) : name
357 end
364 end
358
365
359 def api_request?
366 def api_request?
360 %w(xml json).include? params[:format]
367 %w(xml json).include? params[:format]
361 end
368 end
362
369
363 # Renders a warning flash if obj has unsaved attachments
370 # Renders a warning flash if obj has unsaved attachments
364 def render_attachment_warning_if_needed(obj)
371 def render_attachment_warning_if_needed(obj)
365 flash[:warning] = l(:warning_attachments_not_saved, obj.unsaved_attachments.size) if obj.unsaved_attachments.present?
372 flash[:warning] = l(:warning_attachments_not_saved, obj.unsaved_attachments.size) if obj.unsaved_attachments.present?
366 end
373 end
367
374
368 # Sets the `flash` notice or error based the number of issues that did not save
375 # Sets the `flash` notice or error based the number of issues that did not save
369 #
376 #
370 # @param [Array, Issue] issues all of the saved and unsaved Issues
377 # @param [Array, Issue] issues all of the saved and unsaved Issues
371 # @param [Array, Integer] unsaved_issue_ids the issue ids that were not saved
378 # @param [Array, Integer] unsaved_issue_ids the issue ids that were not saved
372 def set_flash_from_bulk_issue_save(issues, unsaved_issue_ids)
379 def set_flash_from_bulk_issue_save(issues, unsaved_issue_ids)
373 if unsaved_issue_ids.empty?
380 if unsaved_issue_ids.empty?
374 flash[:notice] = l(:notice_successful_update) unless issues.empty?
381 flash[:notice] = l(:notice_successful_update) unless issues.empty?
375 else
382 else
376 flash[:error] = l(:notice_failed_to_save_issues,
383 flash[:error] = l(:notice_failed_to_save_issues,
377 :count => unsaved_issue_ids.size,
384 :count => unsaved_issue_ids.size,
378 :total => issues.size,
385 :total => issues.size,
379 :ids => '#' + unsaved_issue_ids.join(', #'))
386 :ids => '#' + unsaved_issue_ids.join(', #'))
380 end
387 end
381 end
388 end
382
389
383 # Rescues an invalid query statement. Just in case...
390 # Rescues an invalid query statement. Just in case...
384 def query_statement_invalid(exception)
391 def query_statement_invalid(exception)
385 logger.error "Query::StatementInvalid: #{exception.message}" if logger
392 logger.error "Query::StatementInvalid: #{exception.message}" if logger
386 session.delete(:query)
393 session.delete(:query)
387 sort_clear if respond_to?(:sort_clear)
394 sort_clear if respond_to?(:sort_clear)
388 render_error "An error occurred while executing the query and has been logged. Please report this error to your Redmine administrator."
395 render_error "An error occurred while executing the query and has been logged. Please report this error to your Redmine administrator."
389 end
396 end
390
397
391 # Converts the errors on an ActiveRecord object into a common JSON format
398 # Converts the errors on an ActiveRecord object into a common JSON format
392 def object_errors_to_json(object)
399 def object_errors_to_json(object)
393 object.errors.collect do |attribute, error|
400 object.errors.collect do |attribute, error|
394 { attribute => error }
401 { attribute => error }
395 end.to_json
402 end.to_json
396 end
403 end
397
404
398 end
405 end
General Comments 0
You need to be logged in to leave comments. Login now