Browse Source

Respond with 404 on ActionView::MissingTemplate (#11503).

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@10204 e93f8b46-1217-0410-a6f0-8f06a7374b81
tags/2.1.0
Jean-Philippe Lang 12 years ago
parent
commit
327660eb7f
2 changed files with 15 additions and 5 deletions
  1. 10
    5
      app/controllers/application_controller.rb
  2. 5
    0
      test/integration/application_test.rb

+ 10
- 5
app/controllers/application_controller.rb View File

@@ -39,6 +39,7 @@ class ApplicationController < ActionController::Base

rescue_from ActionController::InvalidAuthenticityToken, :with => :invalid_authenticity_token
rescue_from ::Unauthorized, :with => :deny_access
rescue_from ::ActionView::MissingTemplate, :with => :missing_template

include Redmine::Search::Controller
include Redmine::MenuManager::MenuController
@@ -352,13 +353,17 @@ class ApplicationController < ActionController::Base
format.html {
render :template => 'common/error', :layout => use_layout, :status => @status
}
format.atom { head @status }
format.xml { head @status }
format.js { head @status }
format.json { head @status }
format.any { head @status }
end
end

# Handler for ActionView::MissingTemplate exception
def missing_template
logger.warn "Missing template, responding with 404"
@project = nil
render_404
end

# Filter for actions that provide an API response
# but have no HTML representation for non admin users
def require_admin_or_api_request

+ 5
- 0
test/integration/application_test.rb View File

@@ -60,4 +60,9 @@ class ApplicationTest < ActionController::IntegrationTest
assert_response 200
assert_nil session[:user_id]
end

def test_missing_template_should_respond_with_404
get '/login.png'
assert_response 404
end
end

Loading…
Cancel
Save