Skip to content

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

[#41852] fix undefined method path for nil class when click attachment

jenenliu69f4cc2ff304
diff --git a/lib/api/helpers/attachment_renderer.rb b/lib/api/helpers/attachment_renderer.rb
index 25ae274267b..5692f47515a 100644
--- a/lib/api/helpers/attachment_renderer.rb
+++ b/lib/api/helpers/attachment_renderer.rb
@@ -86,6 +86,10 @@ module API
end
def send_attachment(attachment)
+ if attachment.diskfile.nil?
+ raise ::API::Errors::NotFound.new
+ end
+
content_type attachment_content_type(attachment)
header["Content-Disposition"] = attachment.content_disposition
env["api.format"] = :binary
diff --git a/spec/requests/api/v3/attachments/attachment_resource_shared_examples.rb b/spec/requests/api/v3/attachments/attachment_resource_shared_examples.rb
index cc32297a87d..57fd8038680 100644
--- a/spec/requests/api/v3/attachments/attachment_resource_shared_examples.rb
+++ b/spec/requests/api/v3/attachments/attachment_resource_shared_examples.rb
@@ -471,6 +471,13 @@ RSpec.shared_examples "an APIv3 attachment resource", content_type: :json, type:
expect(subject.body)
.to match(mock_file.read)
end
+
+ it "responds with not found if file has been deleted" do
+ File.delete attachment.file.path
+
+ get path
+ expect(subject.status).to eq 404
+ end
end
context "for a local text file" do