Unsuccessful save unlocks the page; some tweaks and debug-level logging in in return_to_last_remembered

This commit is contained in:
Alexey Verkhovsky 2005-01-18 00:36:43 +00:00
parent 94292199b2
commit 7c02805102
3 changed files with 15 additions and 8 deletions

View file

@ -28,12 +28,15 @@ class ApplicationController < ActionController::Base
$instiki_wiki_service $instiki_wiki_service
end end
@@REMEMBER_NOT = [] @@REMEMBER_NOT = ['locked', 'save']
def remember_location def remember_location
logger.debug @request.method
if @response.headers['Status'] == '200 OK' if @response.headers['Status'] == '200 OK'
@session[:return_to] = url_for unless @@REMEMBER_NOT.include? action_name unless @@REMEMBER_NOT.include? action_name or @request.method != :get
@session[:already_tried_index_as_fallback] = false @session[:return_to] = url_for
logger.debug("Session ##{session.object_id}: remembered URL '#{@session[:return_to]}'")
end
end end
end end
@ -42,10 +45,11 @@ class ApplicationController < ActionController::Base
redirect_target, @session[:return_to] = @session[:return_to], nil redirect_target, @session[:return_to] = @session[:return_to], nil
# then try to redirect to it # then try to redirect to it
if redirect_target.nil? if redirect_target.nil?
raise 'Cannot redirect to index' if @session[:already_tried_index_as_fallback] logger.debug("Session ##{session.object_id}: no remembered redirect location, trying /")
@session[:already_tried_index_as_fallback] = true
redirect_to_url '/' redirect_to_url '/'
else else
logger.debug("Session ##{session.object_id}: " +
"redirect to the last remembered URL #{redirect_target}")
redirect_to_url(redirect_target) redirect_to_url(redirect_target)
end end
end end

View file

@ -216,20 +216,22 @@ class WikiController < ApplicationController
cookies['author'] = @params['author'] cookies['author'] = @params['author']
begin begin
page = @web.pages[@page_name]
if @web.pages[@page_name] if @web.pages[@page_name]
page = wiki.revise_page( wiki.revise_page(
@web_name, @page_name, @params['content'], Time.now, @web_name, @page_name, @params['content'], Time.now,
Author.new(@params['author'], remote_ip) Author.new(@params['author'], remote_ip)
) )
page.unlock page.unlock
else else
page = wiki.write_page( wiki.write_page(
@web_name, @page_name, @params['content'], Time.now, @web_name, @page_name, @params['content'], Time.now,
Author.new(@params['author'], remote_ip) Author.new(@params['author'], remote_ip)
) )
end end
redirect_show(@page_name) redirect_show(@page_name)
rescue Instiki::ValidationError => e rescue Instiki::ValidationError => e
page.unlock if defined? page
flash[:error] = e flash[:error] = e
return_to_last_remembered return_to_last_remembered
end end

View file

@ -542,6 +542,7 @@ class WikiControllerTest < Test::Unit::TestCase
def test_save_new_revision_identical_to_last def test_save_new_revision_identical_to_last
revisions_before = @home.revisions.size revisions_before = @home.revisions.size
@home.lock(Time.now, 'AnAuthor')
r = process 'save', {'web' => 'wiki1', 'id' => 'HomePage', r = process 'save', {'web' => 'wiki1', 'id' => 'HomePage',
'content' => @home.revisions.last.content.dup, 'content' => @home.revisions.last.content.dup,
@ -553,7 +554,7 @@ class WikiControllerTest < Test::Unit::TestCase
revisions_after = @home.revisions.size revisions_after = @home.revisions.size
assert_equal revisions_before, revisions_after assert_equal revisions_before, revisions_after
assert !@home.locked?(Time.now), 'HomePage should be unlocked if an edit was unsuccessful'
end end