diff --git a/app/controllers/dmsf_controller.rb b/app/controllers/dmsf_controller.rb index 0f015174..9521ea86 100644 --- a/app/controllers/dmsf_controller.rb +++ b/app/controllers/dmsf_controller.rb @@ -50,7 +50,7 @@ class DmsfController < ApplicationController # also try to lookup folder by title if this is API call find_folder_by_title if [:xml, :json].include? request.format.to_sym get_display_params - if @folder && @folder.deleted? + if (@folder && @folder.deleted?) || (params[:folder_title].present? && !@folder) render_404 return end diff --git a/app/controllers/dmsf_upload_controller.rb b/app/controllers/dmsf_upload_controller.rb index cc74e002..f3c9199e 100644 --- a/app/controllers/dmsf_upload_controller.rb +++ b/app/controllers/dmsf_upload_controller.rb @@ -118,6 +118,7 @@ class DmsfUploadController < ApplicationController # REST API file commit def commit + @files = [] attachments = params[:attachments] if attachments && attachments.is_a?(Hash) @folder = DmsfFolder.visible.find_by_id attachments[:folder_id].to_i if attachments[:folder_id].present? @@ -127,8 +128,8 @@ class DmsfUploadController < ApplicationController upload = DmsfUpload.create_from_uploaded_attachment(@project, @folder, uploaded_file) uploaded_file[:disk_filename] = upload.disk_filename end + commit_files_internal uploaded_files end - commit_files_internal uploaded_files end def delete_dmsf_attachment @@ -141,7 +142,7 @@ class DmsfUploadController < ApplicationController private def commit_files_internal(commited_files) - DmsfUploadHelper.commit_files_internal(commited_files, @project, @folder, self) + @files, failed_uploads = DmsfUploadHelper.commit_files_internal(commited_files, @project, @folder, self) respond_to do |format| format.js format.api { render_validation_errors(failed_uploads) unless failed_uploads.empty? } diff --git a/app/helpers/dmsf_upload_helper.rb b/app/helpers/dmsf_upload_helper.rb index a8caaf3d..e13ce77d 100644 --- a/app/helpers/dmsf_upload_helper.rb +++ b/app/helpers/dmsf_upload_helper.rb @@ -22,13 +22,14 @@ module DmsfUploadHelper include Redmine::I18n def self.commit_files_internal(commited_files, container, folder, controller) + failed_uploads = [] + files = [] if container.is_a?(Project) project = container else project = container.project end if commited_files && commited_files.is_a?(Hash) - files = [] failed_uploads = [] commited_files.each_value do |commited_file| name = commited_file[:name] @@ -136,9 +137,10 @@ module DmsfUploadHelper end end end - unless failed_uploads.empty? + if failed_uploads.present? controller.flash[:warning] = l(:warning_some_files_were_not_commited, :files => failed_uploads.map{|u| u['name']}.join(', ')) end + [files, failed_uploads] end end diff --git a/app/views/dmsf_files/show.api.rsb b/app/views/dmsf_files/show.api.rsb index f998adce..dc192c53 100644 --- a/app/views/dmsf_files/show.api.rsb +++ b/app/views/dmsf_files/show.api.rsb @@ -1,7 +1,8 @@ api.dmsf_file do api.id @file.id api.name @file.name - api.project_id @file.project_id + api.container_id @file.container_id + api.container_type @file.container_type api.dmsf_folder_id @file.folder if @file.dmsf_folder_id api.version "#{@file.last_revision.major_version}.#{@file.last_revision.minor_version}" if @file.last_revision api.content_url url_for(:controller => :dmsf_files, :action => 'show', :download => '', :id => @file) diff --git a/extra/api/api_client.sh b/extra/api/api_client.sh index 772414c2..7c90206d 100644 --- a/extra/api/api_client.sh +++ b/extra/api/api_client.sh @@ -44,6 +44,7 @@ curl -v -H "Content-Type: application/xml" -X GET -u ${1}:${2} http://localhost: # 5. list folder contents & check folder existence (by folder title) # curl -v -H "Content-Type: application/json" -X GET -H "X-Redmine-API-Key: USERS_API_KEY" http://localhost:3000/projects/1/dmsf.json?folder_title=Updated%20title + # 6. list folder contents & check folder existence (by folder id) # curl -v -H "Content-Type: application/json" -X GET -H "X-Redmine-API-Key: USERS_API_KE" http://localhost:3000/projects/1/dmsf.json?folder_id=3 # both returns 404 not found, or json with following structure: @@ -67,8 +68,7 @@ curl -v -H "Content-Type: application/xml" -X GET -u ${1}:${2} http://localhost: #} # 7. update folder -# curl -v -H "Content-Type: application/json" -X POST --data "@update-folder-payload.json" -H "X-Redmine-API-Key: USERS_API_KEY" http://localhost:3000//projects/#{project_id}/dmsf/save.json - +# curl -v -H "Content-Type: application/json" -X POST --data "@update-folder-payload.json" -H "X-Redmine-API-Key: USERS_API_KEY" http://localhost:3000//projects/#{project_id}/dmsf/save.json?folder_id=#{folder_id} # update-folder-payload.json # { @@ -76,5 +76,4 @@ curl -v -H "Content-Type: application/xml" -X GET -u ${1}:${2} http://localhost: # "title": title, # "description": description # }, -# "folder_id": id -- id of folder to be updated # } \ No newline at end of file diff --git a/test/integration/rest_api/dmsf_file_api_test.rb b/test/integration/rest_api/dmsf_file_api_test.rb new file mode 100644 index 00000000..96cd8596 --- /dev/null +++ b/test/integration/rest_api/dmsf_file_api_test.rb @@ -0,0 +1,125 @@ +# encoding: utf-8 +# +# Redmine plugin for Document Management System "Features" +# +# Copyright (C) 2011-17 Karel Pičman +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +require File.expand_path('../../../test_helper', __FILE__) + +class DmsfFileApiTest < RedmineDmsf::Test::IntegrationTest + + fixtures :projects, :users, :dmsf_files, :dmsf_file_revisions, :members, :roles + + def setup + DmsfFile.storage_path = File.expand_path '../../../fixtures/files', __FILE__ + timestamp = DateTime.now.strftime("%y%m%d%H%M") + @tmp_storage_path = File.expand_path("./dmsf_test-#{timestamp}", DmsfHelper.temp_dir) + Dir.mkdir(@tmp_storage_path) unless File.directory?(@tmp_storage_path) + @jsmith = User.find_by_id 2 + @file1 = DmsfFile.find_by_id 1 + Setting.rest_api_enabled = '1' + @role = Role.find_by_id 1 + @project1 = Project.find_by_id 1 + end + + def teardown + # Delete our tmp folder + begin + FileUtils.rm_rf @tmp_storage_path + rescue Exception => e + error e.message + end + end + + def test_truth + assert_kind_of User, @jsmith + assert_kind_of DmsfFile, @file1 + assert_kind_of Role, @role + assert_kind_of Project, @project1 + end + + def test_get_document + @role.add_permission! :view_dmsf_files + token = Token.create!(:user => @jsmith, :action => 'api') + #curl -v -H "Content-Type: application/xml" -X GET -u ${1}:${2} http://localhost:3000/dmsf/files/17216.xml + get "/dmsf/files/#{@file1.id}.xml?key=#{token.value}" + assert_response :success + assert_equal 'application/xml', @response.content_type + # + # + # 1 + # test.txt + # 1 + # Project + # 1.0 + # /dmsf/files/1/download + # + assert_select 'dmsf_file > id', :text => @file1.id.to_s + assert_select 'dmsf_file > name', :text => @file1.name + assert_select 'dmsf_file > container_id', :text => @file1.container_id.to_s + assert_select 'dmsf_file > container_type', :text => @file1.container_type.to_s + assert_select 'dmsf_file > version', :text => "#{@file1.last_revision.major_version}.#{@file1.last_revision.minor_version}" + assert_select 'dmsf_file > content_url', :text => "/dmsf/files/#{@file1.id}/download" + #curl -v -H "Content-Type: application/octet-stream" -X GET -u ${1}:${2} http://localhost:3000/dmsf/files/41532/download > file.txt + get "/dmsf/files/#{@file1.id}/download?key=#{token.value}" + assert_response :success + end + + def test_upload_document + DmsfFile.storage_path = @tmp_storage_path + @role.add_permission! :file_manipulation + token = Token.create!(:user => @jsmith, :action => 'api') + #curl --data-binary "@cat.gif" -H "Content-Type: application/octet-stream" -X POST -u ${1}:${2} http://localhost:3000/projects/12/dmsf/upload.xml?filename=cat.gif + post "/projects/#{@project1.id}/dmsf/upload.xml?filename=test.txt&key=#{token.value}", 'File content', {"CONTENT_TYPE" => 'application/octet-stream'} + assert_response :created + assert_equal 'application/xml', response.content_type + # + # + # 2.8bb2564936980e92ceec8a5759ec34a8 + # + xml = Hash.from_xml(response.body) + assert_kind_of Hash, xml['upload'] + ftoken = xml['upload']['token'] + assert_not_nil ftoken + #curl -v -H "Content-Type: application/xml" -X POST --data "@file.xml" -u ${1}:${2} http://localhost:3000/projects/12/dmsf/commit.xml + payload = %{ + + + + + test.txt + test.txt + test.txt + REST API + From API + + #{ftoken} + + + } + post "/projects/#{@project1.id}/dmsf/commit.xml?&key=#{token.value}", payload, {"CONTENT_TYPE" => 'application/xml'} + # + # + # + # 17229 + # test.txt + # + # + assert_select 'dmsf_files > file > name', :text => 'test.txt' + assert_response :success + end +end \ No newline at end of file diff --git a/test/integration/rest_api/dmsf_folder_api_test.rb b/test/integration/rest_api/dmsf_folder_api_test.rb new file mode 100644 index 00000000..67b3cda4 --- /dev/null +++ b/test/integration/rest_api/dmsf_folder_api_test.rb @@ -0,0 +1,194 @@ +# encoding: utf-8 +# +# Redmine plugin for Document Management System "Features" +# +# Copyright (C) 2011-17 Karel Pičman +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +require File.expand_path('../../../test_helper', __FILE__) + +class DmsfFolderApiTest < RedmineDmsf::Test::IntegrationTest + + fixtures :dmsf_folders, :dmsf_files, :dmsf_file_revisions, :projects, :users, :members, :roles + + def setup + DmsfFile.storage_path = File.expand_path '../../../../fixtures/files', __FILE__ + @jsmith = User.find_by_id 2 + @file1 = DmsfFile.find_by_id 1 + @folder1 = DmsfFolder.find_by_id 1 + Setting.rest_api_enabled = '1' + @role = Role.find_by_id 1 + end + + def test_truth + assert_kind_of User, @jsmith + assert_kind_of DmsfFolder, @folder1 + assert_kind_of DmsfFile, @file1 + assert_kind_of Role, @role + end + + def test_list_folder + @role.add_permission! :view_dmsf_folders + token = Token.create!(:user => @jsmith, :action => 'api') + #curl -v -H "Content-Type: application/xml" -X GET -u ${1}:${2} http://localhost:3000/dmsf/files/17216.xml + get "/projects/1/dmsf.xml?key=#{token.value}" + assert_response :success + assert_equal 'application/xml', @response.content_type + # + # + # + # + # 1 + # folder1 + # + # + # 6 + # folder6 + # + # + # + # + # 1 + # test.txt + # + # + # + # + # + assert_select 'dmsf > dmsf_folders > folder > id', :text => @folder1.id.to_s + assert_select 'dmsf > dmsf_folders > folder > title', :text => @folder1.title.to_s + assert_select 'dmsf > dmsf_files > file > id', :text => @file1.id.to_s + assert_select 'dmsf > dmsf_files > file > name', :text => @file1.name.to_s + + end + + def test_create_folder + @role.add_permission! :folder_manipulation + token = Token.create!(:user => @jsmith, :action => 'api') + #curl -v -H "Content-Type: application/xml" -X POST --data "@folder.xml" -u ${1}:${2} http://localhost:3000/projects/12/dmsf/create.xml + payload = %{ + + + rest_api + A folder created via REST API + + + } + post "/projects/1/dmsf/create.xml?&key=#{token.value}", payload, {"CONTENT_TYPE" => 'application/xml'} + assert_response :success + # + # + # 8 + # rest_api + # + assert_select 'dmsf_folder > title', :text => 'rest_api' + end + + def test_find_folder_by_title + @role.add_permission! :view_dmsf_folders + token = Token.create!(:user => @jsmith, :action => 'api') + # curl -v -H "Content-Type: application/json" -X GET -H "X-Redmine-API-Key: USERS_API_KEY" http://localhost:3000/projects/1/dmsf.json?folder_title=Updated%20title + get "/projects/1/dmsf.xml?key=#{token.value}&folder_title=#{@folder1.title}" + assert_response :success + assert_equal 'application/xml', @response.content_type + # + # + # + # + # 2 + # folder2 + # + # + # + # + # + # + # + # 1 + # folder1 + # + # + assert_select 'dmsf > found_folder > id', :text => @folder1.id.to_s + assert_select 'dmsf > found_folder > title', :text => @folder1.title + end + + def test_find_folder_by_title_not_found + @role.add_permission! :view_dmsf_folders + token = Token.create!(:user => @jsmith, :action => 'api') + # curl -v -H "Content-Type: application/json" -X GET -H "X-Redmine-API-Key: USERS_API_KEY" http://localhost:3000/projects/1/dmsf.json?folder_title=Updated%20title + get "/projects/1/dmsf.xml?key=#{token.value}&folder_title=xxx" + assert_response :missing + end + + def test_find_folder_by_id + @role.add_permission! :view_dmsf_folders + token = Token.create!(:user => @jsmith, :action => 'api') + # curl -v -H "Content-Type: application/json" -X GET -H "X-Redmine-API-Key: USERS_API_KE" http://localhost:3000/projects/1/dmsf.json?folder_id=3 + get "/projects/1/dmsf.xml?key=#{token.value}&folder_id=#{@folder1.id}" + assert_response :success + assert_equal 'application/xml', @response.content_type + # + # + # + # + # 2 + # folder2 + # + # + # + # + # + # + # + # 1 + # folder1 + # + # + assert_select 'dmsf > found_folder > id', :text => @folder1.id.to_s + assert_select 'dmsf > found_folder > title', :text => @folder1.title + end + + def test_find_folder_by_id_not_found + @role.add_permission! :view_dmsf_folders + token = Token.create!(:user => @jsmith, :action => 'api') + # curl -v -H "Content-Type: application/json" -X GET -H "X-Redmine-API-Key: USERS_API_KE" http://localhost:3000/projects/1/dmsf.json?folder_id=3 + get "/projects/1/dmsf.xml?key=#{token.value}&folder_id=99999999999" + assert_response :missing + end + + def test_update_folder + @role.add_permission! :folder_manipulation + token = Token.create!(:user => @jsmith, :action => 'api') + #curl -v -H "Content-Type: application/json" -X POST --data "@update-folder-payload.json" -H "X-Redmine-API-Key: USERS_API_KEY" http://localhost:3000//projects/#{project_id}/dmsf/save.json + payload = %{ + + + rest_api + A folder updated via REST API + + } + post "/projects/1/dmsf/save.xml?folder_id=1&key=#{token.value}", payload, {"CONTENT_TYPE" => 'application/xml'} + assert_response :success + # + # + # 1 + # rest_api + # A folder updated via REST API + # + assert_select 'dmsf_folder > title', :text => 'rest_api' + end + +end \ No newline at end of file diff --git a/test/integration/dmsf_webdav_delete_test.rb b/test/integration/webdav/dmsf_webdav_delete_test.rb similarity index 97% rename from test/integration/dmsf_webdav_delete_test.rb rename to test/integration/webdav/dmsf_webdav_delete_test.rb index 159ef4cf..733b39dd 100644 --- a/test/integration/dmsf_webdav_delete_test.rb +++ b/test/integration/webdav/dmsf_webdav_delete_test.rb @@ -19,7 +19,7 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -require File.expand_path('../../test_helper', __FILE__) +require File.expand_path('../../../test_helper', __FILE__) class DmsfWebdavDeleteTest < RedmineDmsf::Test::IntegrationTest include Redmine::I18n @@ -29,7 +29,6 @@ class DmsfWebdavDeleteTest < RedmineDmsf::Test::IntegrationTest :dmsf_locks def setup - DmsfFile.storage_path = File.expand_path '../../fixtures/files', __FILE__ DmsfLock.delete_all @admin = credentials 'admin' @jsmith = credentials 'jsmith' @@ -41,7 +40,7 @@ class DmsfWebdavDeleteTest < RedmineDmsf::Test::IntegrationTest @file1 = DmsfFile.find_by_id 1 Setting.plugin_redmine_dmsf['dmsf_webdav'] = '1' Setting.plugin_redmine_dmsf['dmsf_webdav_strategy'] = 'WEBDAV_READ_WRITE' - DmsfFile.storage_path = File.expand_path '../../fixtures/files', __FILE__ + DmsfFile.storage_path = File.expand_path '../../../fixtures/files', __FILE__ User.current = nil end diff --git a/test/integration/dmsf_webdav_get_test.rb b/test/integration/webdav/dmsf_webdav_get_test.rb similarity index 97% rename from test/integration/dmsf_webdav_get_test.rb rename to test/integration/webdav/dmsf_webdav_get_test.rb index fde1257d..87b0f250 100644 --- a/test/integration/dmsf_webdav_get_test.rb +++ b/test/integration/webdav/dmsf_webdav_get_test.rb @@ -19,7 +19,7 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -require File.expand_path('../../test_helper', __FILE__) +require File.expand_path('../../../test_helper', __FILE__) class DmsfWebdavGetTest < RedmineDmsf::Test::IntegrationTest @@ -34,7 +34,7 @@ class DmsfWebdavGetTest < RedmineDmsf::Test::IntegrationTest @role = Role.find_by_id 1 # Manager Setting.plugin_redmine_dmsf['dmsf_webdav'] = '1' Setting.plugin_redmine_dmsf['dmsf_webdav_strategy'] = 'WEBDAV_READ_WRITE' - DmsfFile.storage_path = File.expand_path '../../fixtures/files', __FILE__ + DmsfFile.storage_path = File.expand_path '../../../fixtures/files', __FILE__ User.current = nil end diff --git a/test/integration/dmsf_webdav_head_test.rb b/test/integration/webdav/dmsf_webdav_head_test.rb similarity index 97% rename from test/integration/dmsf_webdav_head_test.rb rename to test/integration/webdav/dmsf_webdav_head_test.rb index 5d4fdabd..9c4e6ec9 100644 --- a/test/integration/dmsf_webdav_head_test.rb +++ b/test/integration/webdav/dmsf_webdav_head_test.rb @@ -19,7 +19,7 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -require File.expand_path('../../test_helper', __FILE__) +require File.expand_path('../../../test_helper', __FILE__) class DmsfWebdavHeadTest < RedmineDmsf::Test::IntegrationTest @@ -33,7 +33,7 @@ class DmsfWebdavHeadTest < RedmineDmsf::Test::IntegrationTest @project2 = Project.find_by_id 2 Setting.plugin_redmine_dmsf['dmsf_webdav'] = '1' Setting.plugin_redmine_dmsf['dmsf_webdav_strategy'] = 'WEBDAV_READ_WRITE' - DmsfFile.storage_path = File.expand_path '../../fixtures/files', __FILE__ + DmsfFile.storage_path = File.expand_path '../../../fixtures/files', __FILE__ User.current = nil end diff --git a/test/integration/dmsf_webdav_mkcol_test.rb b/test/integration/webdav/dmsf_webdav_mkcol_test.rb similarity index 96% rename from test/integration/dmsf_webdav_mkcol_test.rb rename to test/integration/webdav/dmsf_webdav_mkcol_test.rb index 74bc16f4..ac571671 100644 --- a/test/integration/dmsf_webdav_mkcol_test.rb +++ b/test/integration/webdav/dmsf_webdav_mkcol_test.rb @@ -19,7 +19,7 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -require File.expand_path('../../test_helper', __FILE__) +require File.expand_path('../../../test_helper', __FILE__) class DmsfWebdavMkcolTest < RedmineDmsf::Test::IntegrationTest @@ -35,7 +35,7 @@ class DmsfWebdavMkcolTest < RedmineDmsf::Test::IntegrationTest @folder6 = DmsfFolder.find_by_id 6 Setting.plugin_redmine_dmsf['dmsf_webdav'] = '1' Setting.plugin_redmine_dmsf['dmsf_webdav_strategy'] = 'WEBDAV_READ_WRITE' - DmsfFile.storage_path = File.expand_path '../../fixtures/files', __FILE__ + DmsfFile.storage_path = File.expand_path '../../../fixtures/files', __FILE__ User.current = nil end diff --git a/test/integration/dmsf_webdav_options_test.rb b/test/integration/webdav/dmsf_webdav_options_test.rb similarity index 99% rename from test/integration/dmsf_webdav_options_test.rb rename to test/integration/webdav/dmsf_webdav_options_test.rb index e0d3471d..069b2ed4 100644 --- a/test/integration/dmsf_webdav_options_test.rb +++ b/test/integration/webdav/dmsf_webdav_options_test.rb @@ -19,7 +19,7 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -require File.expand_path('../../test_helper', __FILE__) +require File.expand_path('../../../test_helper', __FILE__) class DmsfWebdavOptionsTest < RedmineDmsf::Test::IntegrationTest diff --git a/test/integration/dmsf_webdav_post_test.rb b/test/integration/webdav/dmsf_webdav_post_test.rb similarity index 96% rename from test/integration/dmsf_webdav_post_test.rb rename to test/integration/webdav/dmsf_webdav_post_test.rb index 1babb4bb..eadc722f 100644 --- a/test/integration/dmsf_webdav_post_test.rb +++ b/test/integration/webdav/dmsf_webdav_post_test.rb @@ -19,7 +19,7 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -require File.expand_path('../../test_helper', __FILE__) +require File.expand_path('../../../test_helper', __FILE__) class DmsfWebdavPostTest < RedmineDmsf::Test::IntegrationTest diff --git a/test/integration/dmsf_webdav_put_test.rb b/test/integration/webdav/dmsf_webdav_put_test.rb similarity index 81% rename from test/integration/dmsf_webdav_put_test.rb rename to test/integration/webdav/dmsf_webdav_put_test.rb index 17924d04..20073b86 100644 --- a/test/integration/dmsf_webdav_put_test.rb +++ b/test/integration/webdav/dmsf_webdav_put_test.rb @@ -19,7 +19,7 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -require File.expand_path('../../test_helper', __FILE__) +require File.expand_path('../../../test_helper', __FILE__) require 'fileutils' class DmsfWebdavPutTest < RedmineDmsf::Test::IntegrationTest @@ -226,46 +226,48 @@ class DmsfWebdavPutTest < RedmineDmsf::Test::IntegrationTest 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 + 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 - 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 + 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 - 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