diff --git a/app/controllers/dmsf_files_controller.rb b/app/controllers/dmsf_files_controller.rb
index 0b4d9e2d..7aee8542 100644
--- a/app/controllers/dmsf_files_controller.rb
+++ b/app/controllers/dmsf_files_controller.rb
@@ -30,7 +30,7 @@ class DmsfFilesController < ApplicationController
before_action :authorize
before_action :permissions
- accept_api_auth :show, :view, :delete
+ accept_api_auth :show, :view, :delete, :create_revision
helper :custom_fields
helper :dmsf_workflows
@@ -100,9 +100,7 @@ class DmsfFilesController < ApplicationController
def create_revision
if params[:dmsf_file_revision]
- if @file.locked_for_user?
- flash[:error] = l(:error_file_is_locked)
- else
+ unless @file.locked_for_user?
revision = DmsfFileRevision.new
revision.title = params[:dmsf_file_revision][:title]
revision.name = params[:dmsf_file_revision][:name]
@@ -148,6 +146,7 @@ class DmsfFilesController < ApplicationController
end
@file.name = revision.name
+ ok = true
if revision.save
revision.assign_workflow params[:dmsf_workflow_id]
@@ -158,43 +157,48 @@ class DmsfFilesController < ApplicationController
Rails.logger.error e.message
flash[:error] = e.message
revision.destroy
- redirect_back_or_default dmsf_folder_path(id: @project.id, folder_id: @folder)
- return
+ ok = false
end
end
- if @file.locked? && !@file.locks.empty?
+ if ok && @file.locked? && !@file.locks.empty?
begin
@file.unlock!
flash[:notice] = "#{l(:notice_file_unlocked)}, "
rescue => e
Rails.logger.error "Cannot unlock the file: #{e.message}"
+ ok = false
end
end
- if @file.save
+ if ok && @file.save
@file.set_last_revision revision
Redmine::Hook.call_hook :dmsf_helper_upload_after_commit, { file: @file }
- flash[:notice] = (flash[:notice].nil? ? '' : flash[:notice]) + l(:notice_file_revision_created)
begin
recipients = DmsfMailer.deliver_files_updated(@project, [@file])
if Setting.plugin_redmine_dmsf['dmsf_display_notified_recipients']
if recipients.any?
to = recipients.collect{ |r| r.name }.first(DMSF_MAX_NOTIFICATION_RECEIVERS_INFO).join(', ')
to << ((recipients.count > DMSF_MAX_NOTIFICATION_RECEIVERS_INFO) ? ',...' : '.')
- flash[:warning] = l(:warning_email_notifications, to: to)
end
end
rescue => e
Rails.logger.error "Could not send email notifications: #{e.message}"
end
- else
- flash[:error] = @file.errors.full_messages.to_sentence
end
- else
- flash[:error] = revision.errors.full_messages.to_sentence
end
end
end
- redirect_back_or_default dmsf_folder_path(id: @project.id, folder_id: @folder)
+
+ respond_to do |format|
+ format.html do
+ flash[:error] = l(:error_file_is_locked) if @file.locked_for_user?
+ flash[:warning] = l(:warning_email_notifications, to: to) if to
+ flash[:error] = @file.errors.full_messages.to_sentence if @file.errors.any?
+ flash[:error] = revision.errors.full_messages.to_sentence if revision.errors.any?
+ flash[:notice] = (flash[:notice].nil? ? '' : flash[:notice]) + l(:notice_file_revision_created) if ok
+ redirect_back_or_default dmsf_folder_path(id: @project.id, folder_id: @folder)
+ end
+ format.api
+ end
end
def delete
diff --git a/app/views/dmsf_files/create_revision.api.rsb b/app/views/dmsf_files/create_revision.api.rsb
new file mode 100644
index 00000000..bd7e2182
--- /dev/null
+++ b/app/views/dmsf_files/create_revision.api.rsb
@@ -0,0 +1,3 @@
+api.dmsf_file_revision do
+ api.id @file.last_revision&.id
+end
\ No newline at end of file
diff --git a/extra/api/api_client.sh b/extra/api/api_client.sh
index afe6a7ad..43a348b1 100644
--- a/extra/api/api_client.sh
+++ b/extra/api/api_client.sh
@@ -44,10 +44,13 @@
#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 -v -H "Content-Type: application/xml" -X POST --data "@file.xml" -u ${1}:${2} http://localhost:3000/projects/12/dmsf/commit.xml
-# 5. List folder content & check folder existence (by folder title)
+# 5. 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
+
+# 6. 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
-# 6. List folder content & check folder existence (by folder id)
+# 7. 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:
# {
@@ -59,7 +62,7 @@
# }
#}
-# 7. Update a folder
+# 8. 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
@@ -70,17 +73,17 @@
# },
# }
-# 8. Delete a folder
+# 9. Delete a folder
# 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}
# 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"
-# 9. Delete a file
+# 10. Delete a file
# a) Move to trash only
# curl -v -H "Content-Type: application/xml" -X DELETE -u ${1}:${2} http://localhost:3000/dmsf/files/196118.xml
# b) Delete permanently
# curl -v -H "Content-Type: application/xml" -X DELETE -u ${1}:${2} http://localhost:3000/dmsf/files/196118.xml?commit=yes"
-# 10. Create a symbolic link
+# 11. 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/extra/api/revision.xml b/extra/api/revision.xml
new file mode 100644
index 00000000..fd9bcb7d
--- /dev/null
+++ b/extra/api/revision.xml
@@ -0,0 +1,10 @@
+
+
+ test
+ test.sql
+ SQL script
+ REST API
+
+ Validation
+
+
\ 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
index 8d4fefb1..5a3bb3ef 100644
--- a/test/integration/rest_api/dmsf_file_api_test.rb
+++ b/test/integration/rest_api/dmsf_file_api_test.rb
@@ -24,7 +24,7 @@ require File.expand_path('../../../test_helper', __FILE__)
class DmsfFileApiTest < RedmineDmsf::Test::IntegrationTest
include Redmine::I18n
- fixtures :dmsf_files, :dmsf_file_revisions, :dmsf_locks
+ fixtures :dmsf_files, :dmsf_file_revisions, :dmsf_locks, :custom_fields
def setup
super
@@ -200,4 +200,28 @@ class DmsfFileApiTest < RedmineDmsf::Test::IntegrationTest
assert_equal DmsfFile::STATUS_ACTIVE, @file1.deleted
end
+ def test_create_revision
+ # curl -v -H "Content-Type: application/xml" -X POST --data "@revision.xml" -u ${1}:${2} http://localhost:3000/dmfs/files/1/revision/create.xml
+ payload = %{
+
+
+ #{@file1.name}
+ #{@file1.name}
+ SQL script
+ REST API
+
+ User documentation
+
+
+ }
+ post "/dmsf/files/#{@file1.id}/revision/create.xml?key=#{@token.value}", params: payload,
+ headers: { 'CONTENT_TYPE' => 'application/xml' }
+ assert_response :success
+ #
+ #
+ # 293566
+ #
+ assert_select 'dmsf_file_revision > id', text: @file1.last_revision.id.to_s
+ end
+
end
\ No newline at end of file