From adab6c153f7ae8b4e38c8eeed5f7c49756d538ac Mon Sep 17 00:00:00 2001 From: Nick Budak Date: Thu, 12 Sep 2024 10:35:07 -0700 Subject: [PATCH] Prevent non-URLs from being hyperlinked in dct_identifier_sm Fixes #1399 --- app/controllers/catalog_controller.rb | 4 ++-- app/helpers/earthworks_blacklight_helper.rb | 2 +- app/models/solr_document.rb | 4 ++++ spec/features/more_details_spec.rb | 9 ++++++++- 4 files changed, 15 insertions(+), 4 deletions(-) diff --git a/app/controllers/catalog_controller.rb b/app/controllers/catalog_controller.rb index e1490941..e01ca326 100644 --- a/app/controllers/catalog_controller.rb +++ b/app/controllers/catalog_controller.rb @@ -198,8 +198,8 @@ class CatalogController < ApplicationController config.add_show_field( Settings.FIELDS.IDENTIFIER, label: 'More details at', - accessor: [:identifiers], - if: proc { |_, _, doc| doc.identifiers.any? }, + accessor: [:external_links], + if: proc { |_, _, doc| doc.external_links.any? }, helper_method: :render_details_links ) diff --git a/app/helpers/earthworks_blacklight_helper.rb b/app/helpers/earthworks_blacklight_helper.rb index 2199c574..36aa2fe0 100644 --- a/app/helpers/earthworks_blacklight_helper.rb +++ b/app/helpers/earthworks_blacklight_helper.rb @@ -22,7 +22,7 @@ def sidebar_classes def render_details_links(args) tag.ul class: 'list-unstyled' do - args[:document].identifiers.collect { |identifier| concat tag.li(link_to(identifier, identifier)) } + args[:document].external_links.collect { |url| concat tag.li(link_to(url, url)) } end end end diff --git a/app/models/solr_document.rb b/app/models/solr_document.rb index 8289bf1b..f1fa9b3b 100644 --- a/app/models/solr_document.rb +++ b/app/models/solr_document.rb @@ -32,6 +32,10 @@ def mixed? fetch(Settings.FIELDS.RESOURCE_CLASS, []) == 'Other' end + def external_links + fetch(Settings.FIELDS.IDENTIFIER, []).filter { |identifier| identifier.start_with?('http') } + end + # Examine the list of references (in dct_references_s) to find a "schema.org/relatedLink" # This is going to be the searchworks url if present. # See https://github.com/sul-dlss/searchworks_traject_indexer/pull/1490 diff --git a/spec/features/more_details_spec.rb b/spec/features/more_details_spec.rb index e7d61e45..7d29442f 100644 --- a/spec/features/more_details_spec.rb +++ b/spec/features/more_details_spec.rb @@ -1,11 +1,18 @@ require 'rails_helper' describe 'More detail links' do - context 'when a document has a purl and doi' do + context 'when a document has a purl and doi in its identifiers' do it 'shows them in more details' do visit solr_document_path 'stanford-dy750qs3024' expect(page).to have_link 'https://purl.stanford.edu/dy750qs3024' expect(page).to have_link 'https://doi.org/10.7946/P2Z31V' end end + + context 'when a document has no URLs in its identifiers' do + it 'does not show the more details section' do + visit solr_document_path 'harvard-g7064-s2-1834-k3' + expect(page).to have_no_text 'More details at' + end + end end