From ff29ca0cf8d9fab03a7be915c6b7d8891982ebc6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karel=20Pi=C4=8Dman?= Date: Mon, 11 Sep 2023 12:24:35 +0200 Subject: [PATCH] #1132 REST API --- CHANGELOG.md | 2 +- README.md | 1 + extra/api/api_client.sh | 30 ++++++++++++---------- test/integration/rest_api/dmsf_api_test.rb | 20 +++++++++++++++ 4 files changed, 39 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 17adb7aa..71f00847 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,7 +9,7 @@ Changelog for Redmine DMSF REST API Entries operation (copy, move, download, delete) -IMPORTANT: REST API for copying/moving has changed. +IMPORTANT: REST API for copying/moving has changed. Check *extra/api/api_client.sh*. 3.1.2 *2023-08-23* ------------------ diff --git a/README.md b/README.md index ea599def..df8dba5e 100644 --- a/README.md +++ b/README.md @@ -38,6 +38,7 @@ Features * Documents attachable to issues * Office documents are displayed inline * Editing of office documents + * REST API * Compatible with Redmine 5.0.x Dependencies diff --git a/extra/api/api_client.sh b/extra/api/api_client.sh index c14eab84..6c1f0b04 100644 --- a/extra/api/api_client.sh +++ b/extra/api/api_client.sh @@ -21,7 +21,7 @@ # Authentication as input parameters either as login + password or the API key #USER_LOGIN="${1}" #USER_PASSWORD="${2}" -#USER_API_KEY="${1}" +USER_API_KEY="${1}" # BOTH XML and JSON formats are supported. # Just replace .xml with .json @@ -44,25 +44,29 @@ # 4. Create a new revision #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 document(s) +# 5. Entries operation +# 5.1 Copy document(s)/folder(s) #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 document(s) +# 5.2 Move document(s)/folder(s) #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" +# 5.3 Download document(x)/folders(s) +#curl -v -H "Content-Type: application/octet-stream" -X POST --data "" -H "X-Redmine-API-Key: ${USER_API_KEY}" http://localhost:3000/projects/3342/dmsf/entries.xml?ids[]=file-254566 +# 5.4 Delete document(x)/folder(s) +#curl -v -H "Content-Type: application/xml" -X POST --data "" -H "X-Redmine-API-Key: ${USER_API_KEY}" "http://localhost:3000/projects/3342/dmsf/entries.xml?ids[]=file-254566&delete_entries=true" -# 7. Delete a document +# 6. Delete a document # a) Move to trash only # curl -v -H "Content-Type: application/xml" -X DELETE -u ${USER_LOGIN}:${USER_PASSWORD} http://localhost:3000/dmsf/files/196118.xml # b) Delete permanently # 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 +# 7. Create a folder #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) +# 8. 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 -# 10. List folder content & check folder existence (by folder id) +# 9. 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 # both returns 404 not found, or json with following structure: # { @@ -74,7 +78,7 @@ # } #} -# 11. Update a folder +# 10. 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} # update-folder-payload.json @@ -85,17 +89,17 @@ # }, # } -# 12. Copy a folder +# 11. 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 -# 13. Move a folder +# 12. 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 -# 14. Delete a folder +# 13. Delete a folder # a) Move to trash only # 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 # 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 +# 14. 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 \ No newline at end of file diff --git a/test/integration/rest_api/dmsf_api_test.rb b/test/integration/rest_api/dmsf_api_test.rb index 4bf0f661..8c74c8d7 100644 --- a/test/integration/rest_api/dmsf_api_test.rb +++ b/test/integration/rest_api/dmsf_api_test.rb @@ -145,4 +145,24 @@ class DmsfFileApiTest < RedmineDmsf::Test::IntegrationTest end assert_response :redirect end + + def test_download_entries + # curl -v -H "Content-Type: application/xml" -X POST --data "" -H "X-Redmine-API-Key: ${USER_API_KEY}" \ + # "http://localhost:3000/projects/3342/dmsf/entries.xml?ids[]=file-254566" + post "/projects/#{@project1.id}/dmsf/entries.xml?ids[]=file-#{@file1.id}&key=#{@token.value}", + params: '', + headers: { 'CONTENT_TYPE' => 'application/octet-stream' } + assert_response :success + end + + def test_delete_entries + # curl -v -H "Content-Type: application/xml" -X POST --data "" -H "X-Redmine-API-Key: ${USER_API_KEY}" \ + # "http://localhost:3000/projects/3342/dmsf/entries.xml?ids[]=file-254566&delete_entries=true" + assert_difference('@project1.dmsf_files.visible.count', -1) do + post "/projects/#{@project1.id}/dmsf/entries.xml?ids[]=file-#{@file1.id}&delete_entries=true&key=#{@token.value}", + params: '', + headers: { 'CONTENT_TYPE' => 'application/xml' } + end + assert_response :redirect + end end