[#43763] Set default active work package custom fields only if not provided

https://community.openproject.org/work_packages/43763
pull/11462/head
Christophe Bliard 2 years ago committed by Oliver Günther
parent 691587c48d
commit de83aebe82
  1. 6
      app/services/projects/set_attributes_service.rb
  2. 28
      spec/services/projects/copy_service_integration_spec.rb

@ -47,7 +47,7 @@ module Projects
set_default_public(attribute_keys.include?('public'))
set_default_module_names(attribute_keys.include?('enabled_module_names'))
set_default_types(attribute_keys.include?('types') || attribute_keys.include?('type_ids'))
set_default_active_work_package_custom_fields
set_default_active_work_package_custom_fields(attribute_keys.include?('work_package_custom_fields'))
end
def set_default_public(provided)
@ -62,7 +62,9 @@ module Projects
model.types = ::Type.default if !provided && model.types.empty?
end
def set_default_active_work_package_custom_fields
def set_default_active_work_package_custom_fields(provided)
return if provided
model.work_package_custom_fields = WorkPackageCustomField.joins(:types).where(types: { id: model.type_ids })
end

@ -744,6 +744,34 @@ describe Projects::CopyService, 'integration', type: :model do
expect(cv.map(&:formatted_value)).to contain_exactly('A', 'B')
end
end
context 'with disabled work package custom field' do
it 'is still disabled in the copy' do
custom_field = create(:text_wp_custom_field)
create(:type_task,
projects: [source],
custom_fields: [custom_field])
expect(subject).to be_success
expect(source.work_package_custom_fields).to eq([])
expect(project_copy.work_package_custom_fields).to match_array(source.work_package_custom_fields)
end
end
context 'with enabled work package custom field' do
it 'is still enabled in the copy' do
custom_field = create(:text_wp_custom_field, projects: [source])
create(:type_task,
projects: [source],
custom_fields: [custom_field])
expect(subject).to be_success
expect(source.work_package_custom_fields).to eq([custom_field])
expect(project_copy.work_package_custom_fields).to match_array(source.work_package_custom_fields)
end
end
end
end
end

Loading…
Cancel
Save