Skip to content

Commit

Permalink
Merge pull request #16593 from opf/bug/57612-work-package-report-expo…
Browse files Browse the repository at this point in the history
…rt-fails-if-work-package-has-unavailable-attachments

Bug/57612 work package report export fails if work package has unavailable attachments
  • Loading branch information
dombesz authored Sep 3, 2024
2 parents f00b6e9 + 6decead commit 14eaeea
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
14 changes: 12 additions & 2 deletions app/models/work_package/pdf_export/markdown.rb
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,22 @@ def write_markdown!(work_package, markdown)

private

def attachment_image_local_file(attachment)
attachment.file.local_file
rescue StandardError => e
Rails.logger.error "Failed to access attachment #{attachment.id} file: #{e}"
nil # return nil as if the id was wrong and the attachment obj has not been found
end

def attachment_image_filepath(work_package, src)
# images are embedded into markup with the api-path as img.src
attachment = attachment_by_api_content_src(work_package, src)
return nil if attachment.nil? || attachment.file.local_file.nil? || !pdf_embeddable?(attachment.content_type)
return nil if attachment.nil? || !pdf_embeddable?(attachment.content_type)

local_file = attachment_image_local_file(attachment)
return nil if local_file.nil?

resize_image(attachment.file.local_file.path)
resize_image(local_file.path)
end

def attachment_by_api_content_src(work_package, src)
Expand Down
14 changes: 14 additions & 0 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 @@ -244,6 +244,20 @@ def get_column_value(column_name)
end
end

describe "with a faulty image" do
before 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)
end

it "still finishes the export" do
expect(pdf[:images].length).to eq(0)
end
end

describe "with embedded work package attributes" do
let(:supported_work_package_embeds) do
[
Expand Down

0 comments on commit 14eaeea

Please sign in to comment.