Merge pull request #622 from kacerr/devel-1.5.9

API extension: allow calling save action from api, extend show action so that it can be used to confirm folder existence
This commit is contained in:
Karel Picman 2016-12-12 08:21:43 +01:00 committed by GitHub
commit a1bba8e817
4 changed files with 83 additions and 7 deletions

View File

@ -29,7 +29,9 @@ class DmsfController < ApplicationController
before_filter :find_parent, :only => [:new, :create]
before_filter :tree_view, :only => [:delete, :show]
accept_api_auth :show, :create
accept_api_auth :show, :create, :save
skip_before_action :verify_authenticity_token, if: -> { request.headers["HTTP_X_REDMINE_API_KEY"].present? }
helper :all
@ -44,6 +46,8 @@ class DmsfController < ApplicationController
end
def show
# 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?
render_404
@ -180,6 +184,8 @@ class DmsfController < ApplicationController
saved = @folder.save
respond_to do |format|
format.js
format.api {
@ -223,11 +229,21 @@ class DmsfController < ApplicationController
end
end
if @folder.save
flash[:notice] = l(:notice_folder_details_were_saved)
redirect_to dmsf_folder_path(:id => @project, :folder_id => @folder)
else
render :action => 'edit'
saved = @folder.save
respond_to do |format|
format.api {
unless saved
render_validation_errors(@folder)
end
}
format.html {
if saved
flash[:notice] = l(:notice_folder_details_were_saved)
redirect_to dmsf_folder_path(:id => @project, :folder_id => @folder)
else
render :action => 'edit'
end
}
end
end
@ -538,6 +554,15 @@ class DmsfController < ApplicationController
render_404
end
def find_folder_by_title
# find by title has to be scoped to project
@folder = DmsfFolder.find_by(title: params[:folder_title], project_id: params[:id]) if params[:folder_title].present?
rescue DmsfAccessError
render_403
rescue ActiveRecord::RecordNotFound
render_404
end
def find_parent
@parent = DmsfFolder.visible.find params[:parent_id] if params[:parent_id].present?
rescue DmsfAccessError
@ -667,3 +692,4 @@ class DmsfController < ApplicationController
end
end

View File

@ -0,0 +1,5 @@
api.dmsf_folder do
api.id @folder.id
api.title @folder.title
api.description @folder.description
end

View File

@ -29,4 +29,12 @@ api.dmsf do
end
end
end
if @folder
api.found_folder do
api.id @folder.id
api.title @folder.title
end
end
end

View File

@ -40,4 +40,41 @@ curl -v -H "Content-Type: application/xml" -X GET -u ${1}:${2} http://localhost:
# 4. 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 -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 ${1}:${2} http://localhost:3000/projects/12/dmsf/commit.xml
# 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:
# {
# "dmsf":{
# "dmsf_folders":[
#
# ],
# "total_count":0,
# "dmsf_files":[
#
# ],
# "dmsf_links":[
#
# ],
# "found_folder":{
# "id":3,
# "title":"Updated title"
# }
# }
#}
# 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
# update-folder-payload.json
# {
# "dmsf_folder": {
# "title": title,
# "description": description
# },
# "folder_id": id -- id of folder to be updated
# }