From 2d5c2b34222c3162348bce664d28360845abe20e Mon Sep 17 00:00:00 2001 From: Henare Degan Date: Sun, 9 Dec 2012 17:59:45 +1100 Subject: This is deprecated and now set in application.rb --- app/controllers/application_controller.rb | 3 --- 1 file changed, 3 deletions(-) (limited to 'app/controllers/application_controller.rb') diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 320d0cc50..79fde5a7f 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -27,9 +27,6 @@ class ApplicationController < ActionController::Base before_filter :set_vary_header before_filter :set_popup_banner - # scrub sensitive parameters from the logs - filter_parameter_logging :password - def set_vary_header response.headers['Vary'] = 'Cookie' end -- cgit v1.2.3 From 4b007cbcc938bd88230ac81e8b377d181d7d9c20 Mon Sep 17 00:00:00 2001 From: Henare Degan Date: Sun, 9 Dec 2012 18:21:05 +1100 Subject: Disable rescue customisations until we can move it to rack --- app/controllers/application_controller.rb | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) (limited to 'app/controllers/application_controller.rb') diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 79fde5a7f..51e37d8f0 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -151,19 +151,20 @@ class ApplicationController < ActionController::Base render :template => "general/exception_caught.rhtml", :status => @status end - # For development sites. - alias original_rescue_action_locally rescue_action_locally - def rescue_action_locally(exception) - # Make sure expiry time for session is set (before_filters are - # otherwise missed by this override) - session_remember_me - - # Make sure the locale is set correctly too - set_gettext_locale - - # Display default, detailed error for developers - original_rescue_action_locally(exception) - end + # FIXME: This was disabled during the Rails 3 upgrade as this is now handled by Rack + # # For development sites. + # alias original_rescue_action_locally rescue_action_locally + # def rescue_action_locally(exception) + # # Make sure expiry time for session is set (before_filters are + # # otherwise missed by this override) + # session_remember_me + + # # Make sure the locale is set correctly too + # set_gettext_locale + + # # Display default, detailed error for developers + # original_rescue_action_locally(exception) + # end def local_request? false -- cgit v1.2.3 From 80c63dd90359712d19671f40dc54bba4e88f7c0c Mon Sep 17 00:00:00 2001 From: Henare Degan Date: Mon, 10 Dec 2012 00:52:25 +1100 Subject: Thought I got this in b0ae75aba63d40146cfbc7e6af27e1d6051f1804 but it must have been set twice - safety first! --- app/controllers/application_controller.rb | 3 --- 1 file changed, 3 deletions(-) (limited to 'app/controllers/application_controller.rb') diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 51e37d8f0..b22adf660 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -71,9 +71,6 @@ class ApplicationController < ActionController::Base end end - # scrub sensitive parameters from the logs - filter_parameter_logging :password - helper_method :locale_from_params # Help work out which request causes RAM spike. -- cgit v1.2.3 From b2f28a42f65c473bbf50bb98c2492518e87c10c4 Mon Sep 17 00:00:00 2001 From: Henare Degan Date: Mon, 10 Dec 2012 01:40:45 +1100 Subject: Using #request_uri is deprecated --- app/controllers/application_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app/controllers/application_controller.rb') diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index b22adf660..3206df1d2 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -240,7 +240,7 @@ class ApplicationController < ActionController::Base # Check the user is logged in def authenticated?(reason_params) unless session[:user_id] - post_redirect = PostRedirect.new(:uri => request.request_uri, :post_params => params, + post_redirect = PostRedirect.new(:uri => request.fullpath, :post_params => params, :reason_params => reason_params) post_redirect.save! # 'modal' controls whether the sign-in form will be displayed in the typical full-blown -- cgit v1.2.3 From f18fc44b0feca3000ff1e84e7453ecb244eaec20 Mon Sep 17 00:00:00 2001 From: Matthew Landauer Date: Tue, 29 Jan 2013 13:34:02 +1100 Subject: Fixup up test_code_redirect_by_email_token for rspec 2 --- app/controllers/application_controller.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'app/controllers/application_controller.rb') diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 9b39d5178..d8206fe76 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -170,6 +170,7 @@ class ApplicationController < ActionController::Base # Called from test code, is a mimic of UserController.confirm, for use in following email # links when in controller tests (though we also have full integration tests that # can work over multiple controllers) + # TODO: Move this to the tests. It shouldn't be here def test_code_redirect_by_email_token(token, controller_example_group) post_redirect = PostRedirect.find_by_email_token(token) if post_redirect.nil? @@ -177,7 +178,7 @@ class ApplicationController < ActionController::Base end session[:user_id] = post_redirect.user.id session[:user_circumstance] = post_redirect.circumstance - params = controller_example_group.params_from(:get, post_redirect.local_part_uri) + params = Rails.application.routes.recognize_path(post_redirect.local_part_uri) params.merge(post_redirect.post_params) controller_example_group.get params[:action], params end -- cgit v1.2.3 From 835b51c1de0d49e652fe9c9a60f0974275de070c Mon Sep 17 00:00:00 2001 From: Henare Degan Date: Wed, 27 Feb 2013 10:34:47 +1100 Subject: Rename ALL THE TEMPLATES!!1!!!one!!1!! .rhtml is deprecated in favour of .erb in Rails 3 --- app/controllers/application_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app/controllers/application_controller.rb') diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 2a2b29bfe..04fd0ed0e 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -145,7 +145,7 @@ class ApplicationController < ActionController::Base @exception_backtrace = exception.backtrace.join("\n") @exception_class = exception.class.to_s @exception_message = exception.message - render :template => "general/exception_caught.rhtml", :status => @status + render :template => "general/exception_caught", :status => @status end # FIXME: This was disabled during the Rails 3 upgrade as this is now handled by Rack -- cgit v1.2.3 From cbdff06aa95a7987b54c712dc6729e138f608eca Mon Sep 17 00:00:00 2001 From: Henare Degan Date: Sun, 3 Mar 2013 14:52:30 +1100 Subject: Rename Configuration class to avoid conflict with ActiveSupport::Configurable --- app/controllers/application_controller.rb | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'app/controllers/application_controller.rb') diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 04fd0ed0e..e86bf5fb3 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -51,12 +51,12 @@ class ApplicationController < ActionController::Base end def set_gettext_locale - if Configuration::include_default_locale_in_urls == false + if AlaveteliConfiguration::include_default_locale_in_urls == false params_locale = params[:locale] ? params[:locale] : I18n.default_locale else params_locale = params[:locale] end - if Configuration::use_default_browser_language + if AlaveteliConfiguration::use_default_browser_language requested_locale = params_locale || session[:locale] || cookies[:locale] || request.env['HTTP_ACCEPT_LANGUAGE'] || I18n.default_locale else requested_locale = params_locale || session[:locale] || cookies[:locale] || I18n.default_locale @@ -86,7 +86,7 @@ class ApplicationController < ActionController::Base # egrep "CONSUME MEMORY: [0-9]{7} KB" production.log around_filter :record_memory def record_memory - record_memory = Configuration::debug_record_memory + record_memory = AlaveteliConfiguration::debug_record_memory if record_memory logger.info "Processing request for #{request.url} with Rails process #{Process.pid}" File.read("/proc/#{Process.pid}/status").match(/VmRSS:\s+(\d+)/) @@ -342,10 +342,10 @@ class ApplicationController < ActionController::Base # def check_read_only - if !Configuration::read_only.empty? + if !AlaveteliConfiguration::read_only.empty? flash[:notice] = _("

{{site_name}} is currently in maintenance. You can only view existing requests. You cannot make new ones, add followups or annotations, or otherwise change the database.

{{read_only}}

", :site_name => site_name, - :read_only => Configuration::read_only) + :read_only => AlaveteliConfiguration::read_only) redirect_to frontpage_url end @@ -552,10 +552,10 @@ class ApplicationController < ActionController::Base def country_from_ip country = "" - if !Configuration::gaze_url.empty? - country = quietly_try_to_open("#{Configuration::gaze_url}/gaze-rest?f=get_country_from_ip;ip=#{request.remote_ip}") + if !AlaveteliConfiguration::gaze_url.empty? + country = quietly_try_to_open("#{AlaveteliConfiguration::gaze_url}/gaze-rest?f=get_country_from_ip;ip=#{request.remote_ip}") end - country = Configuration::iso_country_code if country.empty? + country = AlaveteliConfiguration::iso_country_code if country.empty? return country end -- cgit v1.2.3 From f60b736de4bd00e1012c3baf0606a07423a7d73f Mon Sep 17 00:00:00 2001 From: Henare Degan Date: Tue, 5 Mar 2013 17:15:06 +1100 Subject: Not required with the new version of exception_notification --- app/controllers/application_controller.rb | 3 --- 1 file changed, 3 deletions(-) (limited to 'app/controllers/application_controller.rb') diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index e86bf5fb3..a6df11ef7 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -16,9 +16,6 @@ class ApplicationController < ActionController::Base layout "default" include FastGettext::Translation # make functions like _, n_, N_ etc available) - # Send notification email on exceptions - include ExceptionNotification::Notifiable - # Note: a filter stops the chain if it redirects or renders something before_filter :authentication_check before_filter :set_gettext_locale -- cgit v1.2.3 From 44ec166b8691743e0ffbcc108eaf41ab0d2ef3cd Mon Sep 17 00:00:00 2001 From: Matthew Landauer Date: Tue, 26 Mar 2013 09:47:06 +1100 Subject: Change email address in header of source code to hello@mysociety.org --- app/controllers/application_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app/controllers/application_controller.rb') diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index df522519d..029b536ec 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -5,7 +5,7 @@ # will be available for all controllers. # # Copyright (c) 2007 UK Citizens Online Democracy. All rights reserved. -# Email: francis@mysociety.org; WWW: http://www.mysociety.org/ +# Email: hello@mysociety.org; WWW: http://www.mysociety.org/ require 'open-uri' -- cgit v1.2.3 From 0b6b29f248a74321638f5149800dac777080a95b Mon Sep 17 00:00:00 2001 From: Louise Crow Date: Wed, 1 May 2013 16:37:04 +0100 Subject: Add new error handler method that renders the general/exception_caught template --- app/controllers/application_controller.rb | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'app/controllers/application_controller.rb') diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 029b536ec..d062519bc 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -12,6 +12,11 @@ require 'open-uri' class ApplicationController < ActionController::Base class PermissionDenied < StandardError end + # assign our own handler method for non-local exceptions + if ! Rails.application.config.consider_all_requests_local + rescue_from Exception, :with => :render_exception + end + # Standard headers, footers and navigation for whole site layout "default" include FastGettext::Translation # make functions like _, n_, N_ etc available) @@ -111,6 +116,14 @@ class ApplicationController < ActionController::Base end end + def render_exception(exception) + @exception_backtrace = exception.backtrace.join("\n") + @exception_class = exception.class.to_s + @exception_message = exception.message + status_code = case exception + render :template => "general/exception_caught", :status => status_code + end + # Override default error handler, for production sites. def rescue_action_in_public(exception) # Looks for before_filters called something like `set_view_paths_{themename}`. These -- cgit v1.2.3 From 0d9045ca1c6b2e2c2889e9237ed96ad689eec902 Mon Sep 17 00:00:00 2001 From: Louise Crow Date: Wed, 1 May 2013 16:40:39 +0100 Subject: Return the correct status codes for ActiveRecord::RecordNotFound, ActionController::UnknownAction, PermissionDenied and general exceptions. --- app/controllers/application_controller.rb | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'app/controllers/application_controller.rb') diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index d062519bc..7c9585955 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -121,6 +121,14 @@ class ApplicationController < ActionController::Base @exception_class = exception.class.to_s @exception_message = exception.message status_code = case exception + when ActiveRecord::RecordNotFound, + ActionController::UnknownAction + 404 + when PermissionDenied + 403 + else + 500 + end render :template => "general/exception_caught", :status => status_code end -- cgit v1.2.3 From 6acce073443fbd700f346b1bf99ee72be3e4f387 Mon Sep 17 00:00:00 2001 From: Louise Crow Date: Thu, 2 May 2013 10:23:26 +0100 Subject: Clearer setting of status code, addition of notification. --- app/controllers/application_controller.rb | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) (limited to 'app/controllers/application_controller.rb') diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 7c9585955..b8bdc403c 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -13,9 +13,7 @@ class ApplicationController < ActionController::Base class PermissionDenied < StandardError end # assign our own handler method for non-local exceptions - if ! Rails.application.config.consider_all_requests_local - rescue_from Exception, :with => :render_exception - end + rescue_from Exception, :with => :render_exception # Standard headers, footers and navigation for whole site layout "default" @@ -117,19 +115,28 @@ class ApplicationController < ActionController::Base end def render_exception(exception) + + # In development, or the admin interface, or for a local request, let Rails handle the exception + # with its stack trace templates. Local requests in testing are a special case so that we can + # test this method - there we use consider_all_requests_local to control behaviour. + if Rails.application.config.consider_all_requests_local || local_request? || + (request.local? && !Rails.env.test?) + raise exception + end + @exception_backtrace = exception.backtrace.join("\n") @exception_class = exception.class.to_s @exception_message = exception.message - status_code = case exception - when ActiveRecord::RecordNotFound, - ActionController::UnknownAction - 404 + case exception + when ActiveRecord::RecordNotFound + @status = 404 when PermissionDenied - 403 + @status = 403 else - 500 + ExceptionNotifier::Notifier.exception_notification(request.env, exception).deliver + @status = 500 end - render :template => "general/exception_caught", :status => status_code + render :template => "general/exception_caught", :status => @status end # Override default error handler, for production sites. -- cgit v1.2.3 From 106bbf1976406b9bb212944131758d797f516682 Mon Sep 17 00:00:00 2001 From: Louise Crow Date: Thu, 2 May 2013 10:29:39 +0100 Subject: Handle routing errors with our custom template too. --- app/controllers/application_controller.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'app/controllers/application_controller.rb') diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index b8bdc403c..62479f200 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -12,6 +12,8 @@ require 'open-uri' class ApplicationController < ActionController::Base class PermissionDenied < StandardError end + class RouteNotFound < StandardError + end # assign our own handler method for non-local exceptions rescue_from Exception, :with => :render_exception @@ -128,7 +130,7 @@ class ApplicationController < ActionController::Base @exception_class = exception.class.to_s @exception_message = exception.message case exception - when ActiveRecord::RecordNotFound + when ActiveRecord::RecordNotFound, RouteNotFound @status = 404 when PermissionDenied @status = 403 @@ -173,6 +175,7 @@ class ApplicationController < ActionController::Base render :template => "general/exception_caught", :status => @status end + # FIXME: This was disabled during the Rails 3 upgrade as this is now handled by Rack # # For development sites. # alias original_rescue_action_locally rescue_action_locally -- cgit v1.2.3 From 3fe83080842a71c7d53a40f2ed19b62dfe7ce5f1 Mon Sep 17 00:00:00 2001 From: Louise Crow Date: Thu, 2 May 2013 13:31:54 +0100 Subject: Remove now unused methods --- app/controllers/application_controller.rb | 50 ------------------------------- 1 file changed, 50 deletions(-) (limited to 'app/controllers/application_controller.rb') diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 62479f200..d4ab6bd01 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -141,56 +141,6 @@ class ApplicationController < ActionController::Base render :template => "general/exception_caught", :status => @status end - # Override default error handler, for production sites. - def rescue_action_in_public(exception) - # Looks for before_filters called something like `set_view_paths_{themename}`. These - # are set by the themes. - # Normally, this is called by the theme itself in a - # :before_filter, but when there's an error, this doesn't - # happen. By calling it here, we can ensure error pages are - # still styled according to the theme. - ActionController::Base.before_filters.select{|f| f.to_s =~ /set_view_paths/}.each do |f| - self.send(f) - end - # Make sure expiry time for session is set (before_filters are - # otherwise missed by this override) - session_remember_me - - # Make sure the locale is set correctly too - set_gettext_locale - - case exception - when ActiveRecord::RecordNotFound, ActionController::UnknownAction, ActionController::RoutingError - @status = 404 - when PermissionDenied - @status = 403 - else - @status = 500 - notify_about_exception exception - end - # Display user appropriate error message - @exception_backtrace = exception.backtrace.join("\n") - @exception_class = exception.class.to_s - @exception_message = exception.message - render :template => "general/exception_caught", :status => @status - end - - - # FIXME: This was disabled during the Rails 3 upgrade as this is now handled by Rack - # # For development sites. - # alias original_rescue_action_locally rescue_action_locally - # def rescue_action_locally(exception) - # # Make sure expiry time for session is set (before_filters are - # # otherwise missed by this override) - # session_remember_me - - # # Make sure the locale is set correctly too - # set_gettext_locale - - # # Display default, detailed error for developers - # original_rescue_action_locally(exception) - # end - def local_request? false end -- cgit v1.2.3 From c35b3973726e338857695ab371749db14f4aa5fb Mon Sep 17 00:00:00 2001 From: Louise Crow Date: Thu, 2 May 2013 15:16:42 +0100 Subject: Add logging of any errors. --- app/controllers/application_controller.rb | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'app/controllers/application_controller.rb') diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index d4ab6bd01..2615b61f2 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -135,6 +135,10 @@ class ApplicationController < ActionController::Base when PermissionDenied @status = 403 else + message = "\n#{@exception_class} (#{@exception_message}):\n" + backtrace = Rails.backtrace_cleaner.clean(exception.backtrace, :silent) + message << " " << backtrace.join("\n ") + Rails.logger.fatal("#{message}\n\n") ExceptionNotifier::Notifier.exception_notification(request.env, exception).deliver @status = 500 end -- cgit v1.2.3 From 832da034a6855b94eb5eefd3b3dc4fb8fc9f78a6 Mon Sep 17 00:00:00 2001 From: Louise Crow Date: Mon, 3 Jun 2013 16:07:18 +0100 Subject: For non-HTML requests, just return the response code for now. --- app/controllers/application_controller.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'app/controllers/application_controller.rb') diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 2615b61f2..d1d702616 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -142,7 +142,10 @@ class ApplicationController < ActionController::Base ExceptionNotifier::Notifier.exception_notification(request.env, exception).deliver @status = 500 end - render :template => "general/exception_caught", :status => @status + respond_to do |format| + format.html{ render :template => "general/exception_caught", :status => @status } + format.any{ render :nothing => true, :status => @status } + end end def local_request? -- cgit v1.2.3