Skip to content

Commit

Permalink
Restricted downloads open in new tab
Browse files Browse the repository at this point in the history
  • Loading branch information
spilth committed Aug 1, 2024
1 parent 02e7ad1 commit be62a45
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 14 deletions.
5 changes: 3 additions & 2 deletions app/helpers/geoblacklight_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def iiif_jpg_url
@document.references.iiif.endpoint.sub! 'info.json', 'full/full/0/default.jpg'
end

def download_link_file(label, id, url)
def download_link_file(label, id, url, target = nil)
link_to(
label,
url,
Expand All @@ -22,7 +22,8 @@ def download_link_file(label, id, url)
download: 'trigger',
download_type: 'direct',
download_id: id
}
},
target: target
)
end

Expand Down
2 changes: 1 addition & 1 deletion app/views/catalog/_downloads_collapse.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<% end %>
<% end %>
<% if document.direct_download[:download].is_a? String %>
<%= download_link_file(download_text(document.file_format), document.id, document.direct_download[:download]) %>
<%= download_link_file(download_text(document.file_format), document.id, document.direct_download[:download], document.restricted? ? "_blank" : nil) %>
<% end %>
<% end %>

Expand Down
44 changes: 33 additions & 11 deletions spec/features/show_page_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,41 @@

describe 'Show page' do
context 'with restricted NYU result - nyu-2451-34626' do
it 'the displays warning message' do
visit solr_document_path 'nyu-2451-34626'
expect(page).to have_content 'This dataset is only available to members of the New York University community'
end
context 'when signed out' do
it 'the displays warning message' do
visit solr_document_path 'nyu-2451-34626'
expect(page).to have_content 'This dataset is only available to members of the New York University community'
end

it 'does not display download' do
visit solr_document_path 'nyu-2451-34626'
expect(page).not_to have_content 'Export'
it 'does not display download' do
visit solr_document_path 'nyu-2451-34626'
expect(page).not_to have_content 'Export'
end

it 'includes link to login' do
visit solr_document_path 'nyu-2451-34626'
expect(page).to have_link('Login to View and Download')
end
end

it 'includes link to login' do
visit solr_document_path 'nyu-2451-34626'
expect(page).to have_link('Login to View and Download')
context 'when signed in' do
before do
login_as(create(:user), scope: :user)
end

it 'shows a download button' do
visit solr_document_path 'nyu-2451-34626'
expect(page).to have_button('Download')
end

it 'opens download links in a new tab' do
visit solr_document_path 'nyu-2451-34626'
click_button('Download')

within_window(window_opened_by { click_link('Original Shapefile') }) do
expect(page.title).not_to include('NYU Spatial Data Repository')
end
end
end
end

Expand Down Expand Up @@ -44,7 +66,7 @@

# TODO: Refactor this to play nice with Rubocop
# rubocop:disable RSpec/ExampleLength, RSpec/MultipleExpectations
context 'with multiple downloads - nyu-2451-38645' do #
context 'with multiple downloads - nyu-2451-38645' do
it 'includes six download links' do
visit solr_document_path 'nyu-2451-38645'
expect(page).to have_content 'Download'
Expand Down

0 comments on commit be62a45

Please sign in to comment.