Tweak setting initialization
I could not see a meaningful reason behind calling `forbid` so early in the settings initialization block. But moving the `forbid` call until later resolved this issue. In the real world, I don't see how this would cause issues. But I found that calling `forbid` when `wiki_options[:allow_editing]` was set to false caused order-dependent test errors where Sprockets would end up being badly configured and left without an initialized `Sprockets::Environment` object, which is required by the `sprockets-helpers` gem to resolve asset paths. The test that would cause errors is also in this commit diff. I've updated it to be a bit more readable. I also took this opportunity to review and clean up the `@allow_editing` assignment, which seemed a bit obfuscated.
This commit is contained in:
+3
-4
@@ -103,8 +103,7 @@ module Precious
|
|||||||
end
|
end
|
||||||
|
|
||||||
before do
|
before do
|
||||||
settings.wiki_options[:allow_editing] = settings.wiki_options.fetch(:allow_editing, true)
|
@allow_editing = settings.wiki_options.fetch(:allow_editing, true)
|
||||||
@allow_editing = settings.wiki_options[:allow_editing]
|
|
||||||
@critic_markup = settings.wiki_options[:critic_markup]
|
@critic_markup = settings.wiki_options[:critic_markup]
|
||||||
@redirects_enabled = settings.wiki_options.fetch(:redirects_enabled, true)
|
@redirects_enabled = settings.wiki_options.fetch(:redirects_enabled, true)
|
||||||
@per_page_uploads = settings.wiki_options[:per_page_uploads]
|
@per_page_uploads = settings.wiki_options[:per_page_uploads]
|
||||||
@@ -112,8 +111,6 @@ module Precious
|
|||||||
|
|
||||||
@wiki_title = settings.wiki_options.fetch(:title, 'Gollum Wiki')
|
@wiki_title = settings.wiki_options.fetch(:title, 'Gollum Wiki')
|
||||||
|
|
||||||
forbid unless @allow_editing || request.request_method == 'GET'
|
|
||||||
|
|
||||||
if settings.wiki_options[:template_dir]
|
if settings.wiki_options[:template_dir]
|
||||||
Precious::Views::Layout.extend Precious::Views::TemplateCascade
|
Precious::Views::Layout.extend Precious::Views::TemplateCascade
|
||||||
Precious::Views::Layout.template_priority_path = settings.wiki_options[:template_dir]
|
Precious::Views::Layout.template_priority_path = settings.wiki_options[:template_dir]
|
||||||
@@ -143,6 +140,8 @@ module Precious
|
|||||||
config.manifest = Sprockets::Manifest.new(settings.sprockets, @static_assets_path)
|
config.manifest = Sprockets::Manifest.new(settings.sprockets, @static_assets_path)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
forbid unless @allow_editing || request.request_method == 'GET'
|
||||||
end
|
end
|
||||||
|
|
||||||
get '/' do
|
get '/' do
|
||||||
|
|||||||
@@ -3,8 +3,9 @@ require File.expand_path(File.join(File.dirname(__FILE__), 'helper'))
|
|||||||
|
|
||||||
context "Precious::Views::Editing" do
|
context "Precious::Views::Editing" do
|
||||||
include Rack::Test::Methods
|
include Rack::Test::Methods
|
||||||
|
|
||||||
setup do
|
setup do
|
||||||
@path = cloned_testpath('examples/revert.git')
|
@path = cloned_testpath('examples/revert.git')
|
||||||
Precious::App.set(:gollum_path, @path)
|
Precious::App.set(:gollum_path, @path)
|
||||||
@wiki = Gollum::Wiki.new(@path)
|
@wiki = Gollum::Wiki.new(@path)
|
||||||
end
|
end
|
||||||
@@ -13,14 +14,20 @@ context "Precious::Views::Editing" do
|
|||||||
FileUtils.rm_rf(@path)
|
FileUtils.rm_rf(@path)
|
||||||
end
|
end
|
||||||
|
|
||||||
test "creating page is blocked" do
|
test 'creating pages is blocked' do
|
||||||
Precious::App.set(:wiki_options, { allow_editing: false})
|
Precious::App.set(:wiki_options, {allow_editing: false})
|
||||||
post "/gollum/create", :content => 'abc', :page => "D",
|
|
||||||
:format => 'markdown', :message => 'def'
|
|
||||||
assert !last_response.ok?
|
|
||||||
|
|
||||||
page = @wiki.page('D')
|
post '/gollum/create',
|
||||||
assert page.nil?
|
content: 'abc',
|
||||||
|
format: 'markdown',
|
||||||
|
message: 'def',
|
||||||
|
page: 'D'
|
||||||
|
|
||||||
|
assert last_response.body.include? 'Forbidden. This wiki is set to no-edit mode.'
|
||||||
|
|
||||||
|
refute last_response.ok?
|
||||||
|
|
||||||
|
assert_nil @wiki.page('D')
|
||||||
end
|
end
|
||||||
|
|
||||||
test ".redirects.gollum file should not be accessible" do
|
test ".redirects.gollum file should not be accessible" do
|
||||||
|
|||||||
Reference in New Issue
Block a user