Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update downloads_controller to serve file view properly. #866

Merged
merged 12 commits into from
Sep 20, 2018

Conversation

weiweishi
Copy link
Contributor

@weiweishi weiweishi commented Sep 18, 2018

Update the downloads_controller to:

  • use disposition: 'inline' for file viewing
  • use type instead of content-type when sending data
  • use find_by instead of where.first to fetch file in the fileset.

Updated how urls and filename are handled with regular Rails/ActiveStorage way. And added more tests for the download controllers.

accesslint[bot]
accesslint bot previously approved these changes Sep 18, 2018
@@ -1,12 +1,4 @@
module ItemsHelper
def file_view_url(file)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need all these custom helpers? Just use rails routes properly

@@ -11,7 +11,7 @@ def perform(attachment_id)
item = attachment.record.owner

path = ActiveStorage::Blob.service.send(:path_for, attachment.blob.key)
original_filename = attachment.blob.filename.to_s
original_filename = attachment.filename.to_s
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't need to walk the chain of the blob object to get filename, can get it right from the activestorage object

file_set_id: @item.files.first.fileset_uuid,
file_name: @item.files.first.filename,
only_path: true
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was a bug here. We need the absolute url not just the path (relative url)!

From here: https://scholar.google.ca/intl/en/scholar/inclusion.html#indexing

The content of the tag is the absolute URL of the PDF file; for security reasons, it must refer to a file in the same subdirectory as the HTML abstract.

@murny
Copy link
Contributor

murny commented Sep 19, 2018

Need to do some manual testing to make sure theirs no regressions with the file download changes I have made. But so far looks good.

Added comments for my big changes ( of course theres still a few lingering urls that should be moved over to the new download routes i created but can maybe tackle this later)

EDIT: Manual testing seems to be fine, should be all good to go on my end

@weiweishi
Copy link
Contributor Author

Assume this is no longer WIP. I am looking into the manual testing right now.

@weiweishi
Copy link
Contributor Author

Validated all the file download/view links, filename saved in fedora etc, all looks good to me. Now sure if there's an easy way for me to manually test the redirect urls.

@murny
Copy link
Contributor

murny commented Sep 20, 2018

Yeah had hard time testing the redirects as well since they expect some weird formats and kept failing on validation errors (/public/view/item/uuid:{{uuid}}/{{datastream? random numbers}}/:filename)

So not sure best way to verify this either /shrug

@@ -0,0 +1,44 @@
require 'test_helper'

class DownloadsControllerTest < ActionDispatch::IntegrationTest
Copy link
Contributor

@murny murny Sep 20, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New tests for testing the downloads controller, view and download actions. Making sure the file being viewed/downloaded is being streamed back with the proper headers and content

Copy link
Contributor

@murny murny left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@weiweishi weiweishi changed the title WIP - Update downloads_controller to serve file view properly. Update downloads_controller to serve file view properly. Sep 20, 2018
@weiweishi weiweishi merged commit 04b317a into master Sep 20, 2018
@murny murny deleted the download_controller_view branch September 21, 2018 16:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants