Ensure the importer executes under the given user (#9713)

Since the attachment services now depend on a user for authorization, but the viewpoint

snapshot is assigned explictily through snapshot.viewpoint=, there is no way to pass the

current_user explicitly.

Instead, log in the given user for the course of the import process
pull/9715/head
Oliver Günther 3 years ago committed by GitHub
parent 70de3cd615
commit b33d4e78ad
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      modules/bim/app/seeders/bim/demo_data/bcf_xml_seeder.rb
  2. 38
      modules/bim/lib/open_project/bim/bcf_xml/importer.rb
  3. 1
      modules/bim/spec/bcf/bcf_xml/importer_spec.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'

@ -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)

@ -73,7 +73,6 @@ describe ::OpenProject::Bim::BcfXml::Importer do
workflow
priority
bcf_manager_member
login_as(bcf_manager)
end
describe '#to_listing' do

Loading…
Cancel
Save