Skip to content

Commit

Permalink
Rework implementation for license display
Browse files Browse the repository at this point in the history
  • Loading branch information
thatbudakguy committed Jun 28, 2024
1 parent 31111d7 commit b3227b2
Show file tree
Hide file tree
Showing 9 changed files with 136 additions and 44 deletions.
2 changes: 1 addition & 1 deletion app/controllers/catalog_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
7 changes: 7 additions & 0 deletions app/helpers/earthworks_geoblacklight_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 })
Expand Down
12 changes: 12 additions & 0 deletions app/models/concerns/license_concern.rb
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions app/models/solr_document.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ class SolrDocument
# include GeomonitorConcern
# https://github.com/geoblacklight/geo_monitor/issues/12
include WmsRewriteConcern
include LicenseConcern

alias stanford? same_institution?

Expand Down
60 changes: 60 additions & 0 deletions config/licenses.yml
Original file line number Diff line number Diff line change
@@ -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)."
22 changes: 22 additions & 0 deletions lib/license.rb
Original file line number Diff line number Diff line change
@@ -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
25 changes: 0 additions & 25 deletions spec/features/copyright_license_spec.rb

This file was deleted.

33 changes: 33 additions & 0 deletions spec/features/license_spec.rb
Original file line number Diff line number Diff line change
@@ -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
18 changes: 0 additions & 18 deletions spec/features/stanford_new_rights_spec.rb

This file was deleted.

0 comments on commit b3227b2

Please sign in to comment.