This repository has been archived by the owner on Jan 8, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add tests for new mediated download links
- Loading branch information
Showing
14 changed files
with
52 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,14 @@ | ||
class ObjectFilesController < ApplicationController | ||
|
||
before_filter :authenticate_user! | ||
before_action :authenticate_user! | ||
|
||
def show | ||
@fobj = Hydrus::Item.find(params[:id]) | ||
@fobj.current_user = current_user | ||
authorize! :read, @fobj # only users who are authorized to view this object and download the files | ||
filename = params[:filename] | ||
object_file = Hydrus::ObjectFile.new(:pid=>DruidTools::Druid.new(@fobj.pid).druid) | ||
file_location = File.join(object_file.file.store_dir,filename) | ||
filename = params[:filename] | ||
object_file = Hydrus::ObjectFile.new(pid: DruidTools::Druid.new(@fobj.pid).druid) | ||
file_location = File.join(object_file.file.store_dir, filename) | ||
file = File.new(file_location) | ||
send_file file | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
require 'spec_helper' | ||
|
||
describe('Object Files Download', type: :request, integration: true) do | ||
fixtures :object_files | ||
let(:archivist1) { create :archivist1 } | ||
let(:archivist99) { create :archivist99 } | ||
|
||
before :each do | ||
@druid = 'druid:bb123bb1234' | ||
@file = Hydrus::ObjectFile.find(3) # this txt file defined in the fixtures belongs to archivist1 | ||
end | ||
|
||
it 'allows the owner of the file to download it' do | ||
sign_in(archivist1) # owner of the item can download the file | ||
visit @file.url | ||
expect(page.status_code).to eq(200) | ||
expect(page.response_headers['Content-Type']).to eq('text/plain') | ||
logout(archivist1) | ||
end | ||
|
||
it 'redirects to home page with not authorized message when accessing a file URL when no access is allowed' do | ||
sign_in(archivist99) # no view access on the item, no access | ||
visit @file.url | ||
expect(page.response_headers['Content-Type']).not_to eq('text/plain') | ||
expect(current_path).to eq(root_path) | ||
expect(find('#flash-notices div.alert')).to have_content('You are not authorized to access this page.') | ||
logout(archivist99) | ||
visit @file.url | ||
expect(current_path).to eq(root_path) # logged out, still can't get the file | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters