diff --git a/app/controllers/dmsf_controller.rb b/app/controllers/dmsf_controller.rb index 106118ab..6833877a 100644 --- a/app/controllers/dmsf_controller.rb +++ b/app/controllers/dmsf_controller.rb @@ -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 + diff --git a/app/views/dmsf/save.api.rsb b/app/views/dmsf/save.api.rsb new file mode 100644 index 00000000..7af62e91 --- /dev/null +++ b/app/views/dmsf/save.api.rsb @@ -0,0 +1,5 @@ +api.dmsf_folder do + api.id @folder.id + api.title @folder.title + api.description @folder.description +end diff --git a/app/views/dmsf/show.api.rsb b/app/views/dmsf/show.api.rsb index 542a39f4..8d0ef0e0 100644 --- a/app/views/dmsf/show.api.rsb +++ b/app/views/dmsf/show.api.rsb @@ -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 \ No newline at end of file diff --git a/extra/api/api_client.sh b/extra/api/api_client.sh index bb7a112b..772414c2 100644 --- a/extra/api/api_client.sh +++ b/extra/api/api_client.sh @@ -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 \ No newline at end of file +#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 +# } \ No newline at end of file