Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

Fix BCF import by providing a non-ok status

Oliver Günther2ed8382fcfc8
diff --git a/modules/bim/app/controllers/bim/bcf/issues_controller.rb b/modules/bim/app/controllers/bim/bcf/issues_controller.rb
index b9cb9066c73..11949e96083 100644
--- a/modules/bim/app/controllers/bim/bcf/issues_controller.rb
+++ b/modules/bim/app/controllers/bim/bcf/issues_controller.rb
@@ -50,21 +50,21 @@ module Bim
render_next
rescue StandardError => e
flash[:error] = I18n.t("bcf.bcf_xml.import_failed", error: e.message)
- redirect_to action: :upload
+ upload_error_redirect
end
def configure_import
render_next
rescue StandardError => e
flash[:error] = I18n.t("bcf.bcf_xml.import_failed", error: e.message)
- redirect_to action: :upload
+ upload_error_redirect
end
def perform_import
import_file
rescue StandardError => e
flash[:error] = I18n.t("bcf.bcf_xml.import_failed", error: e.message)
- redirect_to action: :upload
+ upload_error_redirect
ensure
@bcf_attachment&.destroy
end
@@ -75,6 +75,10 @@ module Bim
private
+ def upload_error_redirect
+ redirect_to action: :upload, status: :unprocessable_entity
+ end
+
def import_file
set_import_options
@@ -117,6 +121,8 @@ module Bim
end
def render_next
+ response.status = :unprocessable_entity
+
if render_config_unknown_types?
render_config_unknown_types
elsif render_config_unknown_statuses?
@@ -194,7 +200,7 @@ module Bim
@bcf_xml_file = File.new @bcf_attachment.local_path
rescue ActiveRecord::RecordNotFound
flash[:error] = I18n.t("bcf.bcf_xml.import.bcf_file_not_found")
- redirect_to action: :upload
+ upload_error_redirect
end
def persist_file
@@ -203,7 +209,7 @@ module Bim
session[:bcf_file_id] = @bcf_attachment.id
rescue StandardError => e
flash[:error] = "Failed to persist BCF file: #{e.message}"
- redirect_to action: :upload
+ upload_error_redirect
end
def create_attachment
@@ -223,7 +229,7 @@ module Bim
path = params[:bcf_file]&.path
unless path && File.readable?(path)
flash[:error] = I18n.t("bcf.bcf_xml.import_failed", error: "File missing or not readable")
- redirect_to action: :upload
+ upload_error_redirect
end
end
@@ -232,7 +238,7 @@ module Bim
flash[:error] =
I18n.t("bcf.bcf_xml.import_failed_unsupported_bcf_version",
minimal_version: OpenProject::Bim::BcfXml::Importer::MINIMUM_BCF_VERSION)
- redirect_to action: :upload
+ upload_error_redirect
end
end
end