Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DLC-1152 public assets #229

Merged
merged 7 commits into from
Sep 16, 2024
Merged
2 changes: 1 addition & 1 deletion app/components/dcv/search_bar/default_component.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<%= render_hash_as_hidden_fields(search_action_params) %>
<%- rendering_pagination = pagination_will_render? -%>
<div class="input-group flex-lg-fill flex-nowrap align-content-end">
<div class="btn-group input-group-prepend btn-group-toggle flex-shrink-0" data-toggle="buttons">
<div class="btn-group input-group-prepend btn-group-toggle flex-shrink-0">
<button class="btn btn-splash" type="submit">
<span class="hidden-xs"><%= (current_page?(root_url)? t('blacklight.search.form.submit') : '') %></span>
<span class="fa fa-search"></span>
Expand Down
13 changes: 11 additions & 2 deletions app/controllers/children_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,21 @@ def index
opts = {}
opts[:per_page] = params.fetch('per_page', '10')
opts[:page] = params.fetch('page', '0')
render json: children(params['parent_id'], opts), :content_type => 'application/json' # Yes, content_type seems redundant here, but the header wasn't getting sent.
render json: children(params['parent_id'], opts), content_type: 'application/json' # Yes, content_type seems redundant here, but the header wasn't getting sent.
end
end
end

def show
render json: child(params['id']), :content_type => 'application/json' # Yes, content_type seems redundant here, but the header wasn't getting sent.
render json: child(params['id']), content_type: 'application/json' # Yes, content_type seems redundant here, but the header wasn't getting sent.
end

# shims from Blacklight 6 controller fetch to BL 7 search service
def search_service
Blacklight::SearchService.new(config: blacklight_config, user_params: {})
end

def fetch(id = nil, extra_controller_params = {})
return search_service.fetch(id, extra_controller_params)
end
end
7 changes: 5 additions & 2 deletions app/helpers/field_display_helpers/archival_context.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,11 @@ def display_collection_with_links(args={})
clio = collection.fetch('dc:bibliographicCitation',{})['@id']
if clio
bib_id = clio.split('/')[-1].to_s
fa_url = generate_finding_aid_url(bib_id, document) if bib_id =~ /^\d+$/
value = link_to(value, fa_url) if fa_url
if bib_id =~ /^\d+$/
clio_only = collection.fetch('dc:coverage', []).blank?
fa_url = generate_finding_aid_url(bib_id, document, clio_only)
value = link_to(value, fa_url) if fa_url
end
end
end
value.html_safe
Expand Down
4 changes: 2 additions & 2 deletions app/helpers/field_display_helpers/repository.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ def field_helper_repo_code_value(args = {})
end
end

def generate_finding_aid_url(bib_id, document)
def generate_finding_aid_url(bib_id, document, clio_only = false)
repo_code = field_helper_repo_code_value(document: document)
repo_slug = t("cul.archives.arclight_slug.#{repo_code.downcase.sub('-', '')}") if repo_code
if repo_slug.present? && bib_id
if repo_slug.present? && bib_id && !clio_only
"https://findingaids.library.columbia.edu/ead/#{repo_slug}/ldpd_#{bib_id}"
else
"https://clio.columbia.edu/catalog/#{bib_id}" if bib_id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ OpenSeadragon.IIIFTileSource.prototype.getTileUrl = function( level, x, y ){

/** BEGIN - CUL Changed Code **/
var dcvCdnUrls = <%= DCV_CONFIG['cdn_urls'].inspect %>;
var originalIiifUrlAndResourceUrlPath = this['@id'];
var originalIiifUrlAndResourceUrlPath = this['@id'] || this['id'];
var iiifResourceUrl = originalIiifUrlAndResourceUrlPath;
var iiifResourceUrlPath = null;
dcvCdnUrls.forEach(function(url){
Expand Down
6 changes: 3 additions & 3 deletions app/models/iiif/authz/v2/probe_service/response.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ def token_authorized?
def to_h
probe_response = IIIF_TEMPLATES['v2_probe_response'].deep_dup
probe_response[:id] = route_helper.bytestream_probe_url(catalog_id: @document.id, bytestream_id: bytestream_id)
if @ability_helper.can?(Ability::ACCESS_ASSET, @document) && @ability_helper.reading_room_client?
probe_response.merge!(redirect_location_properties)
elsif token_authorized?
if token_authorized?
probe_response.merge!(redirect_location_properties(token_authorizer))
elsif @ability_helper.can?(Ability::ACCESS_ASSET, @document)
probe_response.merge!(redirect_location_properties)
else
no_token = @authorization.blank?
has_id_policy = @document.fetch('access_control_levels_ssim',[]).include?(ACCESS_LEVEL_AFFILIATION)
Expand Down
2 changes: 1 addition & 1 deletion app/models/iiif/manifest/archive_org_reference.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def thumbnail

def as_json(opts = {})
manifest = {}
manifest['id'] = "https://iiif.archive.org/iiif/2/#{@id}/manifest.json"
manifest['id'] = "https://iiif.archive.org/iiif/3/#{@id}/manifest.json"
manifest['type'] = 'Manifest'
manifest['thumbnail'] = thumbnail
manifest['label'] = @solr_document['title']
Expand Down
51 changes: 51 additions & 0 deletions spec/controllers/children_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
require 'rails_helper'

describe ChildrenController, type: :unit do
let(:child_doc) { {} }
let(:controller) { described_class.new }
let(:params) {
ActionController::Parameters.new(
)
}
let(:remote_ip) { '255.255.255.255' }
let(:request_double) { instance_double('ActionDispatch::Request') }
let(:search_service_double) { instance_double('Blacklight::SearchService') }
before do
allow(request_double).to receive(:host).and_return('localhost')
allow(request_double).to receive(:optional_port)
allow(request_double).to receive(:protocol)
allow(request_double).to receive(:remote_ip).and_return(remote_ip)
allow(request_double).to receive(:path_parameters).and_return({})
allow(request_double).to receive(:flash).and_return({})
allow(controller).to receive(:params).and_return(params)
allow(controller).to receive(:request).and_return(request_double)
allow(search_service_double).to receive(:fetch).and_return([{}, child_doc])
allow(controller).to receive(:search_service).and_return(search_service_double)
end

describe '#show' do
let(:child_id) { 'test:child' }
let(:child_doc) { { 'id' => child_id, 'title_ssm' => [child_title] } }
let(:child_thumbnail) { "http://localhost/iiif/2/#{child_id}/full/!768,768/0/native.jpg" }
let(:child_title) { 'test:child title' }
let(:params) {
ActionController::Parameters.new(
parent_id: 'test:parent',
id: 'test:child'
)
}
it do
expect(controller).to receive(:render).with(content_type: 'application/json', json: {
datastreams_ssim: [],
dc_type: nil,
id: child_id,
lib_item_in_context_url_ssm: [],
pid: child_id,
publisher_ssim: [],
thumbnail: child_thumbnail,
title: child_title
})
expect { controller.show }.not_to raise_error
end
end
end
19 changes: 15 additions & 4 deletions spec/helpers/field_display_helpers/archival_context_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,26 @@
id: document_id, archival_context_json_ss: JSON.generate([json]), lib_repo_code_ssim: 'nnc'
}
}
it 'links when the collection has a bib id' do
expect(helper.display_collection_with_links(document: solr_document, value: value).first).to match(/href/)
subject(:display) { helper.display_collection_with_links(document: solr_document, value: value).first }
context 'collection has a bib id' do
it 'links to the finding aid' do
expect(display).to match(/finding/)
end
context 'collection has no further archival context' do
before do
json["dc:coverage"] = []
end
it 'links to clio' do
expect(display).to match(/clio/)
end
end
end
context 'collection has no bib id' do
before do
json["dc:bibliographicCitation"]["@id"] = 'https://clio.columbia.edu/catalog'
json["dc:bibliographicCitation"]["@id"] = 'https://server.columbia.edu/catalog'
end
it 'links when the collection has a bib id' do
expect(helper.display_collection_with_links(document: solr_document, value: value).first).to eql value
expect(display).to eql value
end
end
end
Expand Down
70 changes: 70 additions & 0 deletions spec/models/iiif/authz/v2/probe_service/response_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
require 'rails_helper'

describe Iiif::Authz::V2::ProbeService::Response do
subject(:probe_response) {
_pr = described_class.new(
document: solr_document,
bytestream_id: 'content',
ability_helper: controller,
route_helper: controller,
remote_ip: remote_ip,
authorization: authorization_header
)
_pr.instance_variable_set(:@token_authorizer, token_authorizer)
_pr
}
let(:authorization_header) { "Bearer token.value" }
let(:controller) { instance_double(BytestreamsController) }
let(:remote_ip) { "127.0.0.1" }
let(:solr_document) { SolrDocument.new(solr_hash) }
let(:solr_hash) { {} }
let(:token_authorizer) { instance_double(Iiif::Authz::V2::ProbeService::Response::TokenAuthorizer) }
let(:user) { instance_double(User) }
let(:probe_response_status) { probe_response.to_h[:status] }

before do
allow(controller).to receive(:current_user).and_return(user)
allow(controller).to receive(:bytestream_probe_url)
end

context "authorized without token" do
before do
allow(token_authorizer).to receive(:can_access_asset?).and_return(false)
allow(controller).to receive(:can?).and_return(true)
allow(controller).to receive(:bytestream_content_url)
end
it { expect(probe_response_status).to eql(302) }
end
context "token authorized" do
before do
allow(token_authorizer).to receive(:can_access_asset?).and_return(true)
allow(controller).to receive(:bytestream_content_url)
end
it { expect(probe_response_status).to eql(302) }
end
context "not authorized" do
before do
allow(token_authorizer).to receive(:can_access_asset?).and_return(false)
allow(controller).to receive(:can?).and_return(false)
end
context "not logged in" do
let(:user) { nil }
context "object has id policy" do
let(:solr_hash) {
{
'access_control_levels_ssim' => [Dcv::AccessLevels::ACCESS_LEVEL_AFFILIATION],
}
}
before do
allow(probe_response).to receive(:services)
end
it { expect(probe_response_status).to eql(401) }
end
end
context "no token" do
context "object has id policy" do
it { expect(probe_response_status).to eql(403) }
end
end
end
end
Loading