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

public metadata-only record display for embargo/authenticated items #701

Closed
wants to merge 26 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
cc70840
enable hyrax to create works without files
rococodogs Feb 9, 2021
55f3c37
allow metadata records to be shown for items with discover access
rococodogs Feb 10, 2021
2d21b37
set work.discover_groups = ['public'] unless it's a private item
rococodogs Feb 10, 2021
12323bb
add the ability for embargoed items to be public (metadata only)
rococodogs Feb 10, 2021
8e016c9
add embargo/lease notice to catalog listing header
rococodogs Feb 10, 2021
bfe4289
add specs
rococodogs Feb 15, 2021
ecb3feb
test that pub -> priv removes discover_groups
rococodogs Feb 15, 2021
12fa677
presenters: move common solr doc delegations to base_presenter
rococodogs Feb 17, 2021
3506e9f
:sweat_smile: oops
rococodogs Feb 18, 2021
ec7287f
check a solr_doc's id for permission, not the object
rococodogs Feb 23, 2021
ab731e6
ensure factory file_sets have the right permissions
rococodogs Feb 23, 2021
d9d65ef
acab rubo
rococodogs Feb 23, 2021
78037c5
mini change
rococodogs Feb 23, 2021
6b999f3
move presenter metadata_only language to a helper/locales
rococodogs Feb 23, 2021
4a8726d
cleanup metadata_only_display_html helper a little
rococodogs Feb 23, 2021
9b8bb70
stray <% end %>
rococodogs Feb 23, 2021
a3593c1
don't assume current_user exists
rococodogs Feb 23, 2021
4a993b9
oops forgot erb tags
rococodogs Feb 23, 2021
f5ca929
helper methods + views work
rococodogs Feb 23, 2021
4ac21cb
oof typos
rococodogs Feb 23, 2021
772f72b
more work on rendering the alert
rococodogs Feb 23, 2021
04f5f21
cleanup display_alert helper
rococodogs Feb 23, 2021
f242619
fix labels in locales
rococodogs Feb 23, 2021
e72d9e0
maybe this will help?
rococodogs Feb 23, 2021
9213787
more view typos + fixes
rococodogs Feb 23, 2021
9783a0f
html_safeify catalog info text
rococodogs Feb 23, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions app/actors/spot/actors/base_actor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ def apply_deposit_date(env)
# @return [void]
def apply_save_data_to_curation_concern(env)
transform_rights_statement(env) if env.attributes.key?(:rights_statement)
update_discovery_visibility(env)

super
end
Expand Down Expand Up @@ -61,6 +62,31 @@ def get_date_uploaded_value(env)
def transform_rights_statement(env)
env.attributes[:rights_statement] = Array.wrap(env.attributes[:rights_statement]).map { |v| RDF::URI(v) }
end

# Adds 'public' to the item's +discover_groups+ array unless the item is set to 'private'
# or the incoming attributes change the visibility to 'private'. Note, this also removes
# 'public' from the +discover_groups+ array if it's present and the item is being set
# to 'private'
#
# @return [true]
def update_discovery_visibility(env)
visibility_possibilities = [
env.curation_concern.visibility,
env.attributes[:visibility],
env.attributes[:visibility_during_embargo],
env.attributes[:visibility_during_lease]
]

wants_private = visibility_possibilities.flatten.include?(Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_PRIVATE)

env.curation_concern.discover_groups ||= []

if wants_private
env.curation_concern.discover_groups -= ['public']
else
env.curation_concern.discover_groups += ['public']
end
end
end
end
end
8 changes: 1 addition & 7 deletions app/controllers/catalog_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class CatalogController < ApplicationController
config.advanced_search[:query_parser] ||= 'dismax'
config.advanced_search[:form_solr_parameters] ||= {}

# partial config
config.view.gallery.partials = [:index_header, :index]

config.show.tile_source_field = :content_metadata_image_iiif_info_ssm
Expand Down Expand Up @@ -156,13 +157,6 @@ class CatalogController < ApplicationController
config.add_index_field 'license_tesim',
helper_method: :license_links,
label: :'blacklight.search.fields.license'
config.add_index_field 'embargo_release_date_dtsi',
label: :'blacklight.search.fields.embargo_release_date',
helper_method: :human_readable_date
config.add_index_field 'lease_expiration_date_dtsi',
label: :'blacklight.search.fields.lease_expiration_date',
helper_method: :human_readable_date

#
# search field configuration
#
Expand Down
20 changes: 20 additions & 0 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,24 @@ def extracted_text_highlight_values_for(document)
return [] unless document.has_highlight_field? 'extracted_text_tsimv'
document.highlight_field('extracted_text_tsimv').reject(&:blank?)
end

# @return [String] HTML of bootstrap alert with text
def document_access_display_text(document)
key = if document.embargo_release_date.present?
:embargo
elsif document.lease_expiration_date.present?
:lease
elsif document.registered?
:authenticated
else
# we shouldn't be getting here, but if we do, it's just a blanket "private" message
:private
end

args = { scope: ['spot', 'work', 'access_message'], default: "This item's files are currently unavailable." }
args[:date] = document.embargo_release_date.strftime('%B %e, %Y') if key == :embargo
args[:date] = document.lease_expiration_date.strftime('%B %e, %Y') if key == :lease

I18n.t(key, **args)
end
end
22 changes: 22 additions & 0 deletions app/helpers/spot/ability_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# frozen_string_literal: true
module Spot
module AbilityHelper
# Overrides Hyrax::AbilityHelper#visibility_options by adding an +:all+ variant that
# returns all of the options
def visibility_options(variant)
options = [
Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_PUBLIC,
Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_AUTHENTICATED,
Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_PRIVATE
]
case variant
when :restrict
options.delete_at(0)
options.reverse!
when :loosen
options.delete_at(2)
end
options.map { |value| [visibility_text(value), value] }
end
end
end
10 changes: 5 additions & 5 deletions app/helpers/spot/catalog_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ module CatalogHelper
# Falls back to the original value.
#
# @return [String]
# rubocop:disable Style/RescueModifier
def humanize_edtf_values(args)
Array.wrap(args[:value]).map { |val| humanize_edtf_value(val) }.to_sentence
Array.wrap(args[:value]).map { |value| Date.edtf(value).humanize rescue value }.to_sentence
end
# rubocop:enable Style/RescueModifier

def humanize_edtf_value(value)
Date.edtf(value).humanize
rescue
value
def display_info_alert?(document)
document.embargo_release_date.present? || document.lease_expiration_date.present? || document.registered?
end
end
end
9 changes: 2 additions & 7 deletions app/presenters/hyrax/image_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,8 @@ class ImagePresenter < ::Spot::BasePresenter

humanize_date_fields :date, :date_associated

delegate :contributor, :creator, :date_scope_note, :description,
:donor, :inscription, :keyword, :language_label,
:local_identifier, :note, :original_item_extent, :permalink,
:physical_medium, :publisher, :related_resource, :repository_location,
:requested_by, :research_assistance, :resource_type,
:rights_holder, :rights_statement, :source,
:standard_identifier, :subtitle, :title_alternative,
delegate :date_scope_note, :donor, :inscription, :original_item_extent,
:repository_location, :requested_by, :research_assistance,
to: :solr_document

def subject_ocm
Expand Down
6 changes: 1 addition & 5 deletions app/presenters/hyrax/publication_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,7 @@ class PublicationPresenter < ::Spot::BasePresenter
humanize_date_fields :date_issued

delegate :abstract, :academic_department, :bibliographic_citation,
:contributor, :creator, :date_available,
:division, :editor, :keyword, :language, :language_label,
:local_identifier, :organization, :permalink, :publisher,
:resource_type, :rights_holder, :source, :standard_identifier,
:subtitle, :title_alternative,
:date_available, :division, :editor, :organization,
to: :solr_document

# Metadata formats we're able to export as.
Expand Down
23 changes: 23 additions & 0 deletions app/presenters/spot/base_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,15 @@ class BasePresenter < ::Hyrax::WorkShowPresenter
include PresentsAttributes
include HumanizesDateFields

# delegate common properties to solr_document, so descendents only need
# to add their unique fields
delegate :contributor, :creator, :description, :identifier, :keyword, :language,
:language_label, :location, :local_identifier, :note, :permalink, :physical_medium,
:publisher, :related_resource, :resource_type, :rights_holder, :rights_statement,
:source, :standard_identifier, :subject, :subtitle, :title_alternative, :title, :visibility,
:registered?,
to: :solr_document

# @return [String]
def export_all_text
I18n.t("spot.work.export.download_work_and_metadata_#{multiple_members? ? 'multiple' : 'single'}")
Expand All @@ -39,6 +48,20 @@ def location
solr_document.location.zip(solr_document.location_label).reject(&:empty?)
end

# Conditions for whether to display only metadata or the files attached:
# - "admin" users can see files for all items
# - if the user can +:download+ a record (which includes those that can +:read+),
# we'll show the file
# - if the item is "authenticated" and the user is logged in, show the file
# - if the item is "public" and not embargoed, show the file
#
# Otherwise, we'll display just the metadata.
#
# @return [true, false]
def metadata_only?
@metadata_only ||= !(current_ability.admin? || current_ability.can?(:download, id))
end

# @return [true, false]
def multiple_members?
list_of_item_ids_to_display.count > 1
Expand Down
8 changes: 8 additions & 0 deletions app/views/catalog/_index_header_list_default.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<div class="search-results-title-row">
<h4 class="search-result-title"><%= link_to(document.title_or_label, document) %></h4>
<% if display_info_alert?(document) %>
<div class="alert alert-warning" style="margin:0; padding:5px;">
<%= document_access_display_text(document).html_safe %>
</div>
<% end %>
</div>
14 changes: 7 additions & 7 deletions app/views/catalog/_index_list_default.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@
<dd><%= document.permalink %></dd>
<% end %>
</dl>
</div>

<% highlight_values = extracted_text_highlight_values_for(document) %>
<% if highlight_values.length > 0 -%>
<blockquote class="full-text-excerpt text-muted">
<p><%= highlight_values.join(' ... ').html_safe %></p>
</blockquote>
<% end -%>
<% highlight_values = extracted_text_highlight_values_for(document) %>
<% unless highlight_values.length.zero? -%>
<blockquote class="full-text-excerpt text-muted">
<p><%= highlight_values.join(' ... ').html_safe %></p>
</blockquote>
<% end -%>
</div>
</div>
86 changes: 86 additions & 0 deletions app/views/hyrax/base/_form_visibility_component.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
<%# visibility component for _edit_ form %>

<% if f.object.embargo_release_date %>
<%= render 'form_permission_under_embargo', f: f %>
<% elsif f.object.lease_expiration_date %>
<%= render 'form_permission_under_lease', f: f %>
<% else %>
<fieldset>
<legend class="legend-save-work">Visibility</legend>
<ul class="visibility">
<li class="radio">
<label>
<%= f.radio_button :visibility, Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_PUBLIC, data: { 'target': '#collapsePublic' } %>
<%= visibility_badge(Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_PUBLIC) %>
<br />
<%= t('hyrax.visibility.open.note_html', type: f.object.human_readable_type) %>
<div class="collapse" id="collapsePublic">
<%= t('hyrax.visibility.open.warning_html', label: visibility_badge(Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_PUBLIC)) %>
</div>
</label>
</li>
<li class="radio">
<label>
<%= f.radio_button :visibility, Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_AUTHENTICATED %>
<%= visibility_badge(Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_AUTHENTICATED) %>
<br />
<%= t('hyrax.visibility.authenticated.note_html', institution: institution_name) %>
</label>
</li>
<li class="radio">
<label>
<%= f.radio_button :visibility, Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_EMBARGO, data: { 'target': '#collapseEmbargo' } %>
<%= visibility_badge(Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_EMBARGO) %>
<br />
<%= t('hyrax.visibility.embargo.note_html') %>
<div class="collapse" id="collapseEmbargo">
<div class="form-inline">
<div class="form-group">
<%= f.input :visibility_during_embargo,
# wrapper: :inline,
collection: visibility_options(:all),
include_blank: false %>
<br />
<%= t('hyrax.works.form.visibility_until') %>

<%= f.date_field :embargo_release_date,
wrapper: :inline,
value: f.object.embargo_release_date || Date.tomorrow,
class: 'datepicker form-control',
min: Date.tomorrow %>

<%= f.input :visibility_after_embargo,
wrapper: :inline,
collection: visibility_options(:all),
include_blank: false %>
</div>
</div>
</label>
</li>
<li class="radio">
<label>
<%= f.radio_button :visibility, Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_LEASE, data: { 'target': '#collapseLease' } %>
<%= visibility_badge(Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_LEASE) %>
<br />
<%= t('hyrax.visibility.lease.note_html') %>
<div class="collapse" id="collapseLease">
<div class="form-inline">
<%= f.input :visibility_during_lease, wrapper: :inline, collection: visibility_options(:loosen), include_blank: false %>
<%= t('hyrax.works.form.visibility_until') %>
<%= f.date_field :lease_expiration_date, wrapper: :inline, value: f.object.lease_expiration_date || Date.tomorrow, class: 'datepicker form-control' %>
<%= f.input :visibility_after_lease, wrapper: :inline, collection: visibility_options(:restrict), include_blank: false %>
</div>
</div>
</label>
</li>
<li class="radio">
<label>
<%= f.radio_button :visibility, Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_PRIVATE %>
<%= visibility_badge(Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_PRIVATE) %>
<br />
<%= t('hyrax.visibility.restricted.note_html') %>
</label>
</li>
</ul>
</fieldset>
<% end %>
23 changes: 15 additions & 8 deletions app/views/hyrax/base/_items_table.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<% array_of_ids = presenter.list_of_item_ids_to_display %>
<% members = presenter.member_presenters_for(array_of_ids) %>
<% members = presenter.member_presenters_for(presenter.list_of_item_ids_to_display) %>

<div class="panel panel-default">
<div class="panel-heading panel-heading-slim">
Expand All @@ -15,15 +14,23 @@
<td class="text-center">
<span class="label label-<%= type_class %>"><%= type %></span>
</td>
<td><%= link_to(member.link_name, contextual_path(member, presenter)) %></td>
<td>
<% if presenter.metadata_only? -%>
<%= member.first_title %>
<% else %>
<%= link_to(member.link_name, contextual_path(member, presenter)) -%>
<% end %>
</td>
<td>Uploaded <%= member.try(:date_uploaded) %></td>
<td><%= member.permission_badge %></td>
<td <%= 'colspan="2"'.html_safe if presenter.metadata_only? %>><%= member.permission_badge %></td>
<% unless presenter.metadata_only? %>
<td class="text-center">
<% if model_name == :file_set %>
<%= render "hyrax/file_sets/actions", file_set: member %>
<% end %>
<% if model_name == :file_set %>
<%= render "hyrax/file_sets/actions", file_set: member -%>
<% end %>
</td>
</tr>
<% end %>
</tr >
<% end %>
</tbody>
</table>
Expand Down
13 changes: 11 additions & 2 deletions app/views/hyrax/base/_metadata_and_viewer_panel.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,27 @@
<div class="panel-body">
<div class="row">
<%= render 'workflow_actions_widget', presenter: presenter %>

<div class="col-sm-12">
<%= render 'show_actions', presenter: presenter %>
</div>

<div class="col-sm-12 work-representative-media">
<%= render 'representative_media', presenter: presenter, viewer: presenter.iiif_viewer? %>
<% if display_info_alert?(presenter) %>
<%= render('restricted_access_alert', presenter: presenter) %>
<% end %>

<% unless presenter.metadata_only? %>
<%= render 'representative_media', presenter: presenter, viewer: presenter.iiif_viewer? %>
<% end %>
</div>

<%# <div class="col-sm-3 text-center"> %>
<%# render 'citations', presenter: presenter %>
<%# render 'social_media' %>
<%# </div> %>
<div class="col-sm-12 work-metadata">
<%= render 'export_tools', presenter: presenter %>
<%= render('export_tools', presenter: presenter) unless presenter.metadata_only? %>
<%= render 'work_description', presenter: presenter %>
<%= render 'metadata', presenter: presenter %>
<%= render 'items_table', presenter: presenter %>
Expand Down
3 changes: 3 additions & 0 deletions app/views/hyrax/base/_restricted_access_alert.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<div class="alert alert-warning">
<%= document_access_display_text(presenter).html_safe %>
</div>
2 changes: 1 addition & 1 deletion config/initializers/hyrax.rb
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@
# Should work creation require file upload, or can a work be created first
# and a file added at a later time?
# The default is true.
# config.work_requires_files = true
config.work_requires_files = false

# Enable IIIF image service. This is required to use the
# UniversalViewer-ified show page
Expand Down
Loading