From ae4b1cdeca29f92621cd7bc87963a0ecff316bbb Mon Sep 17 00:00:00 2001 From: Keith Duncan Date: Sat, 15 Sep 2012 17:21:01 +0100 Subject: [PATCH 1/4] Add support for author parameters coming in from the session, to be set by rack middleware further up the stack --- lib/gollum/frontend/app.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/gollum/frontend/app.rb b/lib/gollum/frontend/app.rb index 05468abe..b163e6af 100644 --- a/lib/gollum/frontend/app.rb +++ b/lib/gollum/frontend/app.rb @@ -369,8 +369,13 @@ module Precious wiki.update_page(page, name, format, content.to_s, commit) end + private + def commit_message - { :message => params[:message] } + commit_message = { :message => params[:message] } + author_parameters = session['gollum.author'] + commit_message.merge! author_parameters unless author_parameters.nil? + commit_message end end end From 7dee787a923b67786a9c427705ac99627e79afbc Mon Sep 17 00:00:00 2001 From: Keith Duncan Date: Sun, 16 Sep 2012 15:59:49 +0100 Subject: [PATCH 2/4] Add documentation for where the commit_message parameters are passed and where they're source from --- lib/gollum/frontend/app.rb | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/gollum/frontend/app.rb b/lib/gollum/frontend/app.rb index b163e6af..fee66f0f 100644 --- a/lib/gollum/frontend/app.rb +++ b/lib/gollum/frontend/app.rb @@ -371,6 +371,12 @@ module Precious private + # Options parameter to Gollum::Committer#initialize + # :message - The String commit message. + # :name - The String author full name. + # :email - The String email address. + # message is sourced from the incoming request parameters + # author details are sourced from the session, to be populated by rack middleware ahead of us def commit_message commit_message = { :message => params[:message] } author_parameters = session['gollum.author'] From ac405803e828cf9b6f42f8362140b79db2de505e Mon Sep 17 00:00:00 2001 From: Keith Duncan Date: Sun, 16 Sep 2012 16:25:09 +0100 Subject: [PATCH 3/4] Add notes on providing author details to the Rack documentation section --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 47023643..2b981308 100644 --- a/README.md +++ b/README.md @@ -497,6 +497,8 @@ like Rack::Auth, OmniAuth, etc. Precious::App.set(:wiki_options, {:universal_toc => false}) run Precious::App +Your Rack middleware can pass author details to Gollum in a Hash in the session under the 'gollum.author' key. + ## WINDOWS FILENAME VALIDATION Note that filenames on windows must not contain any of the following characters `\ / : * ? " < > |`. See [this support article](http://support.microsoft.com/kb/177506) for details. From 30c2e675da57cc3b861fa589f7ceceb23479899b Mon Sep 17 00:00:00 2001 From: Keith Duncan Date: Sun, 16 Sep 2012 16:49:17 +0100 Subject: [PATCH 4/4] Test that author details from the session are committed into the repository --- test/test_app.rb | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/test/test_app.rb b/test/test_app.rb index 52983290..5da184dc 100644 --- a/test/test_app.rb +++ b/test/test_app.rb @@ -274,6 +274,24 @@ context "Frontend" do get "/" assert_match "http://example.org/wiki/Home", last_response.headers['Location'] end + + test "author details in session are used" do + page1 = @wiki.page('A') + + gollum_author = { :name => 'ghi', :email => 'jkl' } + session = { 'gollum.author' => gollum_author } + + post "/edit/A", { :content => 'abc', :page => 'A', :format => page1.format, :message => 'def' }, { 'rack.session' => session } + follow_redirect! + assert last_response.ok? + + @wiki.clear_cache + page2 = @wiki.page(page1.name) + + author = page2.version.author + assert_equal 'ghi', author.name + assert_equal 'jkl', author.email + end def app Precious::App