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

Commit b257a2d

Browse files
VivianChuhweng
authored andcommitted
Fix mixed collection search query
Fix thumbnail issue Fix failed test Fix pdf download issue Fix failed tests Fix pdf file download Test Fix failed test Remove access label for local user for search/browse by collection page Remove access label for single collection and object view for metadata-only collection Fix access label issue Refactor display access label function Fix build error Update display access label function and test
1 parent 7f74f34 commit b257a2d

File tree

9 files changed

+226
-58
lines changed

9 files changed

+226
-58
lines changed

app/controllers/catalog_controller.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -321,8 +321,7 @@ def collection_search
321321

322322
def metadata_only_collections(params)
323323
meta_colls = []
324-
solr_params = {}
325-
solr_params[:fq] = ["{!join from=collections_tesim to=id}#{metadata_only_fquery}"]
324+
solr_params = { q: "{!join from=collections_tesim to=id}#{metadata_only_fquery}", fq: 'type_tesim:Collection', rows: 300 }
326325
response = raw_solr(solr_params.merge(params))
327326
response.docs.each do |doc|
328327
mix_obj = mix_objects?(doc['id_t'], metadata_obj_count(doc['id_t']))

app/helpers/catalog_helper.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -96,14 +96,14 @@ def date_list( document )
9696
dateVal
9797
end
9898

99-
def display_access_control_level(document, metadata_colls)
99+
def display_access_control_level(document, metadata_colls, mix_obj, meta_only_obj)
100100
access_group = document['read_access_group_ssim'] # "public" > "local" > "dams-curator" == "dams-rci" == default
101101
view_access = 'Curator Only'
102102
if access_group
103-
if metadata_colls.include?("#{document['id']}true")
104-
view_access = 'Some items restricted'
105-
elsif metadata_colls.include?(document['id']) || metadata_display?(rights_data(document))
106-
view_access = 'Restricted View'
103+
if metadata_colls.include?("#{document['id']}true") || mix_obj
104+
view_access = hide_label?(document) ? nil : 'Some items restricted'
105+
elsif metadata_colls.include?(document['id']) || meta_only_obj
106+
view_access = hide_label?(document) ? nil : 'Restricted View'
107107
elsif access_group.include?('public')
108108
view_access = nil
109109
elsif access_group.include?('local')
@@ -147,7 +147,7 @@ def restricted_object_url()
147147
def object_thumbnail_url(document)
148148
restricted_view = metadata_display?(rights_data(document))
149149
return nil unless restricted_view || (has_thumbnail?(document) && thumbnail_url(document, nil))
150-
if restricted_view
150+
if restricted_view && cannot?(:read, document)
151151
url = 'https://library.ucsd.edu/assets/dams/site/thumb-restricted.png'
152152
image_tag(url, alt: '', class: 'dams-search-thumbnail')
153153
else
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<% acl = display_access_control_level(document, metadata_colls) %>
1+
<% acl = display_access_control_level(document, metadata_colls, false, metadata_display?(rights_data(document))) %>
22
<% if acl != nil %>
33
<li><span class="dams-search-results-fields-label">Access:</span> <span><%= acl %></span></li>
44
<% end %>

app/views/dams_objects/_data_viewer.html.erb

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,12 @@
1313
%>
1414

1515
<div class="form-actions dams-download-button">
16-
<a id="data-view-file" class="btn <%=btnColor%> pull-right" href="<%= viewFilePath %>"><i class="glyphicon glyphicon-eye-open icon-white"></i> View file</a>
17-
<a id="data-download-file" class="btn btn-link pull-left btn-mini hidden-phone" href="<%= filePath %>" rel="nofollow"><i class="glyphicon glyphicon-download-alt"></i> Download file</a>
18-
<a id="data-download-file-phone" class="btn pull-left btn-mini visible-phone" href="<%= filePath %>" rel="nofollow"><i class="glyphicon glyphicon-download-alt"></i> Download file</a>
19-
<% if can? :update, @document%>
16+
<% if can?(:edit, @document) || can?(:read, @document) && can_download?(@document)%>
17+
<a id="data-view-file" class="btn <%=btnColor%> pull-right" href="<%= viewFilePath %>"><i class="glyphicon glyphicon-eye-open icon-white"></i> View file</a>
18+
<a id="data-download-file" class="btn btn-link pull-left btn-mini hidden-phone" href="<%= filePath %>" rel="nofollow"><i class="glyphicon glyphicon-download-alt"></i> Download file</a>
19+
<a id="data-download-file-phone" class="btn pull-left btn-mini visible-phone" href="<%= filePath %>" rel="nofollow"><i class="glyphicon glyphicon-download-alt"></i> Download file</a>
20+
<% end %>
21+
<% if can? :update, @document%>
2022
<% if (defined?(sourcefilePath) && !sourcefilePath.nil? && sourcefilePath != filePath)%>
2123
<a class="btn btn-link pull-left btn-mini hidden-phone" href="<%= sourcefilePath %>" rel="nofollow"><i class="glyphicon glyphicon-download-alt"></i> Download <%= File.extname(sourcefilePath.gsub('/download','')).upcase.gsub('.','')%> source</a>
2224
<a class="btn pull-left btn-mini visible-phone" href="<%= sourcefilePath %>" rel="nofollow"><i class="glyphicon glyphicon-download-alt"></i> Download <%= File.extname(sourcefilePath.gsub('/download','')).upcase.gsub('.','')%> source</a>
Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,13 @@
11
<%
22
htmlOpen = "<dt>%s</dt><dd><ul>"
33
htmlClose = '</ul></dd>'
4-
accessGroup = @document['read_access_group_ssim'] # "public" > "local" > "dams-curator" == "dams-rci" == default
5-
viewAccess = nil
64

7-
if accessGroup != nil
5+
viewAccess = display_access_control_level(@document, [], @mix_objects, @metadata_only)
86

9-
if @mix_objects
10-
viewAccess = 'Some items restricted'
11-
elsif @metadata_only
12-
viewAccess = 'Restricted View'
13-
elsif accessGroup.include?('public')
14-
viewAccess = :public
15-
elsif accessGroup.include?('local')
16-
viewAccess = 'Restricted to UC San Diego use only'
17-
else
18-
viewAccess = 'Curator Only'
19-
end
20-
21-
if viewAccess != :public
22-
htmlOpen %= 'Access'
23-
concat htmlOpen.html_safe
24-
concat "<li>#{viewAccess}</li>".html_safe
25-
concat htmlClose.html_safe
26-
end
27-
28-
end
7+
if viewAccess
8+
htmlOpen %= 'Access'
9+
concat htmlOpen.html_safe
10+
concat "<li>#{viewAccess}</li>".html_safe
11+
concat htmlClose.html_safe
12+
end
2913
%>

lib/dams/controller_helper.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -898,6 +898,21 @@ def referrer_controller( request )
898898
end
899899
end
900900

901+
def hide_label?(document)
902+
cannot?(:edit, document) && can?(:read, document) && (local_display?(rights_data(document)) || local_collection?(document))
903+
end
904+
905+
def local_collection?(document)
906+
data = (Array(document['collection_json_tesim']) + Array(document['visibility_tesim'])).flatten.compact
907+
return false if data.blank?
908+
data.any? { |t| t.include?('local')}
909+
end
910+
911+
def local_display?(data)
912+
return false if data.blank?
913+
data.any? { |t| t.include?('localDisplay') }
914+
end
915+
901916
def metadata_display?(data)
902917
return false if data.blank?
903918
data.any? { |t| t.include?('localDisplay') || t.include?('metadataDisplay') }

spec/features/catalog_spec.rb

Lines changed: 78 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -518,12 +518,26 @@
518518
@localOnlyCollection.delete
519519
@localObj.delete
520520
end
521-
scenario 'rendering the grey generic thumbnail and restricted access info' do
522-
sign_in_developer
521+
522+
scenario 'public user should see the grey generic thumbnail and restricted access info' do
523523
visit catalog_index_path({:q => 'xx909090zz'})
524524
expect(page).to have_css('img.dams-search-thumbnail[src="https://library.ucsd.edu/assets/dams/site/thumb-restricted.png"]')
525525
expect(page).to have_content('Restricted View')
526526
end
527+
528+
scenario 'curator user should not see the grey generic thumbnail and still see restricted access info' do
529+
sign_in_developer
530+
visit catalog_index_path({:q => 'xx909090zz'})
531+
expect(page).to_not have_css('img.dams-search-thumbnail[src="https://library.ucsd.edu/assets/dams/site/thumb-restricted.png"]')
532+
expect(page).to have_content('Restricted View')
533+
end
534+
535+
scenario 'local user should not see the grey generic thumbnail and restricted access info' do
536+
sign_in_anonymous '132.239.0.3'
537+
visit catalog_index_path({:q => 'xx909090zz'})
538+
expect(page).to_not have_css('img.dams-search-thumbnail[src="https://library.ucsd.edu/assets/dams/site/thumb-restricted.png"]')
539+
expect(page).to_not have_content('Restricted View')
540+
end
527541
end
528542

529543
feature 'Visitor wants to view localDisplay License object in UCSD local collection in the search result page' do
@@ -544,8 +558,21 @@
544558
@localOnlyCollection.delete
545559
@localObj.delete
546560
end
547-
scenario 'rendering the grey generic thumbnail and restricted access info' do
561+
scenario 'curator user should not see the grey generic thumbnail and still see restricted access info' do
548562
sign_in_developer
563+
visit catalog_index_path({:q => @localObj.pid})
564+
expect(page).to_not have_css('img.dams-search-thumbnail[src="https://library.ucsd.edu/assets/dams/site/thumb-restricted.png"]')
565+
expect(page).to have_content('Restricted View')
566+
end
567+
568+
scenario 'local user should not see the grey generic thumbnail and restricted access info' do
569+
sign_in_anonymous '132.239.0.3'
570+
visit catalog_index_path({:q => @localObj.pid})
571+
expect(page).to_not have_css('img.dams-search-thumbnail[src="https://library.ucsd.edu/assets/dams/site/thumb-restricted.png"]')
572+
expect(page).to_not have_content('Restricted View')
573+
end
574+
575+
scenario 'public user should see the grey generic thumbnail and restricted access info' do
549576
visit catalog_index_path({:q => @localObj.pid})
550577
expect(page).to have_css('img.dams-search-thumbnail[src="https://library.ucsd.edu/assets/dams/site/thumb-restricted.png"]')
551578
expect(page).to have_content('Restricted View')
@@ -567,7 +594,7 @@
567594
@note = DamsNote.create type: "local attribution", value: "Digital Library Development Program, UC San Diego, La Jolla, 92093-0175"
568595
@localDisplay = DamsOtherRight.create permissionType: "localDisplay"
569596
@publicCollection = DamsProvenanceCollection.create titleValue: "Test Public Collection", visibility: "public"
570-
@localObj = DamsObject.create pid: 'xx909090zz', titleValue: 'Test Object with localDisplay', provenanceCollectionURI: @publicCollection.pid, otherRightsURI: @localDisplay.pid, note_attributes: [{ id: RDF::URI.new("#{ns}#{@note.pid}") }], copyright_attributes: [{status: 'Public domain'}]
597+
@localObj = DamsObject.create pid: 'xx909090zz', titleValue: 'Test Object with localDisplay', provenanceCollectionURI: @publicCollection.pid, otherRightsURI: @localDisplay.pid, note_attributes: [{ id: RDF::URI.new("#{ns}#{@note.pid}") }], copyright_attributes: [{status: 'Under Copyright'}]
571598
solr_index @note.pid
572599
solr_index @localDisplay.pid
573600
solr_index @publicCollection.pid
@@ -586,17 +613,60 @@
586613
expect(page).to have_content('Restricted View')
587614
end
588615

589-
scenario 'local user should see the grey generic thumbnail and restricted access info' do
616+
scenario 'local user should not see the grey generic thumbnail and still see restricted access info' do
590617
sign_in_anonymous '132.239.0.3'
591618
visit catalog_index_path({:q => 'xx909090zz'})
592-
expect(page).to have_css('img.dams-search-thumbnail[src="https://library.ucsd.edu/assets/dams/site/thumb-restricted.png"]')
593-
expect(page).to have_content('Restricted View')
619+
expect(page).to_not have_css('img.dams-search-thumbnail[src="https://library.ucsd.edu/assets/dams/site/thumb-restricted.png"]')
620+
expect(page).to_not have_content('Restricted View')
594621
end
595622

596-
scenario 'curator user should see the grey generic thumbnail and restricted access info' do
623+
scenario 'curator user should not see the grey generic thumbnail and still see restricted access info' do
597624
sign_in_developer
598625
visit catalog_index_path({:q => 'xx909090zz'})
626+
expect(page).to_not have_css('img.dams-search-thumbnail[src="https://library.ucsd.edu/assets/dams/site/thumb-restricted.png"]')
627+
expect(page).to have_content('Restricted View')
628+
end
629+
end
630+
631+
feature 'Visitor wants to view metdatadataDisplay object for public collection in the search result page' do
632+
before(:all) do
633+
ns = Rails.configuration.id_namespace
634+
@note = DamsNote.create type: "local attribution", value: "Digital Library Development Program, UC San Diego, La Jolla, 92093-0175"
635+
@metadataDisplay = DamsOtherRight.create permissionType: "metadataDisplay"
636+
@publicCollection = DamsProvenanceCollection.create titleValue: "Test Public Collection", visibility: "public"
637+
@obj = DamsObject.create pid: 'xx909090yy', titleValue: 'Test Object with localDisplay', note_attributes: [{ id: RDF::URI.new("#{ns}#{@note.pid}") }], copyright_attributes: [{status: 'Under Copyright'}]
638+
@obj.otherRightsURI = @metadataDisplay.pid
639+
@obj.provenanceCollectionURI = @publicCollection.pid
640+
@obj.save
641+
solr_index @note.pid
642+
solr_index @metadataDisplay.pid
643+
solr_index @publicCollection.pid
644+
solr_index @obj.pid
645+
end
646+
after(:all) do
647+
@note.delete
648+
@metadataDisplay.delete
649+
@publicCollection.delete
650+
@obj.delete
651+
end
652+
653+
scenario 'public user should see the grey generic thumbnail and restricted access info' do
654+
visit catalog_index_path({:q => 'xx909090yy'})
655+
expect(page).to have_css('img.dams-search-thumbnail[src="https://library.ucsd.edu/assets/dams/site/thumb-restricted.png"]')
656+
expect(page).to have_content('Restricted View')
657+
end
658+
659+
scenario 'local user should see the grey generic thumbnail and still see restricted access info' do
660+
sign_in_anonymous '132.239.0.3'
661+
visit catalog_index_path({:q => 'xx909090yy'})
599662
expect(page).to have_css('img.dams-search-thumbnail[src="https://library.ucsd.edu/assets/dams/site/thumb-restricted.png"]')
600663
expect(page).to have_content('Restricted View')
601664
end
665+
666+
scenario 'curator user should not see the grey generic thumbnail and still see restricted access info' do
667+
sign_in_developer
668+
visit catalog_index_path({:q => 'xx909090yy'})
669+
expect(page).to_not have_css('img.dams-search-thumbnail[src="https://library.ucsd.edu/assets/dams/site/thumb-restricted.png"]')
670+
expect(page).to have_content('Restricted View')
671+
end
602672
end

spec/features/dams_collections_spec.rb

Lines changed: 63 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -387,12 +387,12 @@
387387
@obj.delete
388388
end
389389

390-
scenario 'should see Restricted View access control information' do
390+
scenario 'local user should not see Restricted View access label' do
391391
sign_in_anonymous '132.239.0.3'
392392
visit dams_collection_path @metadataOnlyCollection.pid
393-
expect(page).to have_content('Restricted View')
393+
expect(page).to_not have_content('Restricted View')
394394
visit dams_collection_path @localOnlyCollection.pid
395-
expect(page).to have_content('Restricted View')
395+
expect(page).to_not have_content('Restricted View')
396396
end
397397

398398
scenario 'should not see Restricted View access control information' do
@@ -401,10 +401,10 @@
401401
expect(page).to_not have_content('Restricted View')
402402
end
403403

404-
scenario 'should see Restricted View access control information when visit browse by collection page' do
404+
scenario 'local user should not see Restricted View access label when visit browse by collection page' do
405405
sign_in_anonymous '132.239.0.3'
406406
visit '/collections'
407-
expect(page).to have_content('Restricted View')
407+
expect(page).to_not have_content('Restricted View')
408408
end
409409
end
410410

@@ -445,7 +445,7 @@
445445
expect(page).to have_content('Restricted View')
446446
end
447447

448-
scenario 'local user should see Restricted View access control information when visit browse by collection page' do
448+
scenario 'local user should see Restricted View access label when visit browse by collection page' do
449449
sign_in_anonymous '132.239.0.3'
450450
visit '/collections'
451451
expect(page).to have_content('Restricted View')
@@ -501,10 +501,27 @@
501501

502502
scenario 'public user should see some items restricted access information when search for collection' do
503503
visit catalog_index_path( {:q => @publicCollection.pid} )
504-
puts "collection id #{@publicCollection.pid}"
505504
expect(page).to_not have_content('Restricted View')
506505
expect(page).to have_content('Some items restricted')
507-
end
506+
end
507+
508+
scenario 'local user should see access label when visit browse by collection page or search for collection' do
509+
sign_in_anonymous '132.239.0.3'
510+
visit '/collections'
511+
expect(page).to have_content('Some items restricted')
512+
513+
visit catalog_index_path( {:q => @publicCollection.pid} )
514+
expect(page).to have_content('Some items restricted')
515+
end
516+
517+
scenario 'curator user should see access label when visit browse by collection page or search for collection' do
518+
sign_in_developer
519+
visit '/collections'
520+
expect(page).to have_content('Some items restricted')
521+
522+
visit catalog_index_path( {:q => @publicCollection.pid} )
523+
expect(page).to have_content('Some items restricted')
524+
end
508525
end
509526

510527
feature "Visitor wants to view a local collection's page with mixed objects" do
@@ -548,6 +565,26 @@
548565
visit catalog_index_path( {:q => @localCollection.pid} )
549566
expect(page).to_not have_content('Restricted View')
550567
expect(page).to have_content('Some items restricted')
568+
end
569+
570+
scenario 'local user should not see access label when visit browse by collection page or search for collection' do
571+
sign_in_anonymous '132.239.0.3'
572+
visit '/collections'
573+
expect(page).to_not have_content('Restricted View')
574+
expect(page).to_not have_content('Some items restricted')
575+
576+
visit catalog_index_path( {:q => @localCollection.pid} )
577+
expect(page).to_not have_content('Restricted View')
578+
expect(page).to_not have_content('Some items restricted')
579+
end
580+
581+
scenario 'curator user should see access label when visit browse by collection page or search for collection' do
582+
sign_in_developer
583+
visit '/collections'
584+
expect(page).to have_content('Some items restricted')
585+
586+
visit catalog_index_path( {:q => @localCollection.pid} )
587+
expect(page).to have_content('Some items restricted')
551588
end
552589
end
553590

@@ -593,4 +630,22 @@
593630
expect(page).to have_content('Restricted View')
594631
expect(page).to_not have_content('Some items restricted')
595632
end
633+
634+
scenario 'local user should see access label when visit browse by collection page or search for collection' do
635+
sign_in_anonymous '132.239.0.3'
636+
visit '/collections'
637+
expect(page).to have_content('Restricted View')
638+
639+
visit catalog_index_path( {:q => @publicCollection.pid} )
640+
expect(page).to have_content('Restricted View')
641+
end
642+
643+
scenario 'curator user should see access label when visit browse by collection page or search for collection' do
644+
sign_in_developer
645+
visit '/collections'
646+
expect(page).to have_content('Restricted View')
647+
648+
visit catalog_index_path( {:q => @publicCollection.pid} )
649+
expect(page).to have_content('Restricted View')
650+
end
596651
end

0 commit comments

Comments
 (0)