Skip to content

Commit

Permalink
don't pass extra parameters to attachment_fu
Browse files Browse the repository at this point in the history
when s3 storage is enabled, attachment_fu's url generation is...
finicky. it'll blow up if parameters it's not expecting are present.

test-plan:
- have s3 storage enabled in your environment
- have a file in your user's file area (new or old, doesn't matter, as
  long as it's on s3)
- select the file in the file UI and click the "download" button
- should download the file instead of giving an error

Change-Id: I1a22cdfd095889045ff7e4b7912a617bcdde3d8c
Reviewed-on: https://gerrit.instructure.com/124791
Reviewed-by: Spencer Olson <[email protected]>
Tested-by: Jenkins
Reviewed-by: Andrew Huff <[email protected]>
QA-Review: Collin Parrish <[email protected]>
Product-Review: Jacob Fugal <[email protected]>
  • Loading branch information
lukfugl committed Sep 1, 2017
1 parent 9a350ee commit ddf0f2d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
4 changes: 3 additions & 1 deletion app/models/attachment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -749,7 +749,9 @@ def authenticated_url(*thumbnail, **options)
if InstFS.enabled? && self.instfs_uuid
InstFS.authenticated_url(self, options)
else
disposition = options[:download] ? "attachment" : "inline"
# attachment_fu doesn't like the extra option when building s3 urls
should_download = options.delete(:download)
disposition = should_download ? "attachment" : "inline"
options[:response_content_disposition] = "#{disposition}; #{disposition_filename}"
self.authenticated_s3_url(*thumbnail, **options)
end
Expand Down
7 changes: 7 additions & 0 deletions spec/models/attachment_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -988,6 +988,13 @@ def configure_canvadocs(opts = {})
course_model
end

it "should work with s3 storage" do
s3_storage!
attachment = attachment_with_context(@course, :display_name => 'foo')
expect(attachment.download_url).to match(/response-content-disposition=attachment/)
expect(attachment.inline_url).to match(/response-content-disposition=inline/)
end

it 'should allow custom ttl for download_url' do
attachment = attachment_with_context(@course, :display_name => 'foo')
allow(attachment).to receive(:authenticated_url) # allow other calls due to, e.g., save
Expand Down

0 comments on commit ddf0f2d

Please sign in to comment.