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

Commit

Permalink
Add Access note for metadata-only collection to the browse by collect…
Browse files Browse the repository at this point in the history
…ion page

Fix hound violations

Fix hound violation

Fix hound violation

Fix hound issue

Update rubocop

Fix access control failed tests
  • Loading branch information
VivianChu committed Apr 26, 2018
1 parent 84da581 commit 541ab00
Show file tree
Hide file tree
Showing 13 changed files with 48 additions and 28 deletions.
4 changes: 4 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ Style/Documentation:
- 'spec/**/*'
- 'app/**/*'

Style/ConditionalAssignment:
Exclude:
- 'app/helpers/*'

Style/Next:
Enabled: true

Expand Down
18 changes: 16 additions & 2 deletions app/controllers/catalog_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ def exclude_unwanted_records(solr_parameters,user_parameters)
end
# get search results from the solr index
def index

@metadata_colls = metadata_only_collections
if params['q'] != nil
params['q'].gsub!('""','')
single_quote_count = params['q'].to_s.count('"')
Expand Down Expand Up @@ -327,7 +327,7 @@ def index
end
end
def collection_search

@metadata_colls = metadata_only_collections
# if we already have the parameters set below, then redirect to /search
# this allows removing Collections limit, etc.
#if (params[:sort] || (params[:fq] && params[:fq].to_s.include?('{!join')) )
Expand Down Expand Up @@ -362,6 +362,20 @@ def collection_search
session[:search] = search
end

def metadata_only_collections
meta_colls = []
params = { q: 'visibility_tesim:local', fq: 'type_tesim:Collection', spellcheck: 'false' }
response = raw_solr(params)
other_rights_fquery = '(otherRights_tesim:localDisplay OR otherRights_tesim:metadataDisplay)'
response.docs.each do |doc|
collection_solr_params = { q: "collections_tesim:#{doc['id']}", fq: other_rights_fquery, rows: 1, spellcheck: 'false' }
collection_response = raw_solr(collection_solr_params)
metadata_only = !collection_response.response['numFound'].zero?
meta_colls << doc['id_t'].to_s if metadata_only
end
meta_colls
end

def lookup_unit_name( unit_code = "" )
# fetch unit solr record
begin
Expand Down
26 changes: 12 additions & 14 deletions app/helpers/catalog_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,23 +91,21 @@ def date_list( document )
dateVal
end

def display_access_control_level(document)

accessGroup = document['read_access_group_ssim'] # "public" > "local" > "dams-curator" == "dams-rci" == default
viewAccess = nil

if accessGroup != nil

if accessGroup.include?('public')
viewAccess = nil
elsif accessGroup.include?('local')
viewAccess = 'Restricted to UC San Diego use only'
else
viewAccess = 'Curator Only'
def display_access_control_level(document, metadata_colls)
access_group = document['read_access_group_ssim'] # "public" > "local" > "dams-curator" == "dams-rci" == default
view_access = 'Curator Only'
if access_group

if access_group.include?('public')
view_access = nil
elsif access_group.include?('local') && metadata_colls.include?(document['id'])
view_access = 'Restricted View'
elsif access_group.include?('local')
view_access = 'Restricted to UC San Diego use only'
end

end
viewAccess
view_access
end

def is_collection?( document )
Expand Down
2 changes: 1 addition & 1 deletion app/views/catalog/_collection.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<% end %>
<% end %>
<%= render :partial => 'catalog/display_access_control_level', :locals => {:document => document} %>
<%= render :partial => 'catalog/display_access_control_level', :locals => {:document => document, :metadata_colls => metadata_colls} %>
<% dateVal = date_list(document) %>
<% if !dateVal.blank? %>
Expand Down
2 changes: 1 addition & 1 deletion app/views/catalog/_display_access_control_level.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<% acl = display_access_control_level(document) %>
<% acl = display_access_control_level(document, metadata_colls) %>
<% if acl != nil %>
<li><span class="dams-search-results-fields-label">Access:</span> <span><%= acl %></span></li>
<% end %>
2 changes: 1 addition & 1 deletion app/views/catalog/_document.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<%# container for a single doc -%>
<li>
<%= render :partial => 'document_header', :locals => { :document => document, :document_counter => document_counter } %>
<%= render :partial => 'document_header', :locals => { :document => document, :document_counter => document_counter, :metadata_colls => metadata_colls } %>
</li>
2 changes: 1 addition & 1 deletion app/views/catalog/_document_header.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

<%# main container for doc partial view -%>
<% if is_collection?( document ) %>
<%= render :partial => 'collection', :locals => { :document => document } %>
<%= render :partial => 'collection', :locals => { :document => document, :metadata_colls => metadata_colls} %>
<% else %>
<%= render_document_partial document, :index %>
<% end %>
Expand Down
2 changes: 1 addition & 1 deletion app/views/catalog/_document_list.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<%# container for all documents in index view -%>
<ol id="dams-search-results">
<%= render :collection => documents, :as => :document, :partial => 'document' %>
<%= render :collection => documents, :as => :document, :partial => 'document', locals: {:metadata_colls => metadata_colls} %>
</ol>
2 changes: 1 addition & 1 deletion app/views/catalog/_index_default.html.erb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<%# default partial to display solr document fields in catalog index view -%>
<ul class="dams-search-results-fields">

<%= render :partial => 'catalog/display_access_control_level', :locals => {:document => document} %>
<%= render :partial => 'catalog/display_access_control_level', :locals => {:document => document, :metadata_colls => @metadata_colls} %>
<% index_fields.each do |solr_fname, field| -%>
<% if should_render_index_field? document, field %>
Expand Down
3 changes: 1 addition & 2 deletions app/views/catalog/collection_search.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
<%= render 'sort_and_per_page' %>
<%#= render :partial => 'constraints' %>
<h3 class="hide-text"><%= t('blacklight.search.search_results') %></h3>
<%= render_document_index %>
<%= render :partial => 'document_list', locals: {:documents => @document_list, :metadata_colls => @metadata_colls}%>
<%#= render 'results_pagination' %>
<div class="dams-search-results-footer">
<%= render :partial => 'paginate_compact' %>
Expand Down
2 changes: 1 addition & 1 deletion app/views/catalog/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
<%= render 'sort_and_per_page' %>
<%= render :partial => 'spellcheck' %>
<h3 class="hide-text"><%= t('blacklight.search.search_results') %></h3>
<%= render_document_index %>
<%= render :partial => 'document_list', locals: {:documents => @document_list, :metadata_colls => @metadata_colls}%>
<div class="dams-search-results-footer">
<%= render :partial => 'paginate_compact' %>
</div>
Expand Down
5 changes: 2 additions & 3 deletions spec/features/access_control_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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' )
Expand Down
6 changes: 6 additions & 0 deletions spec/features/dams_collections_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -392,4 +392,10 @@
visit dams_collection_path @collection.pid
expect(page).to_not have_content('Restricted View')
end

scenario 'should see Restricted View access control information when visit browse by collection page' do
sign_in_anonymous '132.239.0.3'
visit '/collections'
expect(page).to have_content('Restricted View')
end
end

0 comments on commit 541ab00

Please sign in to comment.