Skip to content

Commit

Permalink
Merge pull request #14210 from opf/bug/51173-regression-custom-fields…
Browse files Browse the repository at this point in the history
…-no-longer-appear-in-pdf

[#51173] Regression: most of the custom fields no longer appear in PDF
  • Loading branch information
oliverguenther authored Nov 23, 2023
2 parents 8c0af70 + dbad0ec commit dc92729
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
2 changes: 1 addition & 1 deletion app/models/work_package/pdf_export/work_package_detail.rb
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ def form_key_to_column_entries(form_key, work_package)
cf = CustomField.find_by(id:)
return [] if cf.nil? || cf.formattable?

return [] if work_package.project.work_package_custom_field_ids.exclude?(cf.id)
return [] unless cf.is_for_all? || work_package.project.work_package_custom_field_ids.include?(cf.id)

return [{ label: cf.name || form_key, name: form_key }]
end
Expand Down
25 changes: 17 additions & 8 deletions spec/models/work_packages/pdf_export/work_package_to_pdf_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,16 @@
include Redmine::I18n
include PDFExportSpecUtils
let(:type) do
create(:type_bug, custom_fields: [long_text_custom_field, disabled_custom_field]).tap do |t|
t.attribute_groups.first.attributes.push(disabled_custom_field.attribute_name, long_text_custom_field.attribute_name)
create(:type_bug, custom_fields: [cf_long_text, cf_disabled_in_project, cf_global_bool]).tap do |t|
t.attribute_groups.first.attributes.push(cf_disabled_in_project.attribute_name, cf_long_text.attribute_name)
end
end
let(:project) do
create(:project,
name: 'Foo Bla. Report No. 4/2021 with/for Case 42',
types: [type],
work_package_custom_fields: [long_text_custom_field, disabled_custom_field],
work_package_custom_field_ids: [long_text_custom_field.id]) # disabled_custom_field.id is disabled
work_package_custom_fields: [cf_long_text, cf_disabled_in_project, cf_global_bool],
work_package_custom_field_ids: [cf_long_text.id, cf_global_bool.id]) # cf_disabled_in_project.id is disabled
end
let(:user) do
create(:user,
Expand All @@ -52,11 +52,19 @@
let(:image_path) { Rails.root.join("spec/fixtures/files/image.png") }
let(:image_attachment) { Attachment.new author: user, file: File.open(image_path) }
let(:attachments) { [image_attachment] }
let(:long_text_custom_field) { create(:issue_custom_field, :text, name: 'LongText') }
let!(:disabled_custom_field) do
let(:cf_long_text) { create(:issue_custom_field, :text, name: 'LongText') }
let!(:cf_disabled_in_project) do
# NOT enabled by project.work_package_custom_field_ids => NOT in PDF
create(:float_wp_custom_field, name: 'DisabledCustomField')
end
let(:cf_global_bool) do
create(
:work_package_custom_field,
field_format: 'bool',
is_for_all: true,
default_value: true
)
end
let(:work_package) do
description = <<~DESCRIPTION
**Lorem** _ipsum_ ~~dolor~~ `sit` [amet](https://example.com/), consetetur sadipscing elitr.
Expand All @@ -79,8 +87,9 @@
story_points: 1,
description:,
custom_values: {
long_text_custom_field.id => 'foo',
disabled_custom_field.id => '6.25'
cf_long_text.id => 'foo',
cf_disabled_in_project.id => '6.25',
cf_global_bool.id => true
}).tap do |wp|
allow(wp)
.to receive(:attachments)
Expand Down

0 comments on commit dc92729

Please sign in to comment.