Add an API endpoint 'bcf_xml' accepting POST of a BCF-XML file

pull/7292/head
Wieland Lindenthal 6 years ago
parent a9b8e33c3d
commit e1b3f2c70d
  1. 76
      modules/bcf/lib/api/v3/bcf_xml/bcf_xml_api.rb
  2. 9
      modules/bcf/lib/open_project/bcf/engine.rb

@ -0,0 +1,76 @@
#-- copyright
# OpenProject Documents Plugin
#
# Former OpenProject Core functionality extracted into a plugin.
#
# Copyright (C) 2009-2014 the OpenProject Foundation (OPF)
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License version 3.
#
# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
# Copyright (C) 2006-2013 Jean-Philippe Lang
# Copyright (C) 2010-2013 the ChiliProject Team
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# See doc/COPYRIGHT.rdoc for more details.
#++
module API
module V3
module BcfXml
class BcfXmlAPI < ::API::OpenProjectAPI
resources :projects do
route_param :id do
namespace 'bcf_xml' do
helpers do
# Global helper to set allowed content_types
# This may be overriden when multipart is allowed (file uploads)
def allowed_content_types
if post_request?
%w(application/octet-stream)
else
super
end
end
def post_request?
request.env['REQUEST_METHOD'] == 'POST'
end
end
post do
project = Project.find(params[:id])
authorize(:manage_bcf, context: project) do
raise API::Errors::NotFound.new
end
begin
file = request.body
importer = ::OpenProject::Bcf::BcfXml::Importer.new project, current_user: current_user
importer.import! file
rescue StandardError => e
raise API::Errors::InternalError.new e.message
end
end
end
end
end
end
end
end
end

@ -61,6 +61,15 @@ module OpenProject::Bcf
prepend Patches::Api::V3::ExportFormats prepend Patches::Api::V3::ExportFormats
end end
add_api_path :bcf_xml do |project_id|
"#{project(project_id)}/bcf_xml"
end
add_api_endpoint 'API::V3::Projects::ProjectsAPI' do
content_type :binary, 'application/octet-stream'
mount ::API::V3::BcfXml::BcfXmlAPI
end
initializer 'bcf.register_hooks' do initializer 'bcf.register_hooks' do
# don't use require_dependency to not reload hooks in development mode # don't use require_dependency to not reload hooks in development mode
require 'open_project/xls_export/hooks/work_package_hook.rb' require 'open_project/xls_export/hooks/work_package_hook.rb'

Loading…
Cancel
Save