Skip to content
This repository has been archived by the owner on Mar 24, 2020. It is now read-only.

Commit

Permalink
Fixes #467 - Allow UCSD local users to download video icons for UCSD
Browse files Browse the repository at this point in the history
IP/metadata-only collections.
  • Loading branch information
lsitu committed Jul 27, 2018
1 parent 681bcc2 commit a1834bd
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 3 deletions.
8 changes: 5 additions & 3 deletions lib/dams/controller_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -940,7 +940,7 @@ def mix_objects?(collection_id, obj_count)
#---
def can_download?(solr_doc, fileid = nil)
permissions = (Array(solr_doc['license_tesim']) + Array(solr_doc['otherRights_tesim'])).flatten.compact
return false if streaming_media_type?(solr_doc['resource_type_tesim']) && metadata_display?(permissions)
return false if streaming_media_type?(solr_doc['resource_type_tesim'], fileid) && metadata_display?(permissions)
metadata_only_display = metadata_only_display?(permissions)
return !restricted_file?(fileid) if fileid && metadata_only_display
!metadata_only_display
Expand All @@ -950,9 +950,11 @@ def restricted_file?(fileid)
fileid && fileid.include?('_2.jpg')
end

def streaming_media_type?(resource_types)
def streaming_media_type?(resource_types, fileid = nil)
return false if resource_types.blank?
resource_types.any? { |t| t.include?('video') || t.include?('sound') }
video_type = resource_types.any? { |t| t.include?('video') || t.include?('sound') }
return video_type unless video_type && fileid
fileid.end_with?('.mp4', '.mp3')
end

def metadata_only_display?(data)
Expand Down
54 changes: 54 additions & 0 deletions spec/controllers/file_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,7 @@
obj.licenseURI = license_local.pid
obj.add_file(Base64.decode64(mov_content), '_1.mov', 'audio_source.mov')
obj.add_file(Base64.decode64(mp4_content), '_2.mp4', 'audio_service.mp4')
obj.add_file(Base64.decode64(jpeg_content), '_4.jpg', 'image_icon.jpg')
obj.save
solr_index obj.pid
end
Expand All @@ -491,6 +492,12 @@
get :show, id: obj.pid, ds: '_2.mp4'
expect(response).to have_http_status(200)
end

it 'can download the image icon' do
sign_in User.create!(provider: 'developer')
get :show, id: obj.pid, ds: '_4.jpg'
expect(response).to have_http_status(200)
end
end

describe 'public download' do
Expand All @@ -503,6 +510,11 @@
get :show, id: obj.pid, ds: '_2.mp4'
expect(response).to have_http_status(403)
end

it 'cannot download the image icon' do
get :show, id: obj.pid, ds: '_4.jpg'
expect(response).to have_http_status(403)
end
end

describe 'campus download' do
Expand All @@ -517,6 +529,12 @@
get :show, id: obj.pid, ds: '_2.mp4'
expect(response).to have_http_status(403)
end

it 'can download the image icon' do
sign_in_anonymous '132.239.0.3'
get :show, id: obj.pid, ds: '_4.jpg'
expect(response).to have_http_status(200)
end
end
end

Expand All @@ -531,6 +549,7 @@
obj.otherRightsURI = otherRights_local.pid
obj.add_file(Base64.decode64(mov_content), '_1.mov', 'audio_source.mov')
obj.add_file(Base64.decode64(mp4_content), '_2.mp4', 'audio_service.mp4')
obj.add_file(Base64.decode64(jpeg_content), '_4.jpg', 'image_icon.jpg')
obj.save
solr_index obj.pid
end
Expand All @@ -551,6 +570,12 @@
get :show, id: obj.pid, ds: '_2.mp4'
expect(response).to have_http_status(200)
end

it 'can download the image icon' do
sign_in User.create!(provider: 'developer')
get :show, id: obj.pid, ds: '_4.jpg'
expect(response).to have_http_status(200)
end
end

describe 'public download' do
Expand All @@ -563,6 +588,11 @@
get :show, id: obj.pid, ds: '_2.mp4'
expect(response).to have_http_status(403)
end

it 'cannot download the image icon' do
get :show, id: obj.pid, ds: '_4.jpg'
expect(response).to have_http_status(403)
end
end

describe 'campus download' do
Expand All @@ -577,6 +607,12 @@
get :show, id: obj.pid, ds: '_2.mp4'
expect(response).to have_http_status(403)
end

it 'can download the image icon' do
sign_in_anonymous '132.239.0.3'
get :show, id: obj.pid, ds: '_4.jpg'
expect(response).to have_http_status(200)
end
end
end

Expand Down Expand Up @@ -650,6 +686,7 @@
obj.otherRightsURI = otherRights_metadata.pid
obj.add_file(Base64.decode64(mov_content), '_1.mov', 'audio_source.mov')
obj.add_file(Base64.decode64(mp4_content), '_2.mp4', 'audio_service.mp4')
obj.add_file(Base64.decode64(jpeg_content), '_4.jpg', 'image_icon.jpg')
obj.save
solr_index obj.pid
end
Expand All @@ -670,6 +707,12 @@
get :show, id: obj.pid, ds: '_2.mp4'
expect(response).to have_http_status(200)
end

it 'can download the image icon' do
sign_in User.create!(provider: 'developer')
get :show, id: obj.pid, ds: '_4.jpg'
expect(response).to have_http_status(200)
end
end

describe 'public download' do
Expand All @@ -682,6 +725,11 @@
get :show, id: obj.pid, ds: '_2.mp4'
expect(response).to have_http_status(403)
end

it 'cannot download the image icon' do
get :show, id: obj.pid, ds: '_4.jpg'
expect(response).to have_http_status(403)
end
end

describe 'campus download' do
Expand All @@ -696,6 +744,12 @@
get :show, id: obj.pid, ds: '_2.mp4'
expect(response).to have_http_status(403)
end

it 'can download the image icon' do
sign_in_anonymous '132.239.0.3'
get :show, id: obj.pid, ds: '_4.jpg'
expect(response).to have_http_status(200)
end
end
end
end
Expand Down

0 comments on commit a1834bd

Please sign in to comment.