#1132 Unit tests
This commit is contained in:
parent
06d7bb8762
commit
de3d262965
@ -4,6 +4,13 @@ Changelog for Redmine DMSF
|
|||||||
3.1.3 *????-??-??*
|
3.1.3 *????-??-??*
|
||||||
------------------
|
------------------
|
||||||
|
|
||||||
|
DMS Document as a new custom field type
|
||||||
|
Copy/Move of multiple entries
|
||||||
|
REST API
|
||||||
|
Entries operation (copy, move, download, delete)
|
||||||
|
|
||||||
|
IMPORTANT: REST API for copying/moving has changed.
|
||||||
|
|
||||||
3.1.2 *2023-08-23*
|
3.1.2 *2023-08-23*
|
||||||
------------------
|
------------------
|
||||||
|
|
||||||
|
|||||||
@ -38,7 +38,7 @@ class DmsfController < ApplicationController
|
|||||||
before_action :find_target_folder, only: %i[copymove entries_operation]
|
before_action :find_target_folder, only: %i[copymove entries_operation]
|
||||||
before_action :check_target_folder, only: [:entries_operation]
|
before_action :check_target_folder, only: [:entries_operation]
|
||||||
|
|
||||||
accept_api_auth :show, :create, :save, :delete
|
accept_api_auth :show, :create, :save, :delete, :entries_operation
|
||||||
|
|
||||||
helper :custom_fields
|
helper :custom_fields
|
||||||
helper :dmsf_folder_permissions
|
helper :dmsf_folder_permissions
|
||||||
@ -612,17 +612,18 @@ class DmsfController < ApplicationController
|
|||||||
not_deleted_files = []
|
not_deleted_files = []
|
||||||
if selected_files.any?
|
if selected_files.any?
|
||||||
raise RedmineDmsf::Errors::DmsfAccessError unless User.current.allowed_to?(:file_delete, @project)
|
raise RedmineDmsf::Errors::DmsfAccessError unless User.current.allowed_to?(:file_delete, @project)
|
||||||
end
|
|
||||||
selected_files.each do |id|
|
selected_files.each do |id|
|
||||||
file = DmsfFile.find_by(id: id)
|
file = DmsfFile.find_by(id: id)
|
||||||
if file
|
if file
|
||||||
if file.delete(commit: commit)
|
if file.delete(commit: commit)
|
||||||
deleted_files << file unless commit
|
deleted_files << file unless commit
|
||||||
else
|
else
|
||||||
not_deleted_files << file
|
not_deleted_files << file
|
||||||
|
end
|
||||||
|
elsif !commit
|
||||||
|
raise RedmineDmsf::Errors::DmsfFileNotFoundError
|
||||||
end
|
end
|
||||||
elsif !commit
|
|
||||||
raise RedmineDmsf::Errors::DmsfFileNotFoundError
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
# Activities
|
# Activities
|
||||||
@ -647,10 +648,11 @@ class DmsfController < ApplicationController
|
|||||||
# Links
|
# Links
|
||||||
if selected_links.any?
|
if selected_links.any?
|
||||||
raise RedmineDmsf::Errors::DmsfAccessError unless User.current.allowed_to?(:folder_manipulation, @project)
|
raise RedmineDmsf::Errors::DmsfAccessError unless User.current.allowed_to?(:folder_manipulation, @project)
|
||||||
end
|
|
||||||
selected_links.each do |id|
|
selected_links.each do |id|
|
||||||
link = DmsfLink.find_by(id: id)
|
link = DmsfLink.find_by(id: id)
|
||||||
link&.delete commit: commit
|
link&.delete commit: commit
|
||||||
|
end
|
||||||
end
|
end
|
||||||
flash[:notice] = l(:notice_entries_deleted) if flash[:error].blank? && flash[:warning].blank?
|
flash[:notice] = l(:notice_entries_deleted) if flash[:error].blank? && flash[:warning].blank?
|
||||||
end
|
end
|
||||||
@ -685,6 +687,7 @@ class DmsfController < ApplicationController
|
|||||||
if (selected_folders.any? || selected_links.any?) && !User.current.allowed_to?(:file_manipulation, @project)
|
if (selected_folders.any? || selected_links.any?) && !User.current.allowed_to?(:file_manipulation, @project)
|
||||||
raise RedmineDmsf::Errors::DmsfAccessError
|
raise RedmineDmsf::Errors::DmsfAccessError
|
||||||
end
|
end
|
||||||
|
|
||||||
# Folders
|
# Folders
|
||||||
selected_folders.each do |id|
|
selected_folders.each do |id|
|
||||||
folder = DmsfFolder.find_by(id: id)
|
folder = DmsfFolder.find_by(id: id)
|
||||||
@ -695,16 +698,12 @@ class DmsfController < ApplicationController
|
|||||||
# Files
|
# Files
|
||||||
selected_files.each do |id|
|
selected_files.each do |id|
|
||||||
file = DmsfFile.find_by(id: id)
|
file = DmsfFile.find_by(id: id)
|
||||||
unless file.move_to(@target_project, @target_folder)
|
raise(StandardError, file.errors.full_messages.to_sentence) unless file.move_to(@target_project, @target_folder)
|
||||||
raise(StandardError, file.errors.full_messages.to_sentence)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
# Links
|
# Links
|
||||||
selected_links.each do |id|
|
selected_links.each do |id|
|
||||||
link = DmsfLink.find_by(id: id)
|
link = DmsfLink.find_by(id: id)
|
||||||
unless link.move_to(@target_project, @target_folder)
|
raise(StandardError, link.errors.full_messages.to_sentence) unless link.move_to(@target_project, @target_folder)
|
||||||
raise(StandardError, link.errors.full_messages.to_sentence)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
flash[:notice] = l(:notice_entries_moved) if flash[:error].blank? && flash[:warning].blank?
|
flash[:notice] = l(:notice_entries_moved) if flash[:error].blank? && flash[:warning].blank?
|
||||||
end
|
end
|
||||||
@ -789,45 +788,44 @@ class DmsfController < ApplicationController
|
|||||||
@selected_folders = params[:ids].grep(/folder-\d+/).map { |x| Regexp.last_match(1).to_i if x =~ /folder-(\d+)/ }
|
@selected_folders = params[:ids].grep(/folder-\d+/).map { |x| Regexp.last_match(1).to_i if x =~ /folder-(\d+)/ }
|
||||||
@selected_files = params[:ids].grep(/file-\d+/).map { |x| Regexp.last_match(1).to_i if x =~ /file-(\d+)/ }
|
@selected_files = params[:ids].grep(/file-\d+/).map { |x| Regexp.last_match(1).to_i if x =~ /file-(\d+)/ }
|
||||||
@selected_dir_links = params[:ids].grep(/folder-link-\d+/)
|
@selected_dir_links = params[:ids].grep(/folder-link-\d+/)
|
||||||
.map { |x| Regexp.last_match(1).to_i if x =~ /folder-link-(\d+)/ }
|
.map { |x| Regexp.last_match(1).to_i if x =~ /folder-link-(\d+)/ }
|
||||||
@selected_file_links = params[:ids].grep(/file-link-\d+/)
|
@selected_file_links = params[:ids].grep(/file-link-\d+/)
|
||||||
.map { |x| Regexp.last_match(1).to_i if x =~ /file-link-(\d+)/ }
|
.map { |x| Regexp.last_match(1).to_i if x =~ /file-link-(\d+)/ }
|
||||||
@selected_url_links = params[:ids].grep(/url-link-\d+/)
|
@selected_url_links = params[:ids].grep(/url-link-\d+/)
|
||||||
.map { |x| Regexp.last_match(1).to_i if x =~ /url-link-(\d+)/ }
|
.map { |x| Regexp.last_match(1).to_i if x =~ /url-link-(\d+)/ }
|
||||||
@selected_links = @selected_dir_links + @selected_file_links + @selected_url_links
|
@selected_links = @selected_dir_links + @selected_file_links + @selected_url_links
|
||||||
else
|
else
|
||||||
@selected_folders = []
|
@selected_folders = []
|
||||||
@selected_files = []
|
@selected_files = []
|
||||||
@selected_links = []
|
@selected_links = []
|
||||||
end
|
end
|
||||||
if params[:copy_entries].present? || params[:move_entries].present?
|
return unless params[:copy_entries].present? || params[:move_entries].present?
|
||||||
begin
|
|
||||||
# Prevent copying/moving to the same destination
|
begin
|
||||||
folders = DmsfFolder.where(id: @selected_folders).to_a
|
# Prevent copying/moving to the same destination
|
||||||
files = DmsfFile.where(id: @selected_files).to_a
|
folders = DmsfFolder.where(id: @selected_folders).to_a
|
||||||
links = DmsfLink.where(id: @selected_links).to_a
|
files = DmsfFile.where(id: @selected_files).to_a
|
||||||
(folders + files + links).each do |entry|
|
links = DmsfLink.where(id: @selected_links).to_a
|
||||||
raise RedmineDmsf::Errors::DmsfParentError if entry.dmsf_folder == @target_folder || entry == @target_folder
|
(folders + files + links).each do |entry|
|
||||||
end
|
raise RedmineDmsf::Errors::DmsfParentError if entry.dmsf_folder == @target_folder || entry == @target_folder
|
||||||
# Prevent recursion
|
|
||||||
if params[:move_entries].present?
|
|
||||||
folders.each do |entry|
|
|
||||||
b = entry.any_child?(@target_folder)
|
|
||||||
raise RedmineDmsf::Errors::DmsfParentError if entry.any_child?(@target_folder)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
# Check permissions
|
|
||||||
if (@target_folder && (@target_folder.locked_for_user? ||
|
|
||||||
!DmsfFolder.permissions?(@target_folder, allow_system: false))) ||
|
|
||||||
!@target_project.allows_to?(:folder_manipulation)
|
|
||||||
raise RedmineDmsf::Errors::DmsfAccessError
|
|
||||||
end
|
|
||||||
rescue RedmineDmsf::Errors::DmsfParentError
|
|
||||||
flash[:error] = l(:error_target_folder_same)
|
|
||||||
redirect_back_or_default dmsf_folder_path(id: @project, folder_id: @folder)
|
|
||||||
rescue RedmineDmsf::Errors::DmsfAccessError
|
|
||||||
render_403
|
|
||||||
end
|
end
|
||||||
|
# Prevent recursion
|
||||||
|
if params[:move_entries].present?
|
||||||
|
folders.each do |entry|
|
||||||
|
raise RedmineDmsf::Errors::DmsfParentError if entry.any_child?(@target_folder)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
# Check permissions
|
||||||
|
if (@target_folder && (@target_folder.locked_for_user? ||
|
||||||
|
!DmsfFolder.permissions?(@target_folder, allow_system: false))) ||
|
||||||
|
!@target_project.allows_to?(:folder_manipulation)
|
||||||
|
raise RedmineDmsf::Errors::DmsfAccessError
|
||||||
|
end
|
||||||
|
rescue RedmineDmsf::Errors::DmsfParentError
|
||||||
|
flash[:error] = l(:error_target_folder_same)
|
||||||
|
redirect_back_or_default dmsf_folder_path(id: @project, folder_id: @folder)
|
||||||
|
rescue RedmineDmsf::Errors::DmsfAccessError
|
||||||
|
render_403
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -305,9 +305,8 @@ class DmsfFolder < ApplicationRecord
|
|||||||
new_folder.user = User.current
|
new_folder.user = User.current
|
||||||
new_folder.custom_values = []
|
new_folder.custom_values = []
|
||||||
new_folder.custom_field_values =
|
new_folder.custom_field_values =
|
||||||
custom_field_values.inject({}) do |h, v|
|
custom_field_values.each_with_object({}) do |v, h|
|
||||||
h[v.custom_field_id] = v.value
|
h[v.custom_field_id] = v.value
|
||||||
h
|
|
||||||
end
|
end
|
||||||
unless new_folder.save
|
unless new_folder.save
|
||||||
Rails.logger.error new_folder.errors.full_messages.to_sentence
|
Rails.logger.error new_folder.errors.full_messages.to_sentence
|
||||||
@ -604,6 +603,7 @@ class DmsfFolder < ApplicationRecord
|
|||||||
def any_child?(folder)
|
def any_child?(folder)
|
||||||
dmsf_folders.each do |child|
|
dmsf_folders.each do |child|
|
||||||
return true if child == folder
|
return true if child == folder
|
||||||
|
|
||||||
child.any_child? folder
|
child.any_child? folder
|
||||||
end
|
end
|
||||||
false
|
false
|
||||||
|
|||||||
@ -36,7 +36,7 @@ if Redmine::Plugin.installed? 'redmine_dmsf'
|
|||||||
delete '/projects/:id/dmsf/delete', controller: 'dmsf', action: 'delete', as: 'delete_dmsf'
|
delete '/projects/:id/dmsf/delete', controller: 'dmsf', action: 'delete', as: 'delete_dmsf'
|
||||||
post '/projects/:id/dmsf/save', controller: 'dmsf', action: 'save'
|
post '/projects/:id/dmsf/save', controller: 'dmsf', action: 'save'
|
||||||
post '/projects/:id/dmsf/save/root', controller: 'dmsf', action: 'save_root'
|
post '/projects/:id/dmsf/save/root', controller: 'dmsf', action: 'save_root'
|
||||||
post '/projects/dmsf/entries', controller: 'dmsf', action: 'entries_operation', as: 'entries_operations_dmsf'
|
post '/projects/:id/dmsf/entries', controller: 'dmsf', action: 'entries_operation', as: 'entries_operations_dmsf'
|
||||||
post '/projects/:id/dmsf/entries/delete', controller: 'dmsf', action: 'delete_entries', as: 'delete_entries'
|
post '/projects/:id/dmsf/entries/delete', controller: 'dmsf', action: 'delete_entries', as: 'delete_entries'
|
||||||
post '/projects/:id/dmsf/entries/email', to: 'dmsf#entries_email', as: 'email_entries'
|
post '/projects/:id/dmsf/entries/email', to: 'dmsf#entries_email', as: 'email_entries'
|
||||||
get '/projects/:id/dmsf/entries/download_email_entries', controller: 'dmsf',
|
get '/projects/:id/dmsf/entries/download_email_entries', controller: 'dmsf',
|
||||||
|
|||||||
@ -19,8 +19,9 @@
|
|||||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
|
||||||
# Authentication as input parameters either as login + password or the API key
|
# Authentication as input parameters either as login + password or the API key
|
||||||
# -u ${1}:${2}
|
#USER_LOGIN="${1}"
|
||||||
# -H "X-Redmine-API-Key: ${1}"
|
#USER_PASSWORD="${2}"
|
||||||
|
#USER_API_KEY="${1}"
|
||||||
|
|
||||||
# BOTH XML and JSON formats are supported.
|
# BOTH XML and JSON formats are supported.
|
||||||
# Just replace .xml with .json
|
# Just replace .xml with .json
|
||||||
@ -28,41 +29,41 @@
|
|||||||
# Uncomment a corresponding line to the case you would like to test
|
# Uncomment a corresponding line to the case you would like to test
|
||||||
|
|
||||||
# 1. List of documents in a given folder or the root folder
|
# 1. List of documents in a given folder or the root folder
|
||||||
#curl -v -H "Content-Type: application/xml" -X GET -u ${1}:${2} http://localhost:3000/projects/12/dmsf.xml
|
#curl -v -H "Content-Type: application/xml" -X GET -u ${USER_LOGIN}:${USER_PASSWORD} http://localhost:3000/projects/12/dmsf.xml
|
||||||
#curl -v -H "Content-Type: application/xml" -X GET -u ${1}:${2} http://localhost:3000/projects/12/dmsf.xml?folder_id=5155
|
#curl -v -H "Content-Type: application/xml" -X GET -u ${USER_LOGIN}:${USER_PASSWORD} http://localhost:3000/projects/12/dmsf.xml?folder_id=5155
|
||||||
#curl -v -H "Content-Type: application/xml" -X GET -u ${1}:${2} "http://localhost:3000/projects/12/dmsf.xml?limit=2&offset=1"
|
#curl -v -H "Content-Type: application/xml" -X GET -u ${USER_LOGIN}:${USER_PASSWORD} "http://localhost:3000/projects/12/dmsf.xml?limit=2&offset=1"
|
||||||
|
|
||||||
# 2. Get a document
|
# 2. Get a document
|
||||||
#curl -v -H "Content-Type: application/xml" -X GET -u ${1}:${2} http://localhost:3000/dmsf/files/17216.xml
|
#curl -v -H "Content-Type: application/xml" -X GET -u ${USER_LOGIN}:${USER_PASSWORD} http://localhost:3000/dmsf/files/17216.xml
|
||||||
#curl -v -H "Content-Type: application/octet-stream" -X GET -u ${1}:${2} http://localhost:3000/dmsf/files/41532/download > file.txt
|
#curl -v -H "Content-Type: application/octet-stream" -X GET -u ${USER_LOGIN}:${USER_PASSWORD} http://localhost:3000/dmsf/files/41532/download > file.txt
|
||||||
|
|
||||||
# 3. Upload a document into a given folder or the root folder
|
# 3. Upload a document into a given folder or the root folder
|
||||||
#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
|
#curl --data-binary "@cat.gif" -H "Content-Type: application/octet-stream" -X POST -u ${USER_LOGIN}:${USER_PASSWORD} http://localhost:3000/projects/12/dmsf/upload.xml?filename=cat.gif
|
||||||
#curl -v -H "Content-Type: application/xml" -X POST --data "@file.xml" -u ${1}:${2} http://localhost:3000/projects/12/dmsf/commit.xml
|
#curl -v -H "Content-Type: application/xml" -X POST --data "@file.xml" -u ${USER_LOGIN}:${USER_PASSWORD} http://localhost:3000/projects/12/dmsf/commit.xml
|
||||||
|
|
||||||
# 4. Create a new revision
|
# 4. Create a new revision
|
||||||
#curl -v -H "Content-Type: application/xml" -X POST --data "@revision.xml" -u ${1}:${2} http://localhost:3000/dmsf/files/232565/revision/create.xml
|
#curl -v -H "Content-Type: application/xml" -X POST --data "@revision.xml" -u ${USER_LOGIN}:${USER_PASSWORD} http://localhost:3000/dmsf/files/232565/revision/create.xml
|
||||||
|
|
||||||
# 5. Copy a document
|
# 5. Copy document(s)
|
||||||
#curl -v -H "Content-Type: application/xml" -X POST --data "@file_or_folder_copy_move.xml" -H "X-Redmine-API-Key: USERS_API_KEY" http://localhost:3000/dmsf/files/233313/copy/copy.xml
|
#curl -v -H "Content-Type: application/xml" -X POST --data "@entries.xml" -H "X-Redmine-API-Key: ${USER_API_KEY}" "http://localhost:3000/projects/3342/dmsf/entries.xml?ids[]=file-254566©_entries=true"
|
||||||
|
|
||||||
# 6. Move a document
|
# 6. Move document(s)
|
||||||
#curl -v -H "Content-Type: application/xml" -X POST --data "@file_or_folder_copy_move.xml" -H "X-Redmine-API-Key: USERS_API_KEY" http://localhost:3000/dmsf/files/233313/copy/move.xml
|
#curl -v -H "Content-Type: application/xml" -X POST --data "@entries.xml" -H "X-Redmine-API-Key: ${USER_API_KEY}" "http://localhost:3000/projects/3342/dmsf/entries.xml?ids[]=file-254566&move_entries=true"
|
||||||
|
|
||||||
# 7. Delete a document
|
# 7. Delete a document
|
||||||
# a) Move to trash only
|
# a) Move to trash only
|
||||||
# curl -v -H "Content-Type: application/xml" -X DELETE -u ${1}:${2} http://localhost:3000/dmsf/files/196118.xml
|
# curl -v -H "Content-Type: application/xml" -X DELETE -u ${USER_LOGIN}:${USER_PASSWORD} http://localhost:3000/dmsf/files/196118.xml
|
||||||
# b) Delete permanently
|
# b) Delete permanently
|
||||||
# curl -v -H "Content-Type: application/xml" -X DELETE -u ${1}:${2} http://localhost:3000/dmsf/files/196118.xml?commit=yes"
|
# curl -v -H "Content-Type: application/xml" -X DELETE -u ${USER_LOGIN}:${USER_PASSWORD} http://localhost:3000/dmsf/files/196118.xml?commit=yes"
|
||||||
|
|
||||||
# 8. Create a folder
|
# 8. Create a folder
|
||||||
#curl -v -H "Content-Type: application/xml" -X POST --data "@folder.xml" -u ${1}:${2} http://localhost:3000/projects/12/dmsf/create.xml
|
#curl -v -H "Content-Type: application/xml" -X POST --data "@folder.xml" -u ${USER_LOGIN}:${USER_PASSWORD} http://localhost:3000/projects/12/dmsf/create.xml
|
||||||
|
|
||||||
# 9. List folder content & check folder existence (by folder title)
|
# 9. List folder content & 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
|
# 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
|
||||||
|
|
||||||
# 10. List folder content & check folder existence (by folder id)
|
# 10. List folder content & check folder existence (by folder id)
|
||||||
# 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_id=3
|
# 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_id=3
|
||||||
# both returns 404 not found, or json with following structure:
|
# both returns 404 not found, or json with following structure:
|
||||||
# {
|
# {
|
||||||
# "dmsf":{
|
# "dmsf":{
|
||||||
@ -74,7 +75,7 @@
|
|||||||
#}
|
#}
|
||||||
|
|
||||||
# 11. Update a folder
|
# 11. Update a 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?folder_id=#{folder_id}
|
# 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
|
# update-folder-payload.json
|
||||||
# {
|
# {
|
||||||
@ -85,16 +86,16 @@
|
|||||||
# }
|
# }
|
||||||
|
|
||||||
# 12. Copy a folder
|
# 12. Copy a folder
|
||||||
#curl -v -H "Content-Type: application/xml" -X POST --data "@file_or_folder_copy_move.xml" -H "X-Redmine-API-Key: USERS_API_KEY" http://localhost:3000/dmsf/folders/53075/copy/copy.xml
|
#curl -v -H "Content-Type: application/xml" -X POST --data "@file_or_folder_copy_move.xml" -H "X-Redmine-API-Key: ${USERS_API_KEY}" http://localhost:3000/dmsf/folders/53075/copy/copy.xml
|
||||||
|
|
||||||
# 13. Move a folder
|
# 13. Move a folder
|
||||||
#curl -v -H "Content-Type: application/xml" -X POST --data "@file_or_folder_copy_move.xml" -H "X-Redmine-API-Key: USERS_API_KEY" http://localhost:3000/dmsf/folders/53075/copy/move.xml
|
#curl -v -H "Content-Type: application/xml" -X POST --data "@file_or_folder_copy_move.xml" -H "X-Redmine-API-Key: ${USERS_API_KEY}" http://localhost:3000/dmsf/folders/53075/copy/move.xml
|
||||||
|
|
||||||
# 14. Delete a folder
|
# 14. Delete a folder
|
||||||
# a) Move to trash only
|
# a) Move to trash only
|
||||||
# curl -v -H "Content-Type: application/xml" -X DELETE -u ${1}:${2} http://localhost:3000/projects/2387/dmsf/delete.xml?folder_id=#{folder_id}
|
# curl -v -H "Content-Type: application/xml" -X DELETE -u ${USER_LOGIN}:${USER_PASSWORD} http://localhost:3000/projects/2387/dmsf/delete.xml?folder_id=#{folder_id}
|
||||||
# b) Delete permanently
|
# b) Delete permanently
|
||||||
# curl -v -H "Content-Type: application/xml" -X DELETE -u ${1}:${2} "http://localhost:3000/projects/2387/dmsf/delete.xml?folder_id=#{folder_id}&commit=yes"
|
# curl -v -H "Content-Type: application/xml" -X DELETE -u ${USER_LOGIN}:${USER_PASSWORD} "http://localhost:3000/projects/2387/dmsf/delete.xml?folder_id=#{folder_id}&commit=yes"
|
||||||
|
|
||||||
# 15. Create a symbolic link
|
# 15. Create a symbolic link
|
||||||
# curl -v -H "Content-Type: application/xml" -X POST --data "@link.xml" -H "X-Redmine-API-Key: USERS_API_KEY" http://localhost:3000/dmsf_links.xml
|
# curl -v -H "Content-Type: application/xml" -X POST --data "@link.xml" -H "X-Redmine-API-Key: ${USERS_API_KEY}" http://localhost:3000/dmsf_links.xml
|
||||||
5
extra/api/entries.xml
Normal file
5
extra/api/entries.xml
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8" ?>
|
||||||
|
<dmsf_entries>
|
||||||
|
<target_project_id>3342</target_project_id>
|
||||||
|
<target_folder_id>58659</target_folder_id>
|
||||||
|
</dmsf_entries>
|
||||||
@ -1,5 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8" ?>
|
|
||||||
<dmsf_file_or_folder>
|
|
||||||
<target_project_id>3057</target_project_id>
|
|
||||||
<target_folder_id>53064</target_folder_id>
|
|
||||||
</dmsf_file_or_folder>
|
|
||||||
@ -496,7 +496,7 @@ class DmsfControllerTest < RedmineDmsf::Test::TestCase
|
|||||||
assert_nil flash[:error]
|
assert_nil flash[:error]
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_entries_copy
|
def test_entries_copy_to_the_same_folder
|
||||||
post :entries_operation,
|
post :entries_operation,
|
||||||
params: { id: @file1.project,
|
params: { id: @file1.project,
|
||||||
dmsf_entries: { target_project_id: @file1.project.id, target_folder_id: @file1.dmsf_folder },
|
dmsf_entries: { target_project_id: @file1.project.id, target_folder_id: @file1.dmsf_folder },
|
||||||
@ -581,10 +581,10 @@ class DmsfControllerTest < RedmineDmsf::Test::TestCase
|
|||||||
def test_entries_move_fast_links_enabled
|
def test_entries_move_fast_links_enabled
|
||||||
# Target project is not given
|
# Target project is not given
|
||||||
post :entries_operation,
|
post :entries_operation,
|
||||||
params: { id: @project1.id,
|
params: { id: @project1.id,
|
||||||
dmsf_entries: { target_folder_id: @folder1.id },
|
dmsf_entries: { target_folder_id: @folder1.id },
|
||||||
ids: ["file-#{@file1.id}"],
|
ids: ["file-#{@file1.id}"],
|
||||||
move_entries: true }
|
move_entries: true }
|
||||||
assert_response :redirect
|
assert_response :redirect
|
||||||
assert_nil flash[:error]
|
assert_nil flash[:error]
|
||||||
end
|
end
|
||||||
|
|||||||
@ -109,4 +109,40 @@ class DmsfFileApiTest < RedmineDmsf::Test::IntegrationTest
|
|||||||
assert_select 'node > target_id', text: @folder_link1.target_id.to_s
|
assert_select 'node > target_id', text: @folder_link1.target_id.to_s
|
||||||
assert_select 'node > target_project_id', text: @folder_link1.target_project_id.to_s
|
assert_select 'node > target_project_id', text: @folder_link1.target_project_id.to_s
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_copy_entries
|
||||||
|
# curl -v -H "Content-Type: application/xml" -X POST --data "@entries.xml" -H "X-Redmine-API-Key: ${USER_API_KEY}" \
|
||||||
|
# "http://localhost:3000/projects/3342/dmsf/entries.xml?ids[]=file-254566©_entries=true"
|
||||||
|
payload = %(
|
||||||
|
<?xml version="1.0" encoding="utf-8" ?>
|
||||||
|
<dmsf_entries>
|
||||||
|
<target_project_id>#{@project1.id}</target_project_id>
|
||||||
|
<target_folder_id>#{@folder1.id}</target_folder_id>
|
||||||
|
</dmsf_entries>
|
||||||
|
)
|
||||||
|
assert_difference('@folder1.dmsf_files.count', 1) do
|
||||||
|
post "/projects/#{@project1.id}/dmsf/entries.xml?ids[]=file-#{@file1.id}©_entries=true&key=#{@token.value}",
|
||||||
|
params: payload,
|
||||||
|
headers: { 'CONTENT_TYPE' => 'application/xml' }
|
||||||
|
end
|
||||||
|
assert_response :redirect
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_move_entries
|
||||||
|
# curl -v -H "Content-Type: application/xml" -X POST --data "@entries.xml" -H "X-Redmine-API-Key: ${USER_API_KEY}" \
|
||||||
|
# "http://localhost:3000/projects/3342/dmsf/entries.xml?ids[]=file-254566&move_entries=true"
|
||||||
|
payload = %(
|
||||||
|
<?xml version="1.0" encoding="utf-8" ?>
|
||||||
|
<dmsf_entries>
|
||||||
|
<target_project_id>#{@project1.id}</target_project_id>
|
||||||
|
<target_folder_id>#{@folder1.id}</target_folder_id>
|
||||||
|
</dmsf_entries>
|
||||||
|
)
|
||||||
|
assert_difference('@folder1.dmsf_files.count', 1) do
|
||||||
|
post "/projects/#{@project1.id}/dmsf/entries.xml?ids[]=file-#{@file1.id}&move_entries=true&key=#{@token.value}",
|
||||||
|
params: payload,
|
||||||
|
headers: { 'CONTENT_TYPE' => 'application/xml' }
|
||||||
|
end
|
||||||
|
assert_response :redirect
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -240,40 +240,4 @@ class DmsfFileApiTest < RedmineDmsf::Test::IntegrationTest
|
|||||||
# </dmsf_file_revision>
|
# </dmsf_file_revision>
|
||||||
assert_select 'dmsf_file_revision > id', text: @file1.last_revision.id.to_s
|
assert_select 'dmsf_file_revision > id', text: @file1.last_revision.id.to_s
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_copy_document
|
|
||||||
# curl -v -H "Content-Type: application/xml" -X POST --data "@file_or_folder_copy_move.xml"
|
|
||||||
# -H "X-Redmine-API-Key: USERS_API_KEY" http://localhost:3000/dmsf/files/1/copy/copy.xml
|
|
||||||
payload = %(
|
|
||||||
<?xml version="1.0" encoding="utf-8" ?>
|
|
||||||
<dmsf_file_or_folder>
|
|
||||||
<target_project_id>#{@project1.id}</target_project_id>
|
|
||||||
<target_folder_id>#{@folder1.id}</target_folder_id>
|
|
||||||
</dmsf_file_or_folder>
|
|
||||||
)
|
|
||||||
assert_difference('@folder1.dmsf_files.count', 1) do
|
|
||||||
post "/dmsf/files/#{@file1.id}/copy/copy.xml?key=#{@token.value}",
|
|
||||||
params: payload,
|
|
||||||
headers: { 'CONTENT_TYPE' => 'application/xml' }
|
|
||||||
end
|
|
||||||
assert_response :success
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_move_document
|
|
||||||
# curl -v -H "Content-Type: application/xml" -X POST --data "@file_or_folder_copy_move.xml" -H
|
|
||||||
# "X-Redmine-API-Key: USERS_API_KEY" http://localhost:3000/dmsf/files/1/copy/move.xml
|
|
||||||
payload = %(
|
|
||||||
<?xml version="1.0" encoding="utf-8" ?>
|
|
||||||
<dmsf_file_or_folder>
|
|
||||||
<target_project_id>#{@project1.id}</target_project_id>
|
|
||||||
<target_folder_id>#{@folder1.id}</target_folder_id>
|
|
||||||
</dmsf_file_or_folder>
|
|
||||||
)
|
|
||||||
assert_difference('@folder1.dmsf_files.count', 1) do
|
|
||||||
post "/dmsf/files/#{@file1.id}/copy/move.xml?key=#{@token.value}",
|
|
||||||
params: payload,
|
|
||||||
headers: { 'CONTENT_TYPE' => 'application/xml' }
|
|
||||||
end
|
|
||||||
assert_response :success
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|||||||
@ -292,40 +292,4 @@ class DmsfFolderApiTest < RedmineDmsf::Test::IntegrationTest
|
|||||||
@folder2.reload
|
@folder2.reload
|
||||||
assert_equal DmsfFolder::STATUS_ACTIVE, @folder2.deleted
|
assert_equal DmsfFolder::STATUS_ACTIVE, @folder2.deleted
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_copy_folder
|
|
||||||
# curl -v -H "Content-Type: application/xml" -X POST --data "@file_or_folder_copy_move.xml"
|
|
||||||
# -H "X-Redmine-API-Key: USERS_API_KEY" http://localhost:3000/dmsf/folders/6/copy/copy.xml
|
|
||||||
payload = %(
|
|
||||||
<?xml version="1.0" encoding="utf-8" ?>
|
|
||||||
<dmsf_file_or_folder>
|
|
||||||
<target_project_id>#{@project1.id}</target_project_id>
|
|
||||||
<target_folder_id>#{@folder1.id}</target_folder_id>
|
|
||||||
</dmsf_file_or_folder>
|
|
||||||
)
|
|
||||||
assert_difference('@folder1.dmsf_folders.count', 1) do
|
|
||||||
post "/dmsf/folders/#{@folder6.id}/copy/copy.xml?key=#{@token.value}",
|
|
||||||
params: payload,
|
|
||||||
headers: { 'CONTENT_TYPE' => 'application/xml' }
|
|
||||||
end
|
|
||||||
assert_response :success
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_move_document
|
|
||||||
# curl -v -H "Content-Type: application/xml" -X POST --data "@file_or_folder_copy_move.xml"
|
|
||||||
# -H "X-Redmine-API-Key: USERS_API_KEY" http://localhost:3000/dmsf/folders/6/copy/move.xml
|
|
||||||
payload = %(
|
|
||||||
<?xml version="1.0" encoding="utf-8" ?>
|
|
||||||
<dmsf_file_or_folder>
|
|
||||||
<target_project_id>#{@project1.id}</target_project_id>
|
|
||||||
<target_folder_id>#{@folder1.id}</target_folder_id>
|
|
||||||
</dmsf_file_or_folder>
|
|
||||||
)
|
|
||||||
assert_difference('@folder1.dmsf_folders.count', 1) do
|
|
||||||
post "/dmsf/folders/#{@folder6.id}/copy/move.xml?key=#{@token.value}",
|
|
||||||
params: payload,
|
|
||||||
headers: { 'CONTENT_TYPE' => 'application/xml' }
|
|
||||||
end
|
|
||||||
assert_response :success
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user