From 0f288ba881868ff1dd70d6619a211884c619736d Mon Sep 17 00:00:00 2001
From: "COLA@Redmine.local"
Date: Thu, 2 Feb 2017 19:53:11 +0100
Subject: [PATCH 1/3] Disable file versioning for files that match the filter.
---
app/views/settings/_dmsf_settings.html.erb | 8 ++++++++
config/locales/en.yml | 5 ++++-
init.rb | 3 ++-
lib/redmine_dmsf/webdav/dmsf_resource.rb | 16 +++++++++++++---
4 files changed, 27 insertions(+), 5 deletions(-)
diff --git a/app/views/settings/_dmsf_settings.html.erb b/app/views/settings/_dmsf_settings.html.erb
index 54aad1ca..c1cffd99 100644
--- a/app/views/settings/_dmsf_settings.html.erb
+++ b/app/views/settings/_dmsf_settings.html.erb
@@ -179,6 +179,14 @@
<%= l(:note_webdav_ignore) %> <%= l(:label_default) %>: ^(\._|\.DS_Store$|Thumbs.db$)
+
+ <%= content_tag(:label, l(:label_webdav_disable_versioning)) %>
+ <%= text_field_tag 'settings[dmsf_webdav_disable_versioning]', @settings['dmsf_webdav_disable_versioning'], :size => 50 %>
+
+ <%= l(:note_webdav_disable_versioning) %>
+ <%= l(:label_default) %>: ^\~\$|\.tmp$
+
+
diff --git a/config/locales/en.yml b/config/locales/en.yml
index 8ea935f2..1afbf2fa 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -347,4 +347,7 @@ en:
note_webdav_ignore: A regular expresion with filenames to ignore by PUT requests.
label_document_url: Url
- label_last_revision_id: Revision
\ No newline at end of file
+ label_last_revision_id: Revision
+
+ label_webdav_disable_versioning: No versioning files patterns
+ note_webdav_disable_versioning: A regular expression that disables versioning for matching files.
diff --git a/init.rb b/init.rb
index f134ea8e..3daf39ce 100644
--- a/init.rb
+++ b/init.rb
@@ -49,7 +49,8 @@ Redmine::Plugin.register :redmine_dmsf do
'dmsf_global_title_format' => '',
'dmsf_columns' => %w(title size modified version workflow author),
'dmsf_memcached_servers' => '',
- 'dmsf_webdav_ignore' => '^(\._|\.DS_Store$|Thumbs.db$)'
+ 'dmsf_webdav_ignore' => '^(\._|\.DS_Store$|Thumbs.db$)',
+ 'dmsf_webdav_disable_versioning' => '^\~\$|\.tmp$'
}
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 1256af8c..beaa2162 100644
--- a/lib/redmine_dmsf/webdav/dmsf_resource.rb
+++ b/lib/redmine_dmsf/webdav/dmsf_resource.rb
@@ -534,6 +534,7 @@ module RedmineDmsf
def put(request, response)
raise BadRequest if collection?
raise Forbidden unless User.current.admin? || User.current.allowed_to?(:file_manipulation, project)
+
# 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?
@@ -542,17 +543,24 @@ module RedmineDmsf
return NoContent
end
- new_revision = DmsfFileRevision.new
- reuse_revision = false
+ # Disable versioning for file name patterns given in the plugin settings.
+ pattern = Setting.plugin_redmine_dmsf['dmsf_webdav_disable_versioning']
+ if !pattern.blank? && basename.match(pattern)
+ Rails.logger.info "Versioning disabled for #{basename}"
+ reuse_revision = true
+ else
+ reuse_revision = false
+ end
if exist? # We're over-writing something, so ultimately a new revision
f = file
last_revision = file.last_revision
- if last_revision.size == 0
+ if last_revision.size == 0 || reuse_revision
new_revision = last_revision
new_revision.minor_version -= 1
reuse_revision = true
else
+ new_revision = DmsfFileRevision.new
new_revision.source_revision = last_revision
if last_revision
new_revision.major_version = last_revision.major_version
@@ -568,8 +576,10 @@ module RedmineDmsf
f.name = basename
f.dmsf_folder = parent.folder
f.notification = !Setting.plugin_redmine_dmsf['dmsf_default_notifications'].blank?
+ new_revision = DmsfFileRevision.new
new_revision.minor_version = 0
new_revision.major_version = 0
+ reuse_revision = false
end
new_revision.dmsf_file = f
From ec674de677fb6c49dfa5483c7ffec9c48c7a5ccd Mon Sep 17 00:00:00 2001
From: "COLA@Redmine.local"
Date: Thu, 2 Feb 2017 21:45:48 +0100
Subject: [PATCH 2/3] Implemented tests for non versioned files.
---
test/integration/dmsf_webdav_put_test.rb | 43 ++++++++++++++++++++++++
1 file changed, 43 insertions(+)
diff --git a/test/integration/dmsf_webdav_put_test.rb b/test/integration/dmsf_webdav_put_test.rb
index d826e897..23555eaf 100644
--- a/test/integration/dmsf_webdav_put_test.rb
+++ b/test/integration/dmsf_webdav_put_test.rb
@@ -224,4 +224,47 @@ class DmsfWebdavPutTest < RedmineDmsf::Test::IntegrationTest
end
end
+ def test_put_non_versioned_files
+ @project1.enable_module! :dmsf
+ @role.add_permission! :view_dmsf_folders
+ @role.add_permission! :file_manipulation
+
+ put "/dmsf/webdav/#{@project1.identifier}/file1.tmp", '1234', @admin.merge!({:content_type => :text})
+ assert_response :success
+ file1 = DmsfFile.find_file_by_name @project1, nil, 'file1.tmp'
+ assert_difference 'file1.dmsf_file_revisions.count', 0 do
+ put "/dmsf/webdav/#{@project1.identifier}/file1.tmp", '5678', @admin.merge!({:content_type => :text})
+ assert_response :success # 201 - Created
+ end
+ assert_difference 'file1.dmsf_file_revisions.count', 0 do
+ put "/dmsf/webdav/#{@project1.identifier}/file1.tmp", '9ABC', @admin.merge!({:content_type => :text})
+ assert_response :success # 201 - Created
+ end
+
+ put "/dmsf/webdav/#{@project1.identifier}/~$file2.txt", '1234', @admin.merge!({:content_type => :text})
+ assert_response :success
+ file2 = DmsfFile.find_file_by_name @project1, nil, '~$file2.txt'
+ assert_difference 'file1.dmsf_file_revisions.count', 0 do
+ put "/dmsf/webdav/#{@project1.identifier}/~$file2.txt", '5678', @admin.merge!({:content_type => :text})
+ assert_response :success # 201 - Created
+ end
+ assert_difference 'file1.dmsf_file_revisions.count', 0 do
+ put "/dmsf/webdav/#{@project1.identifier}/~$file2.txt", '9ABC', @admin.merge!({:content_type => :text})
+ assert_response :success # 201 - Created
+ end
+
+ Setting.plugin_redmine_dmsf['dmsf_webdav_disable_versioning'] = '.dump$'
+ put "/dmsf/webdav/#{@project1.identifier}/file3.dump", '1234', @admin.merge!({:content_type => :text})
+ assert_response :success
+ file2 = DmsfFile.find_file_by_name @project1, nil, 'file3.dump'
+ assert_difference 'file1.dmsf_file_revisions.count', 0 do
+ put "/dmsf/webdav/#{@project1.identifier}/file3.dump", '5678', @admin.merge!({:content_type => :text})
+ assert_response :success # 201 - Created
+ end
+ assert_difference 'file1.dmsf_file_revisions.count', 0 do
+ put "/dmsf/webdav/#{@project1.identifier}/file3.dump", '9ABC', @admin.merge!({:content_type => :text})
+ assert_response :success # 201 - Created
+ end
+end
+
end
\ No newline at end of file
From 8d6292d24015c68fc96d6a44180b99b4a27770d8 Mon Sep 17 00:00:00 2001
From: "COLA@Redmine.local"
Date: Thu, 2 Feb 2017 21:58:09 +0100
Subject: [PATCH 3/3] Added new strings.
---
config/locales/cs.yml | 5 ++++-
config/locales/de.yml | 5 ++++-
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 ++++-
12 files changed, 48 insertions(+), 12 deletions(-)
diff --git a/config/locales/cs.yml b/config/locales/cs.yml
index 0f8f61d9..93a81572 100644
--- a/config/locales/cs.yml
+++ b/config/locales/cs.yml
@@ -347,4 +347,7 @@ cs:
note_webdav_ignore: Regulární výraz pro názvy souborů, které budou ignorovány při volání PUT.
label_document_url: Url
- label_last_revision_id: Revize
\ No newline at end of file
+ label_last_revision_id: Revize
+
+ label_webdav_disable_versioning: No versioning files patterns
+ note_webdav_disable_versioning: A regular expression that disables versioning for matching files.
diff --git a/config/locales/de.yml b/config/locales/de.yml
index cdcc9a4a..8440a45c 100644
--- a/config/locales/de.yml
+++ b/config/locales/de.yml
@@ -344,4 +344,7 @@ de:
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
+ note_webdav_ignore: A regular expresion with filenames to ignore by PUT requests.
+
+ label_webdav_disable_versioning: No versioning files patterns
+ note_webdav_disable_versioning: A regular expression that disables versioning for matching files.
diff --git a/config/locales/es.yml b/config/locales/es.yml
index 3917b9d4..546ed027 100644
--- a/config/locales/es.yml
+++ b/config/locales/es.yml
@@ -347,4 +347,7 @@ es:
note_webdav_ignore: A regular expresion with filenames to ignore by PUT requests.
label_document_url: Url
- label_last_revision_id: Revision
\ No newline at end of file
+ label_last_revision_id: Revision
+
+ label_webdav_disable_versioning: No versioning files patterns
+ note_webdav_disable_versioning: A regular expression that disables versioning for matching files.
diff --git a/config/locales/fr.yml b/config/locales/fr.yml
index dbd5d77a..0d343bf2 100644
--- a/config/locales/fr.yml
+++ b/config/locales/fr.yml
@@ -347,4 +347,7 @@ fr:
note_webdav_ignore: A regular expresion with filenames to ignore by PUT requests.
label_document_url: Url
- label_last_revision_id: Revision
\ No newline at end of file
+ label_last_revision_id: Revision
+
+ label_webdav_disable_versioning: No versioning files patterns
+ note_webdav_disable_versioning: A regular expression that disables versioning for matching files.
diff --git a/config/locales/it.yml b/config/locales/it.yml
index 272064df..4b88be75 100644
--- a/config/locales/it.yml
+++ b/config/locales/it.yml
@@ -347,4 +347,7 @@ it: # Italian strings thx 2 Matteo Arceci!
note_webdav_ignore: A regular expresion with filenames to ignore by PUT requests.
label_document_url: Url
- label_last_revision_id: Revision
\ No newline at end of file
+ label_last_revision_id: Revision
+
+ label_webdav_disable_versioning: No versioning files patterns
+ note_webdav_disable_versioning: A regular expression that disables versioning for matching files.
diff --git a/config/locales/ja.yml b/config/locales/ja.yml
index 94ba9b08..94ebe271 100644
--- a/config/locales/ja.yml
+++ b/config/locales/ja.yml
@@ -347,4 +347,7 @@ ja:
note_webdav_ignore: A regular expresion with filenames to ignore by PUT requests.
label_document_url: Url
- label_last_revision_id: Revision
\ No newline at end of file
+ label_last_revision_id: Revision
+
+ label_webdav_disable_versioning: No versioning files patterns
+ note_webdav_disable_versioning: A regular expression that disables versioning for matching files.
diff --git a/config/locales/pl.yml b/config/locales/pl.yml
index 57adc424..a11033fb 100644
--- a/config/locales/pl.yml
+++ b/config/locales/pl.yml
@@ -347,4 +347,7 @@ pl:
note_webdav_ignore: A regular expresion with filenames to ignore by PUT requests.
label_document_url: Url
- label_last_revision_id: Revision
\ No newline at end of file
+ label_last_revision_id: Revision
+
+ label_webdav_disable_versioning: No versioning files patterns
+ note_webdav_disable_versioning: A regular expression that disables versioning for matching files.
diff --git a/config/locales/pt-BR.yml b/config/locales/pt-BR.yml
index 93ce9dc5..2164be35 100644
--- a/config/locales/pt-BR.yml
+++ b/config/locales/pt-BR.yml
@@ -347,4 +347,7 @@ pt-BR:
note_webdav_ignore: A regular expresion with filenames to ignore by PUT requests.
label_document_url: Url
- label_last_revision_id: Revision
\ No newline at end of file
+ label_last_revision_id: Revision
+
+ label_webdav_disable_versioning: No versioning files patterns
+ note_webdav_disable_versioning: A regular expression that disables versioning for matching files.
diff --git a/config/locales/ru.yml b/config/locales/ru.yml
index f0464246..7040c134 100644
--- a/config/locales/ru.yml
+++ b/config/locales/ru.yml
@@ -347,4 +347,7 @@ ru:
note_webdav_ignore: A regular expresion with filenames to ignore by PUT requests.
label_document_url: Url
- label_last_revision_id: Revision
\ No newline at end of file
+ label_last_revision_id: Revision
+
+ label_webdav_disable_versioning: No versioning files patterns
+ note_webdav_disable_versioning: A regular expression that disables versioning for matching files.
diff --git a/config/locales/sl.yml b/config/locales/sl.yml
index ae38f33e..75b72cb8 100644
--- a/config/locales/sl.yml
+++ b/config/locales/sl.yml
@@ -347,4 +347,7 @@ sl:
note_webdav_ignore: A regular expresion with filenames to ignore by PUT requests.
label_document_url: Url
- label_last_revision_id: Revision
\ No newline at end of file
+ label_last_revision_id: Revision
+
+ label_webdav_disable_versioning: No versioning files patterns
+ note_webdav_disable_versioning: A regular expression that disables versioning for matching files.
diff --git a/config/locales/zh-TW.yml b/config/locales/zh-TW.yml
index 67b5a3e2..199ccb95 100644
--- a/config/locales/zh-TW.yml
+++ b/config/locales/zh-TW.yml
@@ -347,4 +347,7 @@ zh-TW:
note_webdav_ignore: A regular expresion with filenames to ignore by PUT requests.
label_document_url: Url
- label_last_revision_id: Revision
\ No newline at end of file
+ label_last_revision_id: Revision
+
+ label_webdav_disable_versioning: No versioning files patterns
+ note_webdav_disable_versioning: A regular expression that disables versioning for matching files.
diff --git a/config/locales/zh.yml b/config/locales/zh.yml
index 883664aa..ab4a6397 100644
--- a/config/locales/zh.yml
+++ b/config/locales/zh.yml
@@ -347,4 +347,7 @@ zh:
note_webdav_ignore: A regular expresion with filenames to ignore by PUT requests.
label_document_url: Url
- label_last_revision_id: Revision
\ No newline at end of file
+ label_last_revision_id: Revision
+
+ label_webdav_disable_versioning: No versioning files patterns
+ note_webdav_disable_versioning: A regular expression that disables versioning for matching files.