From 7c02805102744f4e439caa40a9afe9f1018e3a63 Mon Sep 17 00:00:00 2001 From: Alexey Verkhovsky Date: Tue, 18 Jan 2005 00:36:43 +0000 Subject: [PATCH] Unsuccessful save unlocks the page; some tweaks and debug-level logging in in return_to_last_remembered --- app/controllers/application.rb | 14 +++++++++----- app/controllers/wiki_controller.rb | 6 ++++-- test/functional/wiki_controller_test.rb | 3 ++- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/app/controllers/application.rb b/app/controllers/application.rb index a6a7480f..09219455 100644 --- a/app/controllers/application.rb +++ b/app/controllers/application.rb @@ -28,12 +28,15 @@ class ApplicationController < ActionController::Base $instiki_wiki_service end - @@REMEMBER_NOT = [] + @@REMEMBER_NOT = ['locked', 'save'] def remember_location +logger.debug @request.method if @response.headers['Status'] == '200 OK' - @session[:return_to] = url_for unless @@REMEMBER_NOT.include? action_name - @session[:already_tried_index_as_fallback] = false + unless @@REMEMBER_NOT.include? action_name or @request.method != :get + @session[:return_to] = url_for + logger.debug("Session ##{session.object_id}: remembered URL '#{@session[:return_to]}'") + end end end @@ -42,10 +45,11 @@ class ApplicationController < ActionController::Base redirect_target, @session[:return_to] = @session[:return_to], nil # then try to redirect to it if redirect_target.nil? - raise 'Cannot redirect to index' if @session[:already_tried_index_as_fallback] - @session[:already_tried_index_as_fallback] = true + logger.debug("Session ##{session.object_id}: no remembered redirect location, trying /") redirect_to_url '/' else + logger.debug("Session ##{session.object_id}: " + + "redirect to the last remembered URL #{redirect_target}") redirect_to_url(redirect_target) end end diff --git a/app/controllers/wiki_controller.rb b/app/controllers/wiki_controller.rb index b641797c..0f711ffc 100755 --- a/app/controllers/wiki_controller.rb +++ b/app/controllers/wiki_controller.rb @@ -216,20 +216,22 @@ class WikiController < ApplicationController cookies['author'] = @params['author'] begin + page = @web.pages[@page_name] if @web.pages[@page_name] - page = wiki.revise_page( + wiki.revise_page( @web_name, @page_name, @params['content'], Time.now, Author.new(@params['author'], remote_ip) ) page.unlock else - page = wiki.write_page( + wiki.write_page( @web_name, @page_name, @params['content'], Time.now, Author.new(@params['author'], remote_ip) ) end redirect_show(@page_name) rescue Instiki::ValidationError => e + page.unlock if defined? page flash[:error] = e return_to_last_remembered end diff --git a/test/functional/wiki_controller_test.rb b/test/functional/wiki_controller_test.rb index 2a11daeb..06d7555c 100755 --- a/test/functional/wiki_controller_test.rb +++ b/test/functional/wiki_controller_test.rb @@ -542,6 +542,7 @@ class WikiControllerTest < Test::Unit::TestCase def test_save_new_revision_identical_to_last revisions_before = @home.revisions.size + @home.lock(Time.now, 'AnAuthor') r = process 'save', {'web' => 'wiki1', 'id' => 'HomePage', 'content' => @home.revisions.last.content.dup, @@ -553,7 +554,7 @@ class WikiControllerTest < Test::Unit::TestCase revisions_after = @home.revisions.size assert_equal revisions_before, revisions_after - + assert !@home.locked?(Time.now), 'HomePage should be unlocked if an edit was unsuccessful' end