forgive missing assignee if so specified

pull/7893/head
ulferts 5 years ago
parent a344d35e90
commit e358e5d1fc
No known key found for this signature in database
GPG Key ID: A205708DE1284017
  1. 26
      modules/bcf/app/services/bcf/issues/transform_attributes_service.rb
  2. 4
      modules/bcf/lib/open_project/bcf/bcf_xml/issue_reader.rb
  3. 2
      modules/bcf/spec/bcf/bcf_xml/importer_spec.rb

@ -56,9 +56,7 @@ module Bcf::Issues
return assignee if assignee.present? return assignee if assignee.present?
if attributes[:assignee] missing_assignee(attributes[:assignee], attributes[:import_options] || {})
User::InexistentUser.new
end
end end
## ##
@ -67,13 +65,13 @@ module Bcf::Issues
project.users.find_by(mail: mail) project.users.find_by(mail: mail)
end end
def type(attributes) def type(project, attributes)
type_name = attributes[:type] type_name = attributes[:type]
type = ::Type.find_by(name: type_name) type = project.types.find_by(name: type_name)
return type if type.present? return type if type.present?
missing_type(type_name, attributes[:import_options] || {}) missing_type(project, type_name, attributes[:import_options] || {})
end end
## ##
@ -107,7 +105,7 @@ module Bcf::Issues
{ {
# Fixed attributes we know # Fixed attributes we know
project: project, project: project,
type: type(attributes), type: type(project, attributes),
# Native attributes from the extractor # Native attributes from the extractor
subject: title(attributes), subject: title(attributes),
@ -144,15 +142,21 @@ module Bcf::Issues
end end
end end
def missing_type(type_name, import_options) def missing_type(project, type_name, import_options)
if import_options[:unknown_types_action] == 'default' if import_options[:unknown_types_action] == 'use_default'
::Type.default&.first project.types.default&.first
elsif import_options[:unknown_types_action] == 'chose' && elsif import_options[:unknown_types_action] == 'chose' &&
import_options[:unknown_types_chose_ids].any? import_options[:unknown_types_chose_ids].any?
::Type.find_by(id: import_options[:unknown_types_chose_ids].first) project.types.find_by(id: import_options[:unknown_types_chose_ids].first)
elsif type_name elsif type_name
Type::InexistentType.new Type::InexistentType.new
end end
end end
def missing_assignee(assignee_name, import_options)
if import_options[:invalid_people_action] != 'anonymize' && assignee_name
User::InexistentUser.new
end
end
end end
end end

@ -93,9 +93,9 @@ module OpenProject::Bcf::BcfXml
def work_package_attributes def work_package_attributes
attributes = ::Bcf::Issues::TransformAttributesService attributes = ::Bcf::Issues::TransformAttributesService
.new .new
.call(extractor_attributes) .call(extractor_attributes.merge(import_options: import_options))
.result .result
.merge(send_notifications: false, import_options: import_options) .merge(send_notifications: false)
.symbolize_keys .symbolize_keys
attributes[:start_date] = extractor.creation_date.to_date unless is_update attributes[:start_date] = extractor.creation_date.to_date unless is_update

@ -63,7 +63,7 @@ describe ::OpenProject::Bcf::BcfXml::Importer do
workflow workflow
priority priority
bcf_manager_member bcf_manager_member
allow(User).to receive(:current).and_return(bcf_manager) login_as(bcf_manager)
end end
describe '#to_listing' do describe '#to_listing' do

Loading…
Cancel
Save