From f7051c7ba026b702c9933d8c8db7645a2bec5282 Mon Sep 17 00:00:00 2001 From: Karel Picman Date: Tue, 31 Jan 2017 10:49:23 +0100 Subject: [PATCH] Disable versioning for certain files/file patterns #630 --- app/views/settings/_dmsf_settings.html.erb | 49 ++++++++++++---------- config/locales/cs.yml | 5 ++- config/locales/de.yml | 5 ++- config/locales/en.yml | 3 ++ config/locales/es.yml | 5 ++- config/locales/fr.yml | 5 ++- config/locales/it.yml | 5 ++- config/locales/ja.yml | 5 ++- config/locales/pl.yml | 5 ++- config/locales/pt-BR.yml | 5 ++- config/locales/ru.yml | 5 ++- config/locales/sl.yml | 5 ++- config/locales/zh-TW.yml | 5 ++- config/locales/zh.yml | 5 ++- init.rb | 3 +- lib/redmine_dmsf/webdav/dmsf_resource.rb | 9 ++-- test/integration/dmsf_webdav_put_test.rb | 17 ++++++++ 17 files changed, 102 insertions(+), 39 deletions(-) diff --git a/app/views/settings/_dmsf_settings.html.erb b/app/views/settings/_dmsf_settings.html.erb index da62bbb2..7e5cd6cf 100644 --- a/app/views/settings/_dmsf_settings.html.erb +++ b/app/views/settings/_dmsf_settings.html.erb @@ -124,7 +124,7 @@ <%= content_tag(:label, l(:label_title_format)) %> <%= text_field_tag 'settings[dmsf_global_title_format]', @settings['dmsf_global_title_format'], :size => 10 %> - <%= l(:text_title_format) %> <%= l(:label_default) %>: %t_%v + <%= l(:text_title_format) %>

@@ -164,26 +164,33 @@

-<% if @settings['dmsf_webdav'].nil? || !@settings['dmsf_webdav'].empty? %> -

- <%= content_tag(:label, l(:label_webdav_strategy)) %> - <%= select_tag('settings[dmsf_webdav_strategy]', - options_for_select([ - [l(:select_option_webdav_readonly), 'WEBDAV_READ_ONLY'], - [l(:select_option_webdav_readwrite), 'WEBDAV_READ_WRITE']], - :selected => @settings['dmsf_webdav_strategy'])) %>
- - <%= l(:note_webdav_strategy).html_safe %> <%= l(:label_default) %>: <%= l(:select_option_webdav_readonly) %> - -

-

- <%= content_tag(:label, l(:label_memcached_servers)) %> - <%= text_field_tag 'settings[dmsf_memcached_servers]', @settings['dmsf_memcached_servers'], :size => 50 %> - - <%= l(:text_memcached_servers) %> - -

-<% end %> +

+ <%= content_tag(:label, l(:label_webdav_strategy)) %> + <%= select_tag('settings[dmsf_webdav_strategy]', + options_for_select([ + [l(:select_option_webdav_readonly), 'WEBDAV_READ_ONLY'], + [l(:select_option_webdav_readwrite), 'WEBDAV_READ_WRITE']], + :selected => @settings['dmsf_webdav_strategy'])) %>
+ + <%= l(:note_webdav_strategy).html_safe %> <%= l(:label_default) %>: <%= l(:select_option_webdav_readonly) %> + +

+ +

+ <%= content_tag(:label, l(:label_memcached_servers)) %> + <%= text_field_tag 'settings[dmsf_memcached_servers]', @settings['dmsf_memcached_servers'], :size => 50 %> + + <%= l(:text_memcached_servers) %> + +

+ +

+ <%= content_tag(:label, l(:label_webdav_ignore)) %> + <%= text_field_tag 'settings[dmsf_webdav_ignore]', @settings['dmsf_webdav_ignore'], :size => 50 %> + + <%= l(:note_webdav_ignore) %> <%= l(:label_default) %>: ^(\._|\.DS_Store$|Thumbs.db$) + +


diff --git a/config/locales/cs.yml b/config/locales/cs.yml index e369e407..5b79c5d1 100644 --- a/config/locales/cs.yml +++ b/config/locales/cs.yml @@ -341,4 +341,7 @@ cs: link_extension: Příp. label_memcached_servers: Adresa Memcached serveru - text_memcached_servers: Je podporován pouze jeden server. Pokud není vyplněno, kešování je vypnuté. Při změně adresy je potřeba restartovat aplikaci. \ No newline at end of file + text_memcached_servers: Je podporován pouze jeden server. Pokud není vyplněno, kešování je vypnuté. Při změně adresy je potřeba restartovat aplikaci. + + label_webdav_ignore: Vzory názvů ignorovaných souborů + note_webdav_ignore: Regulární výraz pro názvy souborů, které budou ignorovány při volání PUT. \ No newline at end of file diff --git a/config/locales/de.yml b/config/locales/de.yml index 62489031..cdcc9a4a 100644 --- a/config/locales/de.yml +++ b/config/locales/de.yml @@ -341,4 +341,7 @@ de: link_extension: Ext label_memcached_servers: Memcached Server Adresse - text_memcached_servers: Only a single server is supported, if empty then caching is disabled. After changing this, the application must be restarted! \ No newline at end of file + text_memcached_servers: Only a single server is supported, if empty then caching is disabled. After changing this, the application must be restarted! + + label_webdav_ignore: Ignored files patterns + note_webdav_ignore: A regular expresion with filenames to ignore by PUT requests. \ No newline at end of file diff --git a/config/locales/en.yml b/config/locales/en.yml index 1c8168db..f2f40618 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -342,3 +342,6 @@ en: label_memcached_servers: Memcached server address text_memcached_servers: Only a single server is supported, if empty then caching is disabled. After changing this, the application must be restarted! + + label_webdav_ignore: Ignored files patterns + note_webdav_ignore: A regular expresion with filenames to ignore by PUT requests. \ No newline at end of file diff --git a/config/locales/es.yml b/config/locales/es.yml index 3cd34975..f44080c8 100644 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -341,4 +341,7 @@ es: link_extension: Ext label_memcached_servers: Memcached server address - text_memcached_servers: Only a single server is supported, if empty then caching is disabled. After changing this, the application must be restarted! \ No newline at end of file + text_memcached_servers: Only a single server is supported, if empty then caching is disabled. After changing this, the application must be restarted! + + label_webdav_ignore: Ignored files patterns + note_webdav_ignore: A regular expresion with filenames to ignore by PUT requests. \ No newline at end of file diff --git a/config/locales/fr.yml b/config/locales/fr.yml index 0fd144e1..33b4e85d 100644 --- a/config/locales/fr.yml +++ b/config/locales/fr.yml @@ -341,4 +341,7 @@ fr: link_extension: Ext label_memcached_servers: Memcached server address - text_memcached_servers: Only a single server is supported, if empty then caching is disabled. After changing this, the application must be restarted! \ No newline at end of file + text_memcached_servers: Only a single server is supported, if empty then caching is disabled. After changing this, the application must be restarted! + + label_webdav_ignore: Ignored files patterns + note_webdav_ignore: A regular expresion with filenames to ignore by PUT requests. \ No newline at end of file diff --git a/config/locales/it.yml b/config/locales/it.yml index a548d98c..04116394 100644 --- a/config/locales/it.yml +++ b/config/locales/it.yml @@ -341,4 +341,7 @@ it: # Italian strings thx 2 Matteo Arceci! link_extension: Ext label_memcached_servers: Memcached server address - text_memcached_servers: Only a single server is supported, if empty then caching is disabled. After changing this, the application must be restarted! \ No newline at end of file + text_memcached_servers: Only a single server is supported, if empty then caching is disabled. After changing this, the application must be restarted! + + label_webdav_ignore: Ignored files patterns + note_webdav_ignore: A regular expresion with filenames to ignore by PUT requests. \ No newline at end of file diff --git a/config/locales/ja.yml b/config/locales/ja.yml index cc0182f6..f039fa63 100644 --- a/config/locales/ja.yml +++ b/config/locales/ja.yml @@ -341,4 +341,7 @@ ja: link_extension: Ext label_memcached_servers: Memcached server address - text_memcached_servers: Only a single server is supported, if empty then caching is disabled. After changing this, the application must be restarted! \ No newline at end of file + text_memcached_servers: Only a single server is supported, if empty then caching is disabled. After changing this, the application must be restarted! + + label_webdav_ignore: Ignored files patterns + note_webdav_ignore: A regular expresion with filenames to ignore by PUT requests. \ No newline at end of file diff --git a/config/locales/pl.yml b/config/locales/pl.yml index f337637f..af9928a7 100644 --- a/config/locales/pl.yml +++ b/config/locales/pl.yml @@ -341,4 +341,7 @@ pl: link_extension: Ext label_memcached_servers: Memcached server address - text_memcached_servers: Only a single server is supported, if empty then caching is disabled. After changing this, the application must be restarted! \ No newline at end of file + text_memcached_servers: Only a single server is supported, if empty then caching is disabled. After changing this, the application must be restarted! + + label_webdav_ignore: Ignored files patterns + note_webdav_ignore: A regular expresion with filenames to ignore by PUT requests. \ No newline at end of file diff --git a/config/locales/pt-BR.yml b/config/locales/pt-BR.yml index adfa5e76..60150fdd 100644 --- a/config/locales/pt-BR.yml +++ b/config/locales/pt-BR.yml @@ -341,4 +341,7 @@ pt-BR: link_extension: Ext label_memcached_servers: Memcached server address - text_memcached_servers: Only a single server is supported, if empty then caching is disabled. After changing this, the application must be restarted! \ No newline at end of file + text_memcached_servers: Only a single server is supported, if empty then caching is disabled. After changing this, the application must be restarted! + + label_webdav_ignore: Ignored files patterns + note_webdav_ignore: A regular expresion with filenames to ignore by PUT requests. \ No newline at end of file diff --git a/config/locales/ru.yml b/config/locales/ru.yml index 3709e819..7c40fa25 100644 --- a/config/locales/ru.yml +++ b/config/locales/ru.yml @@ -341,4 +341,7 @@ ru: link_extension: Ext label_memcached_servers: Memcached server address - text_memcached_servers: Only a single server is supported, if empty then caching is disabled. After changing this, the application must be restarted! \ No newline at end of file + text_memcached_servers: Only a single server is supported, if empty then caching is disabled. After changing this, the application must be restarted! + + label_webdav_ignore: Ignored files patterns + note_webdav_ignore: A regular expresion with filenames to ignore by PUT requests. \ No newline at end of file diff --git a/config/locales/sl.yml b/config/locales/sl.yml index 0df747ce..06420dcb 100644 --- a/config/locales/sl.yml +++ b/config/locales/sl.yml @@ -341,4 +341,7 @@ sl: link_extension: Ext label_memcached_servers: Memcached server address - text_memcached_servers: Only a single server is supported, if empty then caching is disabled. After changing this, the application must be restarted! \ No newline at end of file + text_memcached_servers: Only a single server is supported, if empty then caching is disabled. After changing this, the application must be restarted! + + label_webdav_ignore: Ignored files patterns + note_webdav_ignore: A regular expresion with filenames to ignore by PUT requests. \ No newline at end of file diff --git a/config/locales/zh-TW.yml b/config/locales/zh-TW.yml index dea99b33..7439e6c6 100644 --- a/config/locales/zh-TW.yml +++ b/config/locales/zh-TW.yml @@ -341,4 +341,7 @@ zh-TW: link_extension: Ext label_memcached_servers: Memcached server address - text_memcached_servers: Only a single server is supported, if empty then caching is disabled. After changing this, the application must be restarted! \ No newline at end of file + text_memcached_servers: Only a single server is supported, if empty then caching is disabled. After changing this, the application must be restarted! + + label_webdav_ignore: Ignored files patterns + note_webdav_ignore: A regular expresion with filenames to ignore by PUT requests. \ No newline at end of file diff --git a/config/locales/zh.yml b/config/locales/zh.yml index 597dbf8d..c438c482 100644 --- a/config/locales/zh.yml +++ b/config/locales/zh.yml @@ -341,4 +341,7 @@ zh: link_extension: Ext label_memcached_servers: Memcached server address - text_memcached_servers: Only a single server is supported, if empty then caching is disabled. After changing this, the application must be restarted! \ No newline at end of file + text_memcached_servers: Only a single server is supported, if empty then caching is disabled. After changing this, the application must be restarted! + + label_webdav_ignore: Ignored files patterns + note_webdav_ignore: A regular expresion with filenames to ignore by PUT requests. \ No newline at end of file diff --git a/init.rb b/init.rb index 0f1cc202..f134ea8e 100644 --- a/init.rb +++ b/init.rb @@ -48,7 +48,8 @@ Redmine::Plugin.register :redmine_dmsf do 'dmsf_display_notified_recipients' => 0, 'dmsf_global_title_format' => '', 'dmsf_columns' => %w(title size modified version workflow author), - 'dmsf_memcached_servers' => '' + 'dmsf_memcached_servers' => '', + 'dmsf_webdav_ignore' => '^(\._|\.DS_Store$|Thumbs.db$)' } menu :project_menu, :dmsf, { :controller => 'dmsf', :action => 'show' }, :caption => :menu_dmsf, :before => :documents, :param => :id diff --git a/lib/redmine_dmsf/webdav/dmsf_resource.rb b/lib/redmine_dmsf/webdav/dmsf_resource.rb index 46d4163d..f04fabff 100644 --- a/lib/redmine_dmsf/webdav/dmsf_resource.rb +++ b/lib/redmine_dmsf/webdav/dmsf_resource.rb @@ -533,13 +533,12 @@ module RedmineDmsf # HTTP PUT request. def put(request, response) - Rails.logger.info ">>> 1" raise BadRequest if collection? - Rails.logger.info ">>> 2" raise Forbidden unless User.current.admin? || User.current.allowed_to?(:file_manipulation, project) - Rails.logger.info ">>> 3" - # Ignore Mac OS X resource forks and special Windows files. - if basename.match(/^\._/) || basename.match(/^\.DS_Store$/i) || basename.match(/^Thumbs.db$/i) + # Ignore file name patterns given in the plugin settings + pattern = Setting.plugin_redmine_dmsf['dmsf_webdav_ignore'] + pattern = /^(\._|\.DS_Store$|Thumbs.db$)/ if pattern.blank? + if basename.match(pattern) Rails.logger.info "#{basename} ignored" return NoContent end diff --git a/test/integration/dmsf_webdav_put_test.rb b/test/integration/dmsf_webdav_put_test.rb index 11b6bfd2..d826e897 100644 --- a/test/integration/dmsf_webdav_put_test.rb +++ b/test/integration/dmsf_webdav_put_test.rb @@ -207,4 +207,21 @@ class DmsfWebdavPutTest < RedmineDmsf::Test::IntegrationTest end end + def test_put_ignored_files_default + if Setting.plugin_redmine_dmsf['dmsf_webdav_strategy'] == 'WEBDAV_READ_WRITE' + @project1.enable_module! :dmsf + @role.add_permission! :view_dmsf_folders + @role.add_permission! :file_manipulation + put "/dmsf/webdav/#{@project1.identifier}/._test.txt", '1234', @admin.merge!({:content_type => :text}) + assert_response 204 # NoContent + put "/dmsf/webdav/#{@project1.identifier}/.DS_Store", '1234', @admin.merge!({:content_type => :text}) + assert_response 204 # NoContent + put "/dmsf/webdav/#{@project1.identifier}/Thumbs.sb", '1234', @admin.merge!({:content_type => :text}) + assert_response 204 # NoContent + Setting.plugin_redmine_dmsf['dmsf_webdav_ignore'] = '.dump$' + put "/dmsf/webdav/#{@project1.identifier}/test.dump", '1234', @admin.merge!({:content_type => :text}) + assert_response 204 # NoContent + end + end + end \ No newline at end of file