From 43077c285129867798ae6961b0019bd3faa27541 Mon Sep 17 00:00:00 2001 From: Karel Picman Date: Wed, 31 Jan 2018 12:35:19 +0100 Subject: [PATCH] #716 dav4rack -> planio/dav4rack --- app/views/settings/_dmsf_settings.html.erb | 9 ------ lib/redmine_dmsf/webdav/base_resource.rb | 1 - lib/redmine_dmsf/webdav/custom_middleware.rb | 31 +++++++++++-------- lib/redmine_dmsf/webdav/resource_proxy.rb | 2 ++ .../dmsf_webdav_custom_middleware_test.rb | 6 ++++ 5 files changed, 26 insertions(+), 23 deletions(-) diff --git a/app/views/settings/_dmsf_settings.html.erb b/app/views/settings/_dmsf_settings.html.erb index 7ac36bda..ded19807 100644 --- a/app/views/settings/_dmsf_settings.html.erb +++ b/app/views/settings/_dmsf_settings.html.erb @@ -272,15 +272,6 @@

-

- <%= content_tag(:label, l(:label_caching_enabled)) %> - <%= check_box_tag('settings[dmsf_webdav_caching_enabled]', false, @settings['dmsf_webdav_caching_enabled']) %> - - <%= l(:note_webdav_cahing_enabled) %>
- <%= l(:label_default)%>: <%= l(:general_text_No)%> -
-

-
<%= l(:label_full_text) %> diff --git a/lib/redmine_dmsf/webdav/base_resource.rb b/lib/redmine_dmsf/webdav/base_resource.rb index fb15b4c1..894c97dd 100644 --- a/lib/redmine_dmsf/webdav/base_resource.rb +++ b/lib/redmine_dmsf/webdav/base_resource.rb @@ -30,7 +30,6 @@ module RedmineDmsf attr_reader :public_path def initialize(path, request, response, options) - raise NotFound unless Setting.plugin_redmine_dmsf['dmsf_webdav'].present? @project = nil @public_path = "#{options[:root_uri_path]}#{path}" super(path, request, response, options) diff --git a/lib/redmine_dmsf/webdav/custom_middleware.rb b/lib/redmine_dmsf/webdav/custom_middleware.rb index 45a5cc61..e60d0fd1 100644 --- a/lib/redmine_dmsf/webdav/custom_middleware.rb +++ b/lib/redmine_dmsf/webdav/custom_middleware.rb @@ -40,21 +40,26 @@ module RedmineDmsf end def call(env) - status, headers, body = @dav_app.call env - # If the URL map generated by Rack::Builder did not find a matching path, - # it will return a 404 along with the X-Cascade header set to 'pass'. - if status == 404 and headers['X-Cascade'] == 'pass' - # The MS web redirector webdav client likes to go up a level and try - # OPTIONS there. We catch that here and respond telling it that just - # plain HTTP is going on. - if 'OPTIONS'.casecmp(env['REQUEST_METHOD'].to_s) == 0 - [ '200', { 'Allow' => 'OPTIONS,HEAD,GET,PUT,POST,DELETE' }, [''] ] + begin + status, headers, body = @dav_app.call env + # If the URL map generated by Rack::Builder did not find a matching path, + # it will return a 404 along with the X-Cascade header set to 'pass'. + if status == 404 and headers['X-Cascade'] == 'pass' + # The MS web redirector webdav client likes to go up a level and try + # OPTIONS there. We catch that here and respond telling it that just + # plain HTTP is going on. + if 'OPTIONS'.casecmp(env['REQUEST_METHOD'].to_s) == 0 + [ '200', { 'Allow' => 'OPTIONS,HEAD,GET,PUT,POST,DELETE' }, [''] ] + else + # let Rails handle the request + @rails_app.call env + end else - # let Rails handle the request - @rails_app.call env + [status, headers, body] end - else - [status, headers, body] + rescue Exception => e + # let Rails handle the request + @rails_app.call env end end diff --git a/lib/redmine_dmsf/webdav/resource_proxy.rb b/lib/redmine_dmsf/webdav/resource_proxy.rb index aef78b5e..ba53e3a8 100644 --- a/lib/redmine_dmsf/webdav/resource_proxy.rb +++ b/lib/redmine_dmsf/webdav/resource_proxy.rb @@ -34,6 +34,8 @@ module RedmineDmsf attr_reader :read_only def initialize(*args) + # Return 404 - NotFound if WebDAV is not enabled + raise NotFound unless Setting.plugin_redmine_dmsf['dmsf_webdav'].present? super(*args) pinfo = path.split('/').drop(1) if (pinfo.length == 0) # If this is the base_path, we're at root diff --git a/test/integration/webdav/dmsf_webdav_custom_middleware_test.rb b/test/integration/webdav/dmsf_webdav_custom_middleware_test.rb index bdd9b177..fbf2c500 100644 --- a/test/integration/webdav/dmsf_webdav_custom_middleware_test.rb +++ b/test/integration/webdav/dmsf_webdav_custom_middleware_test.rb @@ -36,4 +36,10 @@ class DmsfWebdavCustomMiddlewareTest < RedmineDmsf::Test::IntegrationTest assert_response :success end + def test_webdav_not_enabled + Setting.plugin_redmine_dmsf['dmsf_webdav'] = nil + xml_http_request :options, '/dmsf/webdav' + assert_response 404 + end + end