Skip to content

Commit

Permalink
Prevent non-URLs from being hyperlinked in dct_identifier_sm
Browse files Browse the repository at this point in the history
Fixes #1399
  • Loading branch information
thatbudakguy committed Sep 12, 2024
1 parent 18ee5d6 commit adab6c1
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 4 deletions.
4 changes: 2 additions & 2 deletions app/controllers/catalog_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
)

Expand Down
2 changes: 1 addition & 1 deletion app/helpers/earthworks_blacklight_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 4 additions & 0 deletions app/models/solr_document.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 8 additions & 1 deletion spec/features/more_details_spec.rb
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit adab6c1

Please sign in to comment.