Skip to content

Commit

Permalink
Render 404 Not Found for invalid problem filelink path
Browse files Browse the repository at this point in the history
Previously, /problems/:id/files/download/:path with a non-existent
path would crash with Pundit::NotDefinedError (unable to find policy
of nil), because `find_by_filepath` returns nil if the record is not
found and then `authorize @filelink, :show?` fails.

Full error trace:

```
Completed 500 Internal Server Error in 311ms (ActiveRecord: 30.2ms)
unable to find policy of nil excluded from capture: DSN not set

Pundit::NotDefinedError (unable to find policy of nil):
  app/controllers/filelinks/roots_controller.rb:61:in `show'
```
  • Loading branch information
tom93 committed Jan 8, 2024
1 parent 99b2e7c commit 923f2cd
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion app/controllers/filelinks/roots_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def show
else
raise ActiveRecord::RecordNotFound if params[:filepath].nil?
filepath = [params[:filepath], params[:format]].compact.join('.')
@filelink = model.filelinks.find_by_filepath(filepath)
@filelink = model.filelinks.find_by_filepath!(filepath)
end
authorize @filelink, :show?
send_file FileAttachmentUploader.root + @filelink.file_attachment_url, :filename => File.basename(@filelink.filepath), :disposition => 'inline'
Expand Down

0 comments on commit 923f2cd

Please sign in to comment.