From b3227b2162ea14ebd21a315018070fae7d979d56 Mon Sep 17 00:00:00 2001 From: Nick Budak Date: Wed, 12 Jun 2024 14:31:57 -0700 Subject: [PATCH] Rework implementation for license display --- app/controllers/catalog_controller.rb | 2 +- .../earthworks_geoblacklight_helper.rb | 7 +++ app/models/concerns/license_concern.rb | 12 ++++ app/models/solr_document.rb | 1 + config/licenses.yml | 60 +++++++++++++++++++ lib/license.rb | 22 +++++++ spec/features/copyright_license_spec.rb | 25 -------- spec/features/license_spec.rb | 33 ++++++++++ spec/features/stanford_new_rights_spec.rb | 18 ------ 9 files changed, 136 insertions(+), 44 deletions(-) create mode 100644 app/models/concerns/license_concern.rb create mode 100644 config/licenses.yml create mode 100644 lib/license.rb delete mode 100644 spec/features/copyright_license_spec.rb create mode 100644 spec/features/license_spec.rb delete mode 100644 spec/features/stanford_new_rights_spec.rb diff --git a/app/controllers/catalog_controller.rb b/app/controllers/catalog_controller.rb index 8430fc3e..ebfd024b 100644 --- a/app/controllers/catalog_controller.rb +++ b/app/controllers/catalog_controller.rb @@ -179,7 +179,7 @@ class CatalogController < ApplicationController # config.add_show_field Settings.FIELDS.FORMAT, label: 'Format', itemprop: 'format' config.add_show_field Settings.FIELDS.RIGHTS, label: 'Use and Reproduction', itemprop: 'rights' config.add_show_field Settings.FIELDS.RIGHTS_HOLDER, label: 'Copyright', itemprop: 'rights_holder' - config.add_show_field Settings.FIELDS.LICENSE, label: 'License', itemprop: 'license' + config.add_show_field Settings.FIELDS.LICENSE, label: 'License', itemprop: 'license', helper_method: :render_license config.add_show_field( Settings.FIELDS.IDENTIFIER, label: 'More details at', diff --git a/app/helpers/earthworks_geoblacklight_helper.rb b/app/helpers/earthworks_geoblacklight_helper.rb index 4ee79585..c8f36b02 100644 --- a/app/helpers/earthworks_geoblacklight_helper.rb +++ b/app/helpers/earthworks_geoblacklight_helper.rb @@ -13,6 +13,13 @@ def render_value_as_truncate_abstract(args) end end + # Try to render a human-readable license description, or fall back to the URI + def render_license(args) + tag.span @document.license.description + rescue License::UnknownLicenseError + tag.span args[:value] + end + # Use Mirador as the IIIF manifest viewer def iiif_manifest_viewer tag.div(nil, id: 'mirador', data: { 'manifest-url' => @document.viewer_endpoint }) diff --git a/app/models/concerns/license_concern.rb b/app/models/concerns/license_concern.rb new file mode 100644 index 00000000..5f725796 --- /dev/null +++ b/app/models/concerns/license_concern.rb @@ -0,0 +1,12 @@ +# frozen_string_literal: true + +# Custom handling for license URIs +module LicenseConcern + extend Geoblacklight::SolrDocument + + # Use the first URI in the license field to create a License object + def license + license_uris = fetch(:dct_license_sm, []) + License.new(url: license_uris.first) + end +end diff --git a/app/models/solr_document.rb b/app/models/solr_document.rb index 9e12222a..2dfa5414 100644 --- a/app/models/solr_document.rb +++ b/app/models/solr_document.rb @@ -4,6 +4,7 @@ class SolrDocument # include GeomonitorConcern # https://github.com/geoblacklight/geo_monitor/issues/12 include WmsRewriteConcern + include LicenseConcern alias stanford? same_institution? diff --git a/config/licenses.yml b/config/licenses.yml new file mode 100644 index 00000000..701e61d0 --- /dev/null +++ b/config/licenses.yml @@ -0,0 +1,60 @@ +production: + https://www.apache.org/licenses/LICENSE-2.0: + description: "This work is licensed under an Apache License 2.0." + https://opensource.org/licenses/BSD-2-Clause: + description: 'This work is licensed under a BSD 2-Clause "Simplified" License.' + https://opensource.org/licenses/BSD-3-Clause: + description: 'This work is licensed under a BSD 3-Clause "New" or "Revised" License.' + https://creativecommons.org/licenses/by/3.0/legalcode: + description: "This work is licensed under a Creative Commons Attribution 3.0 Unported license (CC BY)." + https://creativecommons.org/licenses/by/4.0/legalcode: + description: "This work is licensed under a Creative Commons Attribution 4.0 International license (CC BY)." + https://creativecommons.org/licenses/by-nc/3.0/legalcode: + description: "This work is licensed under a Creative Commons Attribution Non Commercial 3.0 Unported license (CC BY-NC)." + https://creativecommons.org/licenses/by-nc/4.0/legalcode: + description: "This work is licensed under a Creative Commons Attribution Non Commercial 4.0 International license (CC BY-NC)." + https://creativecommons.org/licenses/by-nc-nd/3.0/legalcode: + description: "This work is licensed under a Creative Commons Attribution Non Commercial No Derivatives 3.0 Unported license (CC BY-NC-ND)." + https://creativecommons.org/licenses/by-nc-nd/4.0/legalcode: + description: "This work is licensed under a Creative Commons Attribution Non Commercial No Derivatives 4.0 International license (CC BY-NC-ND)." + https://creativecommons.org/licenses/by-nc-sa/3.0/legalcode: + description: "This work is licensed under a Creative Commons Attribution Non Commercial Share Alike 3.0 Unported license (CC BY-NC-SA)." + https://creativecommons.org/licenses/by-nc-sa/4.0/legalcode: + description: "This work is licensed under a Creative Commons Attribution Non Commercial Share Alike 4.0 International license (CC BY-NC-SA)." + https://creativecommons.org/licenses/by-nd/4.0/legalcode: + description: "This work is licensed under a Creative Commons Attribution No Derivatives 4.0 International license (CC BY-ND)." + https://creativecommons.org/licenses/by-sa/3.0/legalcode: + description: "This work is licensed under a Creative Commons Attribution Share Alike 3.0 Unported license (CC BY-SA)." + https://creativecommons.org/licenses/by-sa/4.0/legalcode: + description: "This work is licensed under a Creative Commons Attribution Share Alike 4.0 International license (CC BY-SA)." + https://creativecommons.org/licenses/by-nd/3.0/legalcode: + description: "This work is licensed under a Creative Commons Attribution No Derivatives 3.0 Unported license (CC BY-ND)." + https://creativecommons.org/publicdomain/zero/1.0/legalcode: + description: "This work is licensed under a Creative Commons Zero v1.0 Universal license (CC0)." + https://opensource.org/licenses/cddl1: + description: "This work is licensed under a Common Development and Distribution License 1.0." + https://www.eclipse.org/legal/epl-2.0: + description: "This work is licensed under an Eclipse Public License 2.0." + https://www.gnu.org/licenses/agpl.txt: + description: "This work is licensed under a GNU Affero General Public License v3.0 only." + https://www.gnu.org/licenses/gpl-3.0-standalone.html: + description: "This work is licensed under a GNU General Public License v3.0 only." + https://www.gnu.org/licenses/lgpl-3.0-standalone.html: + description: "This work is licensed under a GNU Lesser General Public License v3.0 only." + https://www.isc.org/downloads/software-support-policy/isc-license/: + description: "This work is licensed under an ISC License." + https://opensource.org/licenses/MIT: + description: "This work is licensed under an MIT License." + https://www.mozilla.org/MPL/2.0/: + description: "This work is licensed under a Mozilla Public License 2.0." + https://opendatacommons.org/licenses/by/1-0/: + description: "This work is licensed under an Open Data Commons Attribution License v1.0." + http://opendatacommons.org/licenses/odbl/1.0/: + # This is a non-canonical url found in some existing data. It redirects to # https://opendatacommons.org/licenses/odbl/1-0/ + description: "This work is licensed under an Open Data Commons Open Database License v1.0." + https://opendatacommons.org/licenses/odbl/1-0/: + description: "This work is licensed under an Open Data Commons Open Database License v1.0." + https://opendatacommons.org/licenses/pddl/1-0/: + description: "This work is licensed under an Open Data Commons Public Domain Dedication & License 1.0." + https://creativecommons.org/publicdomain/mark/1.0/: + description: "This work has been identified as being free of known restrictions under copyright law, including all related and neighboring rights (Public Domain Mark 1.0)." diff --git a/lib/license.rb b/lib/license.rb new file mode 100644 index 00000000..5eded02f --- /dev/null +++ b/lib/license.rb @@ -0,0 +1,22 @@ +# frozen_string_literal: true + +# This is the license entity used for translating a license URL into text +# that is rendered on an item's show page +class License + attr_reader :description, :uri + + # Raised when the license provided is not valid + class UnknownLicenseError < StandardError; end + + def self.licenses + @licenses ||= Rails.application.config_for(:licenses, env: 'production').stringify_keys + end + + def initialize(url:) + raise UnknownLicenseError unless License.licenses.key?(url) + + attrs = License.licenses.fetch(url) + @uri = url + @description = attrs.fetch(:description) + end +end diff --git a/spec/features/copyright_license_spec.rb b/spec/features/copyright_license_spec.rb deleted file mode 100644 index d0115fc5..00000000 --- a/spec/features/copyright_license_spec.rb +++ /dev/null @@ -1,25 +0,0 @@ -require 'rails_helper' - -# rubocop:disable Layout/LineLength -describe 'Use and reproduction, copyright and license' do - it 'Stanford restricted' do - visit solr_document_path 'stanford-cg357zz0321' - expect(page).to have_css 'dt', text: 'Use and reproduction' - expect(page).to have_css 'dd', - text: 'These data are licensed by Stanford Libraries and are available to Stanford University affiliates only. Affiliates are limited to current faculty, staff and students. These data may not be reproduced or used for any purpose without permission. For more information please contact brannerlibrary@stanford.edu.' - expect(page).to have_css 'dt', text: 'Copyright' - expect(page).to have_css 'dd', text: 'Copyright ownership resides with the originator.' - end - - it 'Stanford public' do - visit solr_document_path 'stanford-cz128vq0535' - expect(page).to have_css 'dt', text: 'Use and reproduction' - expect(page).to have_css 'dd', text: 'This item is in the public domain. There are no restrictions on use.' - expect(page).to have_css 'dt', text: 'Copyright' - expect(page).to have_css 'dd', - text: 'This work is in the Public Domain, meaning that it is not subject to copyright.' - expect(page).to have_css 'dt', text: 'License' - expect(page).to have_css 'dd', text: 'Attribution Share Alike 3.0 Unported' - end -end -# rubocop:enable Layout/LineLength diff --git a/spec/features/license_spec.rb b/spec/features/license_spec.rb new file mode 100644 index 00000000..dfbe2c11 --- /dev/null +++ b/spec/features/license_spec.rb @@ -0,0 +1,33 @@ +# frozen_string_literal: true + +require 'rails_helper' + +# rubocop:disable Layout/LineLength +describe 'License rendering' do + context 'with a CC license' do + it 'renders the human-friendly license description' do + visit solr_document_path 'stanford-dy750qs3024' + expect(page).to have_css 'dt', text: 'License' + expect(page).to have_css 'dd', + text: 'This work is licensed under a Creative Commons Attribution Non Commercial 3.0 Unported license (CC BY-NC).' + end + end + + context 'with an ODC license' do + it 'renders the human-friendly license description' do + visit solr_document_path 'stanford-cj936rq6257' + expect(page).to have_css 'dt', text: 'License' + expect(page).to have_css 'dd', + text: 'This work is licensed under an Open Data Commons Open Database License v1.0.' + end + end + + context 'with an unknown license' do + it 'renders the license URI' do + visit solr_document_path 'harvard-g7064-s2-1834-k3' + expect(page).to have_css 'dt', text: 'License' + expect(page).to have_css 'dd', text: 'example.com/license' + end + end +end +# rubocop:enable Layout/LineLength diff --git a/spec/features/stanford_new_rights_spec.rb b/spec/features/stanford_new_rights_spec.rb deleted file mode 100644 index da97b9e6..00000000 --- a/spec/features/stanford_new_rights_spec.rb +++ /dev/null @@ -1,18 +0,0 @@ -require 'rails_helper' - -describe 'Stanford licenses done the new way' do - it 'renders page with rights information and the license logo' do - visit solr_document_path 'stanford-dy750qs3024' - # rubocop:disable Layout/LineLength - expect(page).to have_css 'dt', text: 'License' - expect(page).to have_link 'This work is licensed under a Creative Commons Attribution-Noncommercial 3.0 Unported License', - href: 'http://creativecommons.org/licenses/by-nc/3.0/' - expect(page).to have_css 'dt', text: 'Use and reproduction' - expect(page).to have_css 'dd', - text: 'Image from the Map Collections courtesy Stanford University Libraries. If you have questions, please contact the Branner Earth Science Library & Map Collections at brannerlibrary@stanford.edu.' - expect(page).to have_css 'dt', text: 'Copyright' - expect(page).to have_css 'dd', - text: 'Property rights reside with the repository. Copyright © Stanford University. All Rights Reserved.' - # rubocop:enable Layout/LineLength - end -end