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. diff --git a/lib/gollum/frontend/app.rb b/lib/gollum/frontend/app.rb index 05468abe..fee66f0f 100644 --- a/lib/gollum/frontend/app.rb +++ b/lib/gollum/frontend/app.rb @@ -369,8 +369,19 @@ module Precious wiki.update_page(page, name, format, content.to_s, commit) end + 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 - { :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 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