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
[#62293] PDF export does not export all embedded screenshots
as-opf379bc345547
diff --git a/app/models/work_package/pdf_export/common/attachments.rb b/app/models/work_package/pdf_export/common/attachments.rbindex 2a1574f8618..2464dfbf0ae 100644--- a/app/models/work_package/pdf_export/common/attachments.rb+++ b/app/models/work_package/pdf_export/common/attachments.rb@@ -70,8 +70,21 @@ module WorkPackage::PDFExport::Common::Attachmentsresize_image(local_file.path)end- def attachment_by_api_content_src(work_package, src)- # find attachment by api-path- work_package.attachments.find { |a| api_url_helpers.attachment_content(a.id) == src }+ def attachment_by_api_content_src(_work_package, src)+ # /attachments/#{id}/content+ parts = src.split("/")+ attachments_id = parts[-2]+ # return nil if the src is not an attachment url+ return nil unless api_url_helpers.attachment_content(attachments_id) == src++ attachment = Attachment.find_by(id: attachments_id.to_i)+ return nil if attachment.nil?+ return nil unless attachment.visible?++ attachment+ rescue StandardError+ # if the attachment is not found or the id is invalid, we return nil+ Rails.logger.error "Failed to access attachment #{src}"+ nilendenddiff --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 723b141eedf..460c9c9f597 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@@ -99,6 +99,7 @@ RSpec.describe WorkPackage::PDFExport::WorkPackageToPdf dolet(:image_path) { Rails.root.join("spec/fixtures/files/image.png") }let(:priority) { create(:priority_normal) }let(:image_attachment) { Attachment.new author: user, file: File.open(image_path) }+ let(:image_attachment_elsewhere) { Attachment.new author: user, file: File.open(image_path) }let(:attachments) { [image_attachment] }let(:cf_long_text_description) { "**foo** *faa*" }let(:cf_empty_long_text_description) { "" }@@ -137,6 +138,7 @@ RSpec.describe WorkPackage::PDFExport::WorkPackageToPdf do</figure></p><p><unknown-tag>Foo</unknown-tag></p>+ <img class="op-uc-image op-uc-image_inline" src="/api/v3/attachments/#{image_attachment_elsewhere.id}/content">DESCRIPTIONendlet(:work_package) do@@ -258,6 +260,11 @@ RSpec.describe WorkPackage::PDFExport::WorkPackageToPdf doimages: }end+ before do+ image_attachment.save+ image_attachment_elsewhere.save+ end+describe "with a request for a PDF" dodescribe "with rich text and images" doit "contains correct data" do@@ -274,17 +281,16 @@ RSpec.describe WorkPackage::PDFExport::WorkPackageToPdf do].flatten.join(" ")expect(result).to eq(expected_result)expect(result).not_to include("DisabledCustomField")- expect(pdf[:images].length).to eq(2)+ expect(pdf[:images].length).to eq(3)endend- describe "with a faulty image" do+ describe "with faulty images" dobefore do# simulate a null pointer exception# https://appsignal.com/openproject-gmbh/sites/62a6d833d2a5e482c1ef825d/exceptions/incidents/2326/samples/62a6d833d2a5e482c1ef825d-848752493603098719217252846401# where attachment data is in the database but the file is missing, corrupted or not accessible- allow(image_attachment).to receive(:file)- .and_return(nil)+ allow_any_instance_of(Attachment).to receive(:file).and_return(nil)endit "still finishes the export" do