From 92c91203ffd992bb0a2a67d05a9b529687fd8f24 Mon Sep 17 00:00:00 2001 From: VivianChu Date: Fri, 20 Apr 2018 11:06:58 -0700 Subject: [PATCH] Add restricted note info to complex object view Update qa config Update tests and qa deploy config Fix access control tests issue Add restricted note info to complex object view Update tests and qa deploy config Update tests Fix hound violation --- .rubocop.yml | 9 + app/assets/javascripts/views-object.js | 6 + .../stylesheets/custom-object-viewer.css.scss | 2 +- app/controllers/dams_resource_controller.rb | 2 + app/helpers/dams_objects_helper.rb | 33 ++ .../_audio_viewer_complex.html.erb | 6 +- .../_complex_object_viewer.html.erb | 31 +- .../dams_objects/_document_viewer.html.erb | 3 +- .../dams_objects/_restricted_access.html.erb | 7 + .../_simple_object_viewer.html.erb | 2 +- .../_video_viewer_complex.html.erb | 7 +- config/deploy/qa.rb | 2 +- lib/dams/controller_helper.rb | 10 + spec/features/access_control_spec.rb | 5 +- spec/features/dams_object_spec.rb | 40 +++ spec/fixtures/damsComplexObject10.rdf.xml | 337 ++++++++++++++++++ spec/fixtures/damsComplexObject3.rdf.xml | 2 + 17 files changed, 476 insertions(+), 28 deletions(-) create mode 100644 app/views/dams_objects/_restricted_access.html.erb create mode 100644 spec/fixtures/damsComplexObject10.rdf.xml diff --git a/.rubocop.yml b/.rubocop.yml index 9c4f81fbb..ce7aee34d 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -36,3 +36,12 @@ Metrics/AbcSize: Metrics/LineLength: Max: 150 + +Rails/OutputSafety: + Exclude: + - 'app/helpers/dams_objects_helper.rb' + +Style/SafeNavigation: + Exclude: + - 'app/helpers/dams_objects_helper.rb' + - 'lib/dams/controller_helper.rb' diff --git a/app/assets/javascripts/views-object.js b/app/assets/javascripts/views-object.js index 481dc5b69..a669f7ad8 100644 --- a/app/assets/javascripts/views-object.js +++ b/app/assets/javascripts/views-object.js @@ -299,6 +299,12 @@ $(document).ready(function() $(".simple-object, .first-component, .dams-sidebar").hide(); } + // Hide content if "restricted view notice" present + if($(".restricted-notice-complex").length) + { + $(".simple-object").hide(); + } + // Show hidden "restricted notice" objects $("#view-masked-object").click(function() { $('.restricted-notice').hide(); diff --git a/app/assets/stylesheets/custom-object-viewer.css.scss b/app/assets/stylesheets/custom-object-viewer.css.scss index 38db3bc2c..6661f4fd1 100644 --- a/app/assets/stylesheets/custom-object-viewer.css.scss +++ b/app/assets/stylesheets/custom-object-viewer.css.scss @@ -103,7 +103,7 @@ $complexFile: #AC6F2B !default; .file-thumbnail img{margin-bottom: 20px;} // Masked Objects (Restricted, Sensitive, etc.) -.restricted-notice +.restricted-notice, .restricted-notice-complex { background:#b1b1b1 url(https://library.ucsd.edu/assets/dams/site/restricted.png) no-repeat center center; background-size:150%,150%; diff --git a/app/controllers/dams_resource_controller.rb b/app/controllers/dams_resource_controller.rb index dd5ced76c..000914365 100644 --- a/app/controllers/dams_resource_controller.rb +++ b/app/controllers/dams_resource_controller.rb @@ -56,6 +56,8 @@ def show end end @related_collections = related_collections_map facet_collection_names + else + @metadata_only = metadata_display?(@document['otherRights_tesim']) end @rdfxml = @document['rdfxml_ssi'] diff --git a/app/helpers/dams_objects_helper.rb b/app/helpers/dams_objects_helper.rb index ccb904de8..534f19514 100644 --- a/app/helpers/dams_objects_helper.rb +++ b/app/helpers/dams_objects_helper.rb @@ -688,6 +688,39 @@ def grabRestrictedText(data) end + #--- + # Check to see if an object has a "metadataDisplay or localDisplay otherRights" + # + # @return An HTML string if an object has a "metadataDisplay or localDisplay otherRights", nil otherwise + #--- + + def grab_access_text(document) + result = nil + access_group = document['read_access_group_ssim'] # "public" > "local" > "dams-curator" == "dams-rci" == default + data = document['otherRights_tesim'] + unless data.nil? && access_group.nil? + if access_group.include?('local') + data.each do |datum| + if datum.include?('localDisplay') || datum.include?('metadataDisplay') + result = "

Restricted View

#{get_attribution_note(document['otherNote_json_tesim'])}

".html_safe + end + end + end + end + result + end + + def get_attribution_note(data) + result = 'Content not available. Access may granted for research purposes at the discretion of the UC San Diego Library. ' + result += 'For more information please contact the ' + unless data.nil? + data.each do |datum| + note = JSON.parse(datum) + result += note['value'] if note['type'].start_with?('local attribution') + end + end + result + end #--- # Normalized rdf view from DAMS4 REST API #--- diff --git a/app/views/dams_objects/_audio_viewer_complex.html.erb b/app/views/dams_objects/_audio_viewer_complex.html.erb index 71824025d..1d1c4cc33 100644 --- a/app/views/dams_objects/_audio_viewer_complex.html.erb +++ b/app/views/dams_objects/_audio_viewer_complex.html.erb @@ -7,10 +7,12 @@ dataForDynamicLoad = "{\"file_type\":\"audio\",\"display_file_path\":\"\",\"service_file_path\":\"#{wowzaURL}\"}" %> +<%= render :partial => 'restricted_access', :locals => {:access_notice => access_notice } %> -<% if wowzaURL != nil %> +<% if access_notice.nil? && wowzaURL != nil %>
Loading the player...
<% end %> -<%= render :partial => 'admin_download', :locals => {:downloadFilePath => downloadFilePath, :downloadDerivativePath => downloadDerivativePath } %> + +<%= render :partial => 'admin_download', :locals => {:downloadFilePath => downloadFilePath, :downloadDerivativePath => downloadDerivativePath } if access_notice.nil?%> diff --git a/app/views/dams_objects/_complex_object_viewer.html.erb b/app/views/dams_objects/_complex_object_viewer.html.erb index 84f12af93..111e59fe3 100644 --- a/app/views/dams_objects/_complex_object_viewer.html.erb +++ b/app/views/dams_objects/_complex_object_viewer.html.erb @@ -15,6 +15,7 @@ <% end %> +<% access_text = grab_access_text(@document) %>
@@ -54,48 +55,48 @@ isFirstComponent = (i == 1) ? true : false %> -
> <%= render :partial => 'shared/fields/title', :locals => {:componentIndex => i} %> - <% if fileType == 'image' %> - + <%= render :partial => 'restricted_access', :locals => {:access_notice => access_text} %> + <% if access_text.nil? %> <% zoom_file_path = zoom_path(ark, "#{i}") %> <% dataForDynamicLoad = "{\"file_type\":\"image\",\"display_file_path\":\"#{display_file_path}\",\"service_file_path\":\"#{zoom_file_path}\",\"download_file_path\":\"#{download_file_path}\"}" %>
+ <% end %> <%= render :partial => 'metadata_component', :locals => {:componentIndex => i} %> - <%= render :partial => 'admin_download', :locals => {:downloadFilePath => download_file_path, :downloadDerivativePath => service_file_path } %> + <%= render :partial => 'admin_download', :locals => {:downloadFilePath => download_file_path, :downloadDerivativePath => service_file_path } if access_text.nil?%> <% elsif fileType == 'audio' %> - <%= render :partial => 'audio_viewer_complex', :locals => {:componentIndex => i, :downloadFilePath => download_file_path, :downloadDerivativePath => nil } %> + <%= render :partial => 'audio_viewer_complex', :locals => {:access_notice => access_text, :componentIndex => i, :downloadFilePath => download_file_path, :downloadDerivativePath => nil } %> <%= render :partial => 'metadata_component', :locals => {:componentIndex => i} %> <% elsif fileType == 'video' %> - <%= render :partial => 'video_viewer_complex', :locals => {:componentIndex => i, :downloadFilePath => download_file_path, :downloadDerivativePath => service_file_path } %> + <%= render :partial => 'video_viewer_complex', :locals => {:access_notice => access_text, :componentIndex => i, :downloadFilePath => download_file_path, :downloadDerivativePath => service_file_path } %> <%= render :partial => 'metadata_component', :locals => {:componentIndex => i} %> <% elsif fileType == 'document' %> - <%= render :partial => 'document_viewer', :locals => {:filePath => service_file_path, :displayFilePath => display_file_path, :downloadDerivativePath => service_file_path } %> + <%= render :partial => 'document_viewer', :locals => {:access_notice => access_text, :filePath => service_file_path, :displayFilePath => display_file_path, :downloadDerivativePath => service_file_path } %> <%= render :partial => 'metadata_component', :locals => {:componentIndex => i, :fileMetadata => true, :fileName => service_file} %> - <%= render :partial => 'data_viewer', :locals => {:objectType => 'complex', :filePath => service_file_path, :downloadDerivativePath => service_file_path, :sourcefilePath => source_file_path } %> + <%= render :partial => 'data_viewer', :locals => {:objectType => 'complex', :filePath => service_file_path, :downloadDerivativePath => service_file_path, :sourcefilePath => source_file_path } if access_text.nil?%> <% elsif fileType == 'data' %> - + <%= render :partial => 'restricted_access', :locals => {:access_notice => access_text} %> <%= render :partial => 'metadata_component', :locals => {:componentIndex => i, :fileMetadata => true, :fileName => service_file} %> - <%= render :partial => 'data_viewer', :locals => {:objectType => 'complex', :filePath => service_file_path, :downloadDerivativePath => service_file_path, :sourcefilePath => source_file_path } %> + <%= render :partial => 'data_viewer', :locals => {:objectType => 'complex', :filePath => service_file_path, :downloadDerivativePath => service_file_path, :sourcefilePath => source_file_path } if access_text.nil?%> <% elsif fileType == 'text' %> + <%= render :partial => 'restricted_access', :locals => {:access_notice => access_text} %> <%= render :partial => 'metadata_component', :locals => {:componentIndex => i, :fileMetadata => true, :fileName => service_file} %> - <%= render :partial => 'text_viewer', :locals => {:objectType => 'complex', :downloadFilePath => download_file_path, :downloadDerivativePath => service_file_path } %> + <%= render :partial => 'text_viewer', :locals => {:objectType => 'complex', :downloadFilePath => download_file_path, :downloadDerivativePath => service_file_path } if access_text.nil?%> <% else %> - + <%= render :partial => 'restricted_access', :locals => {:access_notice => access_text} %> <%= render :partial => 'metadata_component', :locals => {:componentIndex => i} %> - <%= render :partial => 'default_viewer', :locals => {:objectType => 'complex'} %> - + <%= render :partial => 'default_viewer', :locals => {:objectType => 'complex'} %> <% end %>
@@ -104,4 +105,4 @@ <% end %> -
\ No newline at end of file + \ No newline at end of file diff --git a/app/views/dams_objects/_document_viewer.html.erb b/app/views/dams_objects/_document_viewer.html.erb index 81602df5f..15318f364 100644 --- a/app/views/dams_objects/_document_viewer.html.erb +++ b/app/views/dams_objects/_document_viewer.html.erb @@ -1,4 +1,5 @@ -<% if defined?(filePath) and defined?(displayFilePath)%> +<%= render :partial => 'restricted_access', :locals => {:access_notice => access_notice } %> +<% if access_notice.nil? and defined?(filePath) and defined?(displayFilePath)%> <% viewFilePath = filePath.gsub('/download', '') %> diff --git a/app/views/dams_objects/_restricted_access.html.erb b/app/views/dams_objects/_restricted_access.html.erb new file mode 100644 index 000000000..04ab306e6 --- /dev/null +++ b/app/views/dams_objects/_restricted_access.html.erb @@ -0,0 +1,7 @@ +<% unless access_notice.nil? %> +
+
+ <%= access_notice %> +
+
+<% end %> \ No newline at end of file diff --git a/app/views/dams_objects/_simple_object_viewer.html.erb b/app/views/dams_objects/_simple_object_viewer.html.erb index fd31b03da..b5f99e555 100644 --- a/app/views/dams_objects/_simple_object_viewer.html.erb +++ b/app/views/dams_objects/_simple_object_viewer.html.erb @@ -27,7 +27,7 @@ <% when 'video-service' %> <%= render :partial => 'video_viewer', :locals => {:filePath => service_file_path, :icon => display_file_path, :downloadFilePath => download_file_path, :downloadDerivativePath => download_derivative_path} %> <% when 'document-service' %> - <%= render :partial => 'document_viewer', :locals => {:filePath => service_file_path, :displayFilePath => display_file_path, :downloadDerivativePath => download_derivative_path} %> + <%= render :partial => 'document_viewer', :locals => {:access_notice => nil, :filePath => service_file_path, :displayFilePath => display_file_path, :downloadDerivativePath => download_derivative_path} %> <%= render :partial => 'metadata_data_file', :locals => {:fileName => service_file} %> <%= render :partial => 'data_viewer', :locals => {:displayFilePath => display_file_path, :filePath => service_file_path, :objectType => 'simple', :pdfFilePath => pdf_file_path, :sourcefilePath => source_file_path} %> <% when 'data-service' %> diff --git a/app/views/dams_objects/_video_viewer_complex.html.erb b/app/views/dams_objects/_video_viewer_complex.html.erb index 5c9302d71..0124b6316 100644 --- a/app/views/dams_objects/_video_viewer_complex.html.erb +++ b/app/views/dams_objects/_video_viewer_complex.html.erb @@ -6,10 +6,9 @@ wowzaURL = grabWowzaURL(fieldData,objid,cmpid) dataForDynamicLoad = "{\"file_type\":\"video\",\"display_file_path\":\"\",\"service_file_path\":\"#{wowzaURL}\"}" %> +<%= render :partial => 'restricted_access', :locals => {:access_notice => access_notice } %> -<% if wowzaURL != nil %> - +<% if access_notice.nil? && wowzaURL != nil %> - <% end %> -<%= render :partial => 'admin_download', :locals => {:downloadFilePath => downloadFilePath, :downloadDerivativePath => downloadDerivativePath } %> +<%= render :partial => 'admin_download', :locals => {:downloadFilePath => downloadFilePath, :downloadDerivativePath => downloadDerivativePath } if access_notice.nil?%> diff --git a/config/deploy/qa.rb b/config/deploy/qa.rb index 67d5a26fe..d6c533383 100644 --- a/config/deploy/qa.rb +++ b/config/deploy/qa.rb @@ -1,5 +1,5 @@ set :stage, :qa -set :branch, 'develop' +set :branch, (ENV['BRANCH'] || fetch(:branch, 'develop')) server 'lib-hydrahead-qa.ucsd.edu', user: 'conan', roles: %w{web app db sitemap_noping} server 'lib-hydratail-qa.ucsd.edu', user: 'conan', roles: %w{web app db sitemap_noping} set :rails_env, "qa" diff --git a/lib/dams/controller_helper.rb b/lib/dams/controller_helper.rb index d9d41eabd..6cc60bf28 100644 --- a/lib/dams/controller_helper.rb +++ b/lib/dams/controller_helper.rb @@ -882,5 +882,15 @@ def referrer_controller( request ) end end end + + def metadata_display?(data) + result = false + unless data.nil? + data.each do |datum| + result = true if datum.include?('localDisplay') || datum.include?('metadataDisplay') + end + end + result + end end end diff --git a/spec/features/access_control_spec.rb b/spec/features/access_control_spec.rb index f02ea7e36..0ea7e3223 100644 --- a/spec/features/access_control_spec.rb +++ b/spec/features/access_control_spec.rb @@ -35,7 +35,7 @@ visit catalog_index_path( {:q => 'object'} ) expect(page).to have_selector('h3', 'Public Object') expect(page).to have_no_content('Curator Object') - expect(page).to have_no_content('Local Object') + expect(page).to have_content('Local Object') expect(page).to have_no_content('Hidden Object') end scenario 'anonymous user viewing public object' do @@ -50,8 +50,7 @@ end scenario 'anonymous user viewing local object' do visit dams_object_path @localObj.pid - expect(page).to have_selector('h1','You are not allowed to view this page.') - expect(page).to have_no_content('Local Object') + expect(page).to have_content('Local Object') end scenario 'anonymous user viewing file attached to hidden object' do visit file_path( @hiddenObj, '_1.txt' ) diff --git a/spec/features/dams_object_spec.rb b/spec/features/dams_object_spec.rb index f54cb9c1d..12deac2bd 100644 --- a/spec/features/dams_object_spec.rb +++ b/spec/features/dams_object_spec.rb @@ -703,6 +703,46 @@ end end +describe "User wants to view a metadata-only complex object" do + let(:restricted_note) {'Restricted View Content not available. Access may granted for research purposes at the discretion of the UC San Diego Library. For more information please contact the Research Data Curation Program, UC San Diego, La Jolla, 92093-0175 (https://lib.ucsd.edu/rdcp)'} + before do + @otherRight = DamsOtherRight.create pid: 'xx58718348', permissionType: "metadataDisplay" + @metadataOnlyCollection = DamsProvenanceCollection.create pid: 'xx91824453', titleValue: "Test UCSD IP only Collection with metadata-only visibility", visibility: "local" + @metadataOnlyObj = DamsObject.create(pid: "xx99999999") + @metadataOnlyObj.damsMetadata.content = File.new('spec/fixtures/damsComplexObject10.rdf.xml').read + @metadataOnlyObj.save! + solr_index @otherRight.pid + solr_index @metadataOnlyCollection.pid + solr_index @metadataOnlyObj.pid + Capybara.javascript_driver = :poltergeist + Capybara.current_driver = Capybara.javascript_driver + sign_in_developer + end + + after do + @otherRight.delete + @metadataOnlyCollection.delete + @metadataOnlyObj.delete + end + + scenario 'should see Restricted View access control information' do + visit dams_object_path @metadataOnlyObj.pid + expect(page).to have_selector('#component-pager-label', :text=>'Component 1 of 4') + expect(page).to have_content('Interval 1 (dredge, rock)') + expect(page).to have_selector('div.restricted-notice-complex', text: restricted_note) + expect(page).to have_selector('div.file-metadata', text: 'Access Restricted View') + end + + scenario 'should see Restricted View access control info in other component when clicking on navigation arrow' do + visit dams_object_path @metadataOnlyObj.pid + click_button 'component-pager-forward' + find('#component-pager-label').should have_content('Component 2 of 4') + expect(page).to have_content('Files') + expect(page).to have_selector('div.restricted-notice-complex', text: restricted_note) + expect(page).to have_selector('div.file-metadata', text: 'Access Restricted View') + end +end + describe "curator embargoed object view" do before do @otherRights = DamsOtherRight.create pid: 'zz58718348', permissionType: "metadataDisplay", basis: "fair use", diff --git a/spec/fixtures/damsComplexObject10.rdf.xml b/spec/fixtures/damsComplexObject10.rdf.xml new file mode 100644 index 000000000..94e72ce8a --- /dev/null +++ b/spec/fixtures/damsComplexObject10.rdf.xml @@ -0,0 +1,337 @@ + + + + + + + + + + Dredge photographs + + + Dredge photographs + + + + + 1 + + + + + + + Image 001 + + + Image 001 + + + 1 + + + full + jhovetmp7957176984930577534.jpg + 9c06f7600e92ba5fb05446e33b0349b8e48fe261 + image-thumbnail + 19109 + /usr/local/tomcat/temp + 1.01 + 2013-12-12T08:16:57-0800 + file + + b05c2f69 + image/jpeg + 0 + openStack + 150x100 + JPEG + 106071896711ad0774803c71dbf20b1f + + + + + full + 38f290a4 + d3bbfd689ccd4ce3439a3554ef05ad45 + JPEG + image-huge + openStack + jhovetmp8792219027437235170.jpg + 63eb643c9925a17d7cd11d203222e55daad3f012 + 1.01 + file + /usr/local/tomcat/temp + 0 + + image/jpeg + 384000 + 1600x1067 + 2013-12-12T08:16:50-0800 + + + + + file + 57f33c5c6bd2da1b42a445c4523d259e + JPEG + image/jpeg + 476f5986 + 372b53ec488b9b1e4f2d3d1b44d44c672059575e + 180256 + + jhovetmp459538904546600193.jpg + openStack + 2013-12-12T08:16:53-0800 + /usr/local/tomcat/temp + 1.01 + full + 0 + image-large + 1024x683 + + + + + 2013-12-12T08:16:47-0800 + 0 + image/jpeg + 97077868006d75919dc2e2acdab9be231b935227 + 1.01 + full + JPEG + jhovetmp2427373142421224682.jpg + 111807 + image-service + /usr/local/tomcat/temp + openStack + 3115372b + 3bbd16d72b0602cb8a9eafa52c8e9c4a + + 768x512 + file + + + + + /usr/local/tomcat/temp + 450x300 + full + jhovetmp1967571600967591238.jpg + image-preview + 51374 + image/jpeg + 1.01 + 064d57360243a3aeb8c20199134b295fb716b174 + JPEG + 0 + fd46378c + + f83b0cd54326fad99bcb9f220f043dbb + openStack + file + 2013-12-12T08:16:45-0800 + + + + + 8c0345bd + 14933 + /usr/local/tomcat/temp + image-icon + + 1f82dc3a8a5a1b959d4d94ac76da3111 + jhovetmp4690185074321915308.jpg + 0 + image/jpeg + openStack + 73c77d84699460c8d3bccc03534fc5f751a60d82 + 2013-12-12T08:16:55-0800 + 65x43 + JPEG + full + 1.01 + file + + + + + f376fa85ff01264a9022e7d906ce255f + fcbee4fd + /pub/data1/dams_staging/rci/staging/siogeocoll/PPTU_RCI_Apr2013_Bag/data/PPTU/Dredge_Photos + pptu04wt-027d_dredgephotograph_001.jpg + 2ac7a5e5917798e56cd0ab41a241a1ea24f96f49 + 0 + file + + image-source + 2013-04-17T02:18:11-0700 + 2348655 + 3504x2336 + JPEG + openStack + image/jpeg + full + + + + + data + + + + + + + Files + + + Files + + + 2 + + + + + -17.615,-176.033 -17.6,-176 + WGS84 + + + + + + IGSN + identifier + SIO001701 + + + + + + local attribution + digital object made available by + Research Data Curation Program, UC San Diego, La Jolla, 92093-0175 (https://lib.ucsd.edu/rdcp) + + + + + + water depth + material details + 2487-2402 meters + + + + + 1986-01-20 + 1986-01-20 + 1986-01-20 + w3cdtf + creation + + + + + 1 + + + Interval 1 (dredge, rock) + + + Interval 1 (dredge, rock) + + + + + + + 20LBS. PUMICE,BUFF/TAN SILTSTONE, ALTERED BASALT. + description + + + + + + thale-cress componentt + + + thale-cress component + + + + + + + weathering - light + material details + rock weather/metamorphism + + + + + no glass + material details + rock glass and Mn/Fe oxide + + + + + + + storage method + material details + room temperature, dry + + + + data + + + + + + Test Object with metadataOnly Display + + + Test Object with metadataOnly Display + + + + + thale-cress + + + thale-cress + + + + + + + sample number + identifier + PPTU04WT-027D + + + + + + Public domain + us + + + + + + + + + + diff --git a/spec/fixtures/damsComplexObject3.rdf.xml b/spec/fixtures/damsComplexObject3.rdf.xml index e0e2b3ce4..29fed97a8 100644 --- a/spec/fixtures/damsComplexObject3.rdf.xml +++ b/spec/fixtures/damsComplexObject3.rdf.xml @@ -321,6 +321,8 @@ us + +