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

Remove final import screen and fix some of the errors

Oliver Günther4a5bcc9e0e87
diff --git a/modules/bim/app/controllers/bim/bcf/issues_controller.rb b/modules/bim/app/controllers/bim/bcf/issues_controller.rb
index 2e88752adaf..e639cb0ac3e 100644
--- a/modules/bim/app/controllers/bim/bcf/issues_controller.rb
+++ b/modules/bim/app/controllers/bim/bcf/issues_controller.rb
@@ -38,11 +38,11 @@ module Bim
before_action :import_canceled?
before_action :check_file_param, only: %i[prepare_import]
- before_action :get_persisted_file, only: %i[perform_import configure_import]
+ before_action :get_persisted_file, only: %i[perform_import]
before_action :persist_file, only: %i[prepare_import]
before_action :set_import_options, only: %i[perform_import]
- before_action :build_importer, only: %i[prepare_import configure_import perform_import]
+ before_action :build_importer, only: %i[prepare_import perform_import]
menu_item :work_packages
@@ -60,29 +60,21 @@ module Bim
redirect_to action: :upload
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
- end
-
def perform_import
- begin
- results = @importer.import!(@import_options).flatten
- @issues = {successful: [], failed: []}
- results.each do |issue|
- if issue.errors.present?
- @issues[:failed] << issue
- else
- @issues[:successful] << issue
- end
+ results = @importer.import!(@import_options).flatten
+ @issues = { successful: [], failed: [] }
+ results.each do |issue|
+ if issue.errors.present?
+ @issues[:failed] << issue
+ else
+ @issues[:successful] << issue
end
- rescue StandardError => e
- flash[:error] = I18n.t('bcf.bcf_xml.import_failed', error: e.message)
end
-
- @bcf_attachment.destroy
+ rescue StandardError => e
+ flash[:error] = I18n.t('bcf.bcf_xml.import_failed', error: e.message)
+ redirect_to action: :upload
+ ensure
+ @bcf_attachment&.destroy
end
def redirect_to_bcf_issues_list
@@ -132,22 +124,10 @@ module Bim
elsif render_config_non_members?
render_config_non_members
else
- render_diff_on_work_packages
+ perform_import
end
end
- def render_diff_on_work_packages
- @listing = @importer.extractor_list
- if @listing.blank?
- raise(StandardError.new(I18n.t('bcf.exceptions.file_invalid')))
- end
-
- @issues = ::Bim::Bcf::Issue
- .includes(work_package: %i[status priority assigned_to])
- .where(uuid: @listing.map { |e| e[:uuid] }, project: @project)
- render 'bim/bcf/issues/diff_on_work_packages'
- end
-
def render_config_invalid_people
render 'bim/bcf/issues/configure_invalid_people'
end
@@ -206,7 +186,8 @@ module Bim
@bcf_attachment = Attachment.find_by! id: session[:bcf_file_id], author: current_user
@bcf_xml_file = File.new @bcf_attachment.local_path
rescue ActiveRecord::RecordNotFound
- render_404 'BCF file not found'
+ flash[:error] = I18n.t('bcf.bcf_xml.import.bcf_file_not_found')
+ redirect_to action: :upload
end
def persist_file
diff --git a/modules/bim/app/views/bim/bcf/issues/_import_solution.html.erb b/modules/bim/app/views/bim/bcf/issues/_import_solution.html.erb
index a9c1d3d2c77..913d07c6a1f 100644
--- a/modules/bim/app/views/bim/bcf/issues/_import_solution.html.erb
+++ b/modules/bim/app/views/bim/bcf/issues/_import_solution.html.erb
@@ -15,7 +15,7 @@
</div>
<%= styled_submit_tag t('bcf.bcf_xml.import.button_proceed'), class: '-highlight' %>
+
<%= link_to t(:button_cancel),
- project_work_packages_path(@project),
+ defaults_bcf_project_ifc_models_path(@project),
class: 'button' %>
-
diff --git a/modules/bim/app/views/bim/bcf/issues/_render_issues.html.erb b/modules/bim/app/views/bim/bcf/issues/_render_issues.html.erb
index 02eae392eb8..0a593c6d9f9 100644
--- a/modules/bim/app/views/bim/bcf/issues/_render_issues.html.erb
+++ b/modules/bim/app/views/bim/bcf/issues/_render_issues.html.erb
@@ -15,9 +15,8 @@
<% if issue.errors.present? %>
<div class="notification-box -error">
<div class="notification-box--content">
- <ul>
- <% issue.errors.each do |attribute, message| %>
- <li><%= attribute %>: <%= message %></li>
+ <% issue.errors.full_messages.each do |message| %>
+ <p><%= message %></p>
<% end %>
</ul>
</div>
diff --git a/modules/bim/app/views/bim/bcf/issues/configure_invalid_people.html.erb b/modules/bim/app/views/bim/bcf/issues/configure_invalid_people.html.erb
index aa62b9cb9b5..565b611a505 100644
--- a/modules/bim/app/views/bim/bcf/issues/configure_invalid_people.html.erb
+++ b/modules/bim/app/views/bim/bcf/issues/configure_invalid_people.html.erb
@@ -1,7 +1,7 @@
<%= stylesheet_link_tag 'bim/bcf.css' %>
<%= toolbar title: t('bcf.bcf_xml.import_title') %>
-<%= styled_form_tag({ action: :configure_import }, multipart: true, method: :post) do %>
+<%= styled_form_tag({ action: :perform_import }, multipart: true, method: :post) do %>
<%= render partial: 'import_errors', locals: { error_message: t('bcf.bcf_xml.import.invalid_emails_found'),
error_objects: @importer.aggregations.invalid_people,
error_default_text: t('bcf.bcf_xml.import.unknown_property')} %>
@@ -14,7 +14,7 @@
<%= styled_submit_tag t('bcf.bcf_xml.import.button_proceed'), class: '-highlight' %>
<%= link_to t(:button_cancel),
- project_work_packages_path(@project),
+ defaults_bcf_project_ifc_models_path(@project),
class: 'button' %>
<% end %>
diff --git a/modules/bim/app/views/bim/bcf/issues/configure_non_members.html.erb b/modules/bim/app/views/bim/bcf/issues/configure_non_members.html.erb
index 74676fa9bfb..7af1f6da245 100644
--- a/modules/bim/app/views/bim/bcf/issues/configure_non_members.html.erb
+++ b/modules/bim/app/views/bim/bcf/issues/configure_non_members.html.erb
@@ -1,7 +1,7 @@
<%= stylesheet_link_tag 'bim/bcf.css' %>
<%= toolbar title: t('bcf.bcf_xml.import_title') %>
-<%= styled_form_tag({ action: :configure_import }, multipart: true, method: :post) do %>
+<%= styled_form_tag({ action: :perform_import }, multipart: true, method: :post) do %>
<%= render partial: 'import_errors', locals: { error_message: t('bcf.bcf_xml.import.non_members_found'),
error_objects: @importer.aggregations.non_members,
error_default_text: t('bcf.bcf_xml.import.unknown_property')} %>
@@ -32,7 +32,7 @@
</div>
<br/>
<%= link_to t(:button_cancel),
- project_work_packages_path(@project),
+ defaults_bcf_project_ifc_models_path(@project),
class: 'button' %>
<% end %>
<% end %>
diff --git a/modules/bim/app/views/bim/bcf/issues/configure_unknown_mails.html.erb b/modules/bim/app/views/bim/bcf/issues/configure_unknown_mails.html.erb
index 22c537496f5..80fce04fd6f 100644
--- a/modules/bim/app/views/bim/bcf/issues/configure_unknown_mails.html.erb
+++ b/modules/bim/app/views/bim/bcf/issues/configure_unknown_mails.html.erb
@@ -1,7 +1,7 @@
<%= stylesheet_link_tag 'bim/bcf.css' %>
<%= toolbar title: t('bcf.bcf_xml.import_title') %>
-<%= styled_form_tag({ action: :configure_import }, multipart: true, method: :post) do %>
+<%= styled_form_tag({ action: :perform_import }, multipart: true, method: :post) do %>
<%= render partial: 'import_errors', locals: { error_message: t('bcf.bcf_xml.import.unknown_emails_found'),
error_objects: @importer.aggregations.unknown_mails,
error_default_text: t('bcf.bcf_xml.import.unknown_property')} %>
@@ -57,7 +57,7 @@
<br/>
<% end %>
<%= link_to t(:button_cancel),
- project_work_packages_path(@project),
+ defaults_bcf_project_ifc_models_path(@project),
class: 'button' %>
<% end %>
diff --git a/modules/bim/app/views/bim/bcf/issues/configure_unknown_priorities.html.erb b/modules/bim/app/views/bim/bcf/issues/configure_unknown_priorities.html.erb
index 85563dfa65e..a3199416c06 100644
--- a/modules/bim/app/views/bim/bcf/issues/configure_unknown_priorities.html.erb
+++ b/modules/bim/app/views/bim/bcf/issues/configure_unknown_priorities.html.erb
@@ -1,7 +1,7 @@
<%= stylesheet_link_tag 'bim/bcf.css' %>
<%= toolbar title: t('bcf.bcf_xml.import_title') %>
-<%= styled_form_tag({ action: :configure_import }, multipart: true, method: :post, class: '-vertical') do %>
+<%= styled_form_tag({ action: :perform_import }, multipart: true, method: :post, class: '-vertical') do %>
<%= render partial: 'import_errors', locals: { error_message: t('bcf.bcf_xml.import.invalid_priorities_found'),
error_objects: @importer.aggregations.unknown_priorities,
error_default_text: t('bcf.bcf_xml.import.no_priority_provided')} %>
diff --git a/modules/bim/app/views/bim/bcf/issues/configure_unknown_statuses.html.erb b/modules/bim/app/views/bim/bcf/issues/configure_unknown_statuses.html.erb
index 902832f52f9..1b6541abb56 100644
--- a/modules/bim/app/views/bim/bcf/issues/configure_unknown_statuses.html.erb
+++ b/modules/bim/app/views/bim/bcf/issues/configure_unknown_statuses.html.erb
@@ -1,7 +1,7 @@
<%= stylesheet_link_tag 'bim/bcf.css' %>
<%= toolbar title: t('bcf.bcf_xml.import_title') %>
-<%= styled_form_tag({ action: :configure_import }, multipart: true, method: :post, class: '-vertical') do %>
+<%= styled_form_tag({ action: :perform_import }, multipart: true, method: :post, class: '-vertical') do %>
<%= render partial: 'import_errors', locals: { error_message: t('bcf.bcf_xml.import.invalid_statuses_found'),
error_objects: @importer.aggregations.unknown_statuses,
error_default_text: t('bcf.bcf_xml.import.no_status_provided')} %>
diff --git a/modules/bim/app/views/bim/bcf/issues/configure_unknown_types.html.erb b/modules/bim/app/views/bim/bcf/issues/configure_unknown_types.html.erb
index 01e148b8a02..75a0fb81a32 100644
--- a/modules/bim/app/views/bim/bcf/issues/configure_unknown_types.html.erb
+++ b/modules/bim/app/views/bim/bcf/issues/configure_unknown_types.html.erb
@@ -1,7 +1,7 @@
<%= stylesheet_link_tag 'bim/bcf.css' %>
<%= toolbar title: t('bcf.bcf_xml.import_title') %>
-<%= styled_form_tag({ action: :configure_import }, multipart: true, method: :post, class: '-vertical') do %>
+<%= styled_form_tag({ action: :perform_import }, multipart: true, method: :post, class: '-vertical') do %>
<%= render partial: 'import_errors', locals: { error_message: t('bcf.bcf_xml.import.invalid_types_found'),
error_objects: @importer.aggregations.unknown_types,
error_default_text: t('bcf.bcf_xml.import.no_type_provided')} %>
diff --git a/modules/bim/app/views/bim/bcf/issues/diff_on_work_packages.html.erb b/modules/bim/app/views/bim/bcf/issues/diff_on_work_packages.html.erb
deleted file mode 100644
index 57eb7b58751..00000000000
--- a/modules/bim/app/views/bim/bcf/issues/diff_on_work_packages.html.erb
+++ /dev/null
@@ -1,71 +0,0 @@
-<%= stylesheet_link_tag 'bim/bcf.css' %>
-<%= toolbar title: t('bcf.bcf_xml.import_title') %>
-
-<p><%= t('bcf.bcf_xml.import.num_issues_found', x_bcf_issues: t('bcf.x_bcf_issues', count: @listing.count)) %></p>
-<%= form_tag({ action: :perform_import }, multipart: true, method: :post) do %>
- <%= render 'import_options_hidden_fields' %>
-
- <% @listing.each do |entry| %>
-
- <% issue = @issues.detect { |bcf| bcf.uuid == entry[:uuid] } %>
- <div class="bcf--import-listing">
-
- <h3><%= entry[:title] %></h3>
- <table class="attributes-table">
- <thead>
- <tr>
- <th></th>
- <th>Work package</th>
- <th>Title</th>
- <th>Status</th>
- <th>Priority</th>
- <th>Author</th>
- <th>Assignee</th>
- <th>Due date</th>
- <th># Viewpoints</th>
- <th># Comments</th>
- </tr>
- </thead>
- <tbody>
- <tr>
- <td><b>About to import</b></td>
- <% if issue && issue.work_package %>
- <td></td>
- <% else %>
- <td>(Will create work package)</td>
- <% end %>
- <td><%= entry[:title] || '-' %></td>
- <td><%= entry[:status] || '-' %></td>
- <td><%= entry[:priority] || '-' %></td>
- <td><%= entry[:author] || '-' %></td>
- <td><%= entry[:assignee] || '-' %></td>
- <td><%= format_date(entry[:due_date]) || '-' %></td>
- <td><%= entry[:viewpoint_count] %></td>
- <td><%= entry[:comments_count] %></td>
- </tr>
- <% if issue&.work_package %>
- <tr>
- <td><b>Work package state before import</b></td>
- <td><%= link_to_work_package issue.work_package %></td>
- <td><%= issue.work_package.subject %></td>
- <td><%= issue.work_package.status.name %></td>
- <td><%= issue.work_package.priority.name %></td>
- <td><%= issue.work_package.author&.name %></td>
- <td><%= issue.work_package.assigned_to&.name %></td>
- <td><%= format_date(issue.work_package.due_date) %></td>
- <td><%= issue.viewpoints.count %></td>
- <td><%= issue.comments.count %></td>
- </tr>
- <% end %>
- </tbody>
- </table>
- </div>
- <% end %>
-
- <p><%= t('bcf.bcf_xml.import.perform_description') %></p>
- <%= submit_tag t('bcf.bcf_xml.import.button_perform_import'), class: 'button -highlight' %>
- <%= link_to t(:button_cancel),
- defaults_bcf_project_ifc_models_path(@project),
- class: 'button' %>
-<% end %>
-
diff --git a/modules/bim/config/locales/en.yml b/modules/bim/config/locales/en.yml
index 04282722cb0..677d762a76c 100644
--- a/modules/bim/config/locales/en.yml
+++ b/modules/bim/config/locales/en.yml
@@ -33,7 +33,7 @@ en:
num_issues_found: '%{x_bcf_issues} are contained in the BCF-XML file, their details are listed below.'
button_prepare: 'Prepare import'
button_perform_import: 'Confirm import'
- button_proceed: 'Proceed'
+ button_proceed: 'Proceed with import'
button_back_to_list: 'Back to list'
no_permission_to_add_members: 'You do not have sufficient permissions to add them as members to the project.'
contact_project_admin: 'Contact your project admin to add them as members and start this import again.'
@@ -59,6 +59,7 @@ en:
import_as_system_user: 'Import them as "System" user.'
what_to_do: "What do you want to do?"
work_package_has_newer_changes: "Outdated! This topic was not updated as the latest changes on the server were newer than the \"ModifiedDate\" of the imported topic. However, comments to the topic were imported."
+ bcf_file_not_found: "Failed to locate BCF file. Please start the upload process again."
export:
format:
diff --git a/modules/bim/config/routes.rb b/modules/bim/config/routes.rb
index edfeb499781..e8a3f8c7baa 100644
--- a/modules/bim/config/routes.rb
+++ b/modules/bim/config/routes.rb
@@ -34,7 +34,6 @@ OpenProject::Application.routes.draw do
resources :issues, controller: 'bim/bcf/issues' do
get :upload, action: :upload, on: :collection
post :prepare_import, action: :prepare_import, on: :collection
- post :configure_import, action: :configure_import, on: :collection
post :import, action: :perform_import, on: :collection
end
diff --git a/modules/bim/lib/open_project/bim/bcf_xml/issue_reader.rb b/modules/bim/lib/open_project/bim/bcf_xml/issue_reader.rb
index 2997a27082e..ff28e0cd593 100644
--- a/modules/bim/lib/open_project/bim/bcf_xml/issue_reader.rb
+++ b/modules/bim/lib/open_project/bim/bcf_xml/issue_reader.rb
@@ -298,13 +298,13 @@ module OpenProject::Bim::BcfXml
end
def import_is_outdated(issue)
- issue.errors.add :base,
- :conflict,
- message: I18n.t('bcf.bcf_xml.import.work_package_has_newer_changes',
- bcf_uuid: issue.uuid)
- ServiceResult.new success: false,
- errors: issue.errors,
- result: issue
+ errors = ActiveModel::Errors.new(issue)
+ errors.add :base,
+ :conflict,
+ message: I18n.t('bcf.bcf_xml.import.work_package_has_newer_changes',
+ bcf_uuid: issue.uuid)
+
+ ServiceResult.new(success: false, errors: errors)
end
end
end
diff --git a/modules/bim/lib/open_project/bim/engine.rb b/modules/bim/lib/open_project/bim/engine.rb
index c5d219e7eab..911dcbf1c38 100644
--- a/modules/bim/lib/open_project/bim/engine.rb
+++ b/modules/bim/lib/open_project/bim/engine.rb
@@ -57,7 +57,7 @@ module OpenProject::Bim
{'bim/bcf/issues': %i[index]},
dependencies: %i[view_work_packages]
permission :manage_bcf,
- {'bim/bcf/issues': %i[index upload prepare_import configure_import perform_import]},
+ {'bim/bcf/issues': %i[index upload prepare_import perform_import]},
dependencies: %i[view_linked_issues
view_work_packages
add_work_packages
diff --git a/modules/bim/spec/controllers/issues_controller_spec.rb b/modules/bim/spec/controllers/issues_controller_spec.rb
index def5fb25292..b5425bda288 100644
--- a/modules/bim/spec/controllers/issues_controller_spec.rb
+++ b/modules/bim/spec/controllers/issues_controller_spec.rb
@@ -125,34 +125,6 @@ describe ::Bim::Bcf::IssuesController, type: :controller do
end
end
- describe '#configure_import' do
- let(:action) do
- post :configure_import, params: { project_id: project.identifier.to_s }
- end
-
- context 'with valid BCF file' do
- let(:filename) { 'MaximumInformation.bcf' }
- let(:file) do
- Rack::Test::UploadedFile.new(
- File.join(Rails.root, "modules/bim/spec/fixtures/files/#{filename}"),
- 'application/octet-stream'
- )
- end
-
- before do
- allow_any_instance_of(Attachment).to receive(:diskfile).and_return(file)
- allow(Attachment).to receive(:find_by).and_return(Attachment.new)
- end
-
- it 'should be successful' do
- expect { action }.to change { Attachment.count }.by(0)
- expect(response).to be_successful
- end
-
- it_behaves_like "check permissions"
- end
- end
-
describe '#perform_import' do
let(:action) do
post :perform_import, params: { project_id: project.identifier.to_s }