Commit 9f7e2a00 authored by azul's avatar azul
Browse files

cleanup error handling - in particular Wiki section not found

parent 94efa26b
......@@ -121,7 +121,7 @@ module Common::Application::RescueErrors
render_auth_error_html(exception)
end
format.js do
render_error_js(exception)
render_error_js(exception, status: 401)
end
format.xml do
headers["Status"] = "Unauthorized"
......@@ -267,7 +267,8 @@ module Common::Application::RescueErrors
error exception if exception.present?
log_exception(exception)
return if performed? # error in after_filter
render template: 'error/alert', locals: {exception: exception}
render template: 'error/alert', locals: {exception: exception},
status: options[:status]
end
def log_exception(exception)
......
......@@ -22,7 +22,7 @@ class Wikis::LocksController < Wikis::BaseController
def destroy
@wiki.release_my_lock!(@section, current_user)
head :accepted
rescue Wiki::SectionNotFound
rescue WikiExtension::Sections::SectionNotFoundError
head :not_found
end
......
......@@ -15,9 +15,7 @@ module Wikis::SectionsHelper
def find_heading_node(doc, section)
return nil if section.nil?
anchor = doc.at("a[@name=#{section}]")
if anchor.nil?
raise Wiki::SectionNotFoundError.new(section)
end
return anchor.parent if anchor.present?
anchor.parent
end
......@@ -42,7 +40,7 @@ module Wikis::SectionsHelper
heading = find_heading_node(doc, section)
# everything between replace_node and next_node should be wrapped
end_before = find_heading_node(doc, wiki.successor_for_section(section).try.name) rescue nil
end_before = find_heading_node(doc, wiki.successor_for_section(section).try.name)
# these nodes should be wrapped
wrapped_nodes = []
......
......@@ -45,7 +45,7 @@ module WikiExtension
def find(section)
node = green_tree if section == :document
node ||= green_tree.find(section)
return node || (raise Wiki::SectionNotFoundError.new(section))
return node || (raise WikiExtension::Sections::SectionNotFoundError.new(section))
end
end
end
......@@ -66,7 +66,8 @@ module Crabgrass
# add our custom 404 error class
config.action_dispatch.rescue_responses.merge!(
'ErrorNotFound' => :not_found
'ErrorNotFound' => :not_found,
'WikiExtension::Sections::SectionNotFoundError' => :not_found
)
# Make Active Record use UTC-base instead of local time
config.time_zone = 'UTC'
......
......@@ -12,21 +12,28 @@ class Wikis::LocksControllerTest < ActionController::TestCase
@wiki.lock!(:document, @user)
end
def test_section_not_found
@wiki = Wiki.create group: @group
login_as @user
xhr :delete, :destroy, wiki_id: @wiki.id, section: :bla
assert_response :not_found
end
def test_destroy_own_lock
login_as @user
delete :destroy, wiki_id: @wiki.id
xhr :delete, :destroy, wiki_id: @wiki.id
assert_nil @wiki.reload.section_edited_by(@user)
end
def test_cannot_destroy_other_peoples_locks
login_as @user2
delete :destroy, wiki_id: @wiki.id
xhr :delete, :destroy, wiki_id: @wiki.id
assert_equal :document, @wiki.reload.section_edited_by(@user)
end
def test_cannot_destroy_locks_when_logged_out
delete :destroy, wiki_id: @wiki
assert_login_required
xhr :delete, :destroy, wiki_id: @wiki
assert_response 401
assert_equal :document, @wiki.reload.section_edited_by(@user)
end
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment