Improve lookup of versions and work package user assignments

pull/8498/head
Oliver Günther 4 years ago
parent 9c0ed65c55
commit 2523040abf
No known key found for this signature in database
GPG Key ID: A3A8BDAD7C0C552C
  1. 8
      app/services/base_services/copy.rb
  2. 8
      app/services/projects/copy/versions_dependent_service.rb
  3. 28
      app/services/projects/copy/work_packages_dependent_service.rb

@ -51,10 +51,16 @@ module BaseServices
# Return only the unsaved copy
return call if params[:attributes_only]
# Try to save the result or return its errors
copy_instance = call.result
unless copy_instance.save
return ServiceResult.new(success: false, result: copy_instance, errors: copy_instance.errors)
end
copy_dependencies.each do |service_cls|
next if skip_dependency?(params, service_cls)
call.merge! call_dependent_service(service_cls, target: call.result, params: params)
call.merge! call_dependent_service(service_cls, target: copy_instance, params: params)
end
call

@ -33,9 +33,13 @@ module Projects::Copy
protected
def copy_dependency(params:)
source.versions.each do |version|
target.version.create version.attributes.dup.except('id', 'project_id', 'created_on', 'updated_at')
version_id_map = {}
source.versions.each do |source_version|
version = target.versions.create source_version.attributes.dup.except('id', 'project_id', 'created_on', 'updated_at')
version_id_map[source_version.id] = version.id
end
state.version_id_lookup = version_id_map
end
end
end

@ -132,9 +132,9 @@ module Projects::Copy
{
project: target,
parent_id: parent_id,
version: work_package_version(source_work_package),
assigned_to: work_package_assigned_to(source_work_package),
responsible: work_package_responsible(source_work_package),
version_id: work_package_version_id(source_work_package),
assigned_to_id: work_package_assigned_to_id(source_work_package),
responsible_id: work_package_responsible_id(source_work_package),
custom_field_values: custom_value_attributes,
# We fetch the value from the global registry to persist it in the job which
# will trigger a delayed job for potentially sending the journal notifications.
@ -142,16 +142,26 @@ module Projects::Copy
}
end
def work_package_version(source_work_package)
source_work_package.version && target.versions.detect { |v| v.name == source_work_package.version.name }
def work_package_version_id(source_work_package)
return unless source_work_package.version_id
state.version_id_lookup[source_work_package.version_id]
end
def work_package_assigned_to(source_work_package)
source_work_package.assigned_to && target.possible_assignees.detect { |u| u.id == source_work_package.assigned_to_id }
def work_package_assigned_to_id(source_work_package)
assigned_to_id = source_work_package.assigned_to_id
return unless assigned_to_id
@assignees ||= target.possible_assignees.pluck(:id).to_set
assigned_to_id if @assignees.include?(assigned_to_id)
end
def work_package_responsible(source_work_package)
source_work_package.responsible && target.possible_responsibles.detect { |u| u.id == source_work_package.responsible_id }
def work_package_responsible_id(source_work_package)
responsible_id = source_work_package.responsible_id
return unless responsible_id
@responsible ||= target.possible_responsibles.pluck(:id).to_set
responsible_id if @responsible.include?(responsible_id)
end
end
end

Loading…
Cancel
Save