OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
[#50896] Disabled custom field (on a project level) is still appearing in PDF file
as-opa686ae1dc9e4
diff --git a/app/models/work_package/pdf_export/work_package_detail.rb b/app/models/work_package/pdf_export/work_package_detail.rbindex 8938ed3f468..412989d8deb 100644--- a/app/models/work_package/pdf_export/work_package_detail.rb+++ b/app/models/work_package/pdf_export/work_package_detail.rb@@ -141,6 +141,8 @@ module WorkPackage::PDFExport::WorkPackageDetailcf = CustomField.find_by(id:)return [] if cf.nil? || cf.formattable?+ return [] if work_package.project.work_package_custom_field_ids.exclude?(cf.id)+return [{ label: cf.name || form_key, name: form_key }]enddiff --git a/spec/models/work_packages/pdf_export/work_package_to_pdf_spec.rb b/spec/models/work_packages/pdf_export/work_package_to_pdf_spec.rbindex 380ff7d8fe4..63c53d7d538 100644--- a/spec/models/work_packages/pdf_export/work_package_to_pdf_spec.rb+++ b/spec/models/work_packages/pdf_export/work_package_to_pdf_spec.rb@@ -32,15 +32,16 @@ RSpec.describe WorkPackage::PDFExport::WorkPackageToPdf doinclude Redmine::I18ninclude PDFExportSpecUtilslet(:type) do- create(:type_bug, custom_fields: [long_text_custom_field]).tap do |t|- t.attribute_groups.first.attributes.push(long_text_custom_field.attribute_name)+ 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)endendlet(:project) docreate(:project,name: 'Foo Bla. Report No. 4/2021 with/for Case 42',types: [type],- work_package_custom_fields: [long_text_custom_field])+ 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 disabledendlet(:user) docreate(:user,@@ -52,6 +53,10 @@ RSpec.describe WorkPackage::PDFExport::WorkPackageToPdf dolet(: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+ # NOT enabled by project.work_package_custom_field_ids => NOT in PDF+ create(:float_wp_custom_field, name: 'DisabledCustomField')+ endlet(:work_package) dodescription = <<~DESCRIPTION**Lorem** _ipsum_ ~~dolor~~ `sit` [amet](https://example.com/), consetetur sadipscing elitr.@@ -73,7 +78,10 @@ RSpec.describe WorkPackage::PDFExport::WorkPackageToPdf dosubject: 'Work package 1',story_points: 1,description:,- custom_values: { long_text_custom_field.id => 'foo' }).tap do |wp|+ custom_values: {+ long_text_custom_field.id => 'foo',+ disabled_custom_field.id => '6.25'+ }).tap do |wp|allow(wp).to receive(:attachments).and_return attachments@@ -110,25 +118,28 @@ RSpec.describe WorkPackage::PDFExport::WorkPackageToPdf dodescribe 'with a request for a PDF' doit 'contains correct data' dodetails = exporter.send(:attributes_data_by_wp, work_package)- .flat_map do |item|+ .flat_map do |item|value = get_column_value(item[:name])result = [item[:label].upcase]result << value if value.present?resultend# Joining the results for comparison since word wrapping leads to a different array for the same content- expect(pdf[:strings].join(' ')).to eq([- "#{type.name} ##{work_package.id} - #{work_package.subject}",- *details,- label_title(:description),- 'Lorem', ' ', 'ipsum', ' ', 'dolor', ' ', 'sit', ' ',- 'amet', ', consetetur sadipscing elitr.', ' ', '@OpenProject Admin',- 'Image Caption',- 'Foo',- '1', export_time_formatted, project.name,- 'LongText', 'foo',- '2', export_time_formatted, project.name- ].join(' '))+ result = pdf[:strings].join(' ')+ expected_result = [+ "#{type.name} ##{work_package.id} - #{work_package.subject}",+ *details,+ label_title(:description),+ 'Lorem', ' ', 'ipsum', ' ', 'dolor', ' ', 'sit', ' ',+ 'amet', ', consetetur sadipscing elitr.', ' ', '@OpenProject Admin',+ 'Image Caption',+ 'Foo',+ '1', export_time_formatted, project.name,+ 'LongText', 'foo',+ '2', export_time_formatted, project.name+ ].join(' ')+ expect(result).to eq(expected_result)+ expect(result).not_to include('DisabledCustomField')expect(pdf[:images].length).to eq(2)endend