diff --git a/modules/bim/app/seeders/bim/demo_data/bcf_xml_seeder.rb b/modules/bim/app/seeders/bim/demo_data/bcf_xml_seeder.rb index 3314dbef12..9bd2ed93bf 100644 --- a/modules/bim/app/seeders/bim/demo_data/bcf_xml_seeder.rb +++ b/modules/bim/app/seeders/bim/demo_data/bcf_xml_seeder.rb @@ -41,7 +41,7 @@ module Bim filename = project_data_for(key, 'bcf_xml_file') return unless filename.present? - user = User.admin.first + user = User.admin.active.first print_status ' ↳ Import BCF XML file' diff --git a/modules/bim/lib/open_project/bim/bcf_xml/importer.rb b/modules/bim/lib/open_project/bim/bcf_xml/importer.rb index 05d1ebca38..c2fb153c53 100644 --- a/modules/bim/lib/open_project/bim/bcf_xml/importer.rb +++ b/modules/bim/lib/open_project/bim/bcf_xml/importer.rb @@ -39,11 +39,32 @@ module OpenProject::Bim::BcfXml end end + def import!(options = {}) + User.execute_as(current_user) do + perform_import(options) + end + end + def aggregations @aggregations ||= Aggregations.new(extractor_list, @project) end - def import!(options = {}) + def bcf_version_valid? + Zip::File.open(@file) do |zip| + zip_entry = zip.find { |entry| entry.name.end_with?('bcf.version') } + markup = zip_entry.get_input_stream.read + doc = Nokogiri::XML(markup, nil, 'UTF-8') + bcf_version = doc.xpath('/Version').first['VersionId'] + return Gem::Version.new(bcf_version) >= Gem::Version.new(MINIMUM_BCF_VERSION) + end + rescue StandardError => e + # The uploaded file could be anything. + false + end + + private + + def perform_import(options) options = DEFAULT_IMPORT_OPTIONS.merge(options) Zip::File.open(@file) do |zip| create_or_add_missing_members(options) @@ -61,21 +82,6 @@ module OpenProject::Bim::BcfXml raise end - def bcf_version_valid? - Zip::File.open(@file) do |zip| - zip_entry = zip.find { |entry| entry.name.end_with?('bcf.version') } - markup = zip_entry.get_input_stream.read - doc = Nokogiri::XML(markup, nil, 'UTF-8') - bcf_version = doc.xpath('/Version').first['VersionId'] - return Gem::Version.new(bcf_version) >= Gem::Version.new(MINIMUM_BCF_VERSION) - end - rescue StandardError => e - # The uploaded file could be anything. - false - end - - private - def create_or_add_missing_members(options) treat_invalid_people(options) treat_unknown_mails(options) diff --git a/modules/bim/spec/bcf/bcf_xml/importer_spec.rb b/modules/bim/spec/bcf/bcf_xml/importer_spec.rb index 8bab6134a7..172df8610d 100644 --- a/modules/bim/spec/bcf/bcf_xml/importer_spec.rb +++ b/modules/bim/spec/bcf/bcf_xml/importer_spec.rb @@ -73,7 +73,6 @@ describe ::OpenProject::Bim::BcfXml::Importer do workflow priority bcf_manager_member - login_as(bcf_manager) end describe '#to_listing' do