diff --git a/app/actors/spot/actors/base_actor.rb b/app/actors/spot/actors/base_actor.rb index 5936389dc..93783af74 100644 --- a/app/actors/spot/actors/base_actor.rb +++ b/app/actors/spot/actors/base_actor.rb @@ -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 @@ -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 diff --git a/app/controllers/catalog_controller.rb b/app/controllers/catalog_controller.rb index 23c2ecebc..5fd540942 100644 --- a/app/controllers/catalog_controller.rb +++ b/app/controllers/catalog_controller.rb @@ -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 @@ -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 # diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 3b6edad60..9871e14b7 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -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 diff --git a/app/helpers/spot/ability_helper.rb b/app/helpers/spot/ability_helper.rb new file mode 100644 index 000000000..f7c95734b --- /dev/null +++ b/app/helpers/spot/ability_helper.rb @@ -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 diff --git a/app/helpers/spot/catalog_helper.rb b/app/helpers/spot/catalog_helper.rb index 550c4b023..99b401536 100644 --- a/app/helpers/spot/catalog_helper.rb +++ b/app/helpers/spot/catalog_helper.rb @@ -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 diff --git a/app/presenters/hyrax/image_presenter.rb b/app/presenters/hyrax/image_presenter.rb index f0800b566..ccb89f619 100644 --- a/app/presenters/hyrax/image_presenter.rb +++ b/app/presenters/hyrax/image_presenter.rb @@ -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 diff --git a/app/presenters/hyrax/publication_presenter.rb b/app/presenters/hyrax/publication_presenter.rb index fa58e3f62..e36d0726a 100644 --- a/app/presenters/hyrax/publication_presenter.rb +++ b/app/presenters/hyrax/publication_presenter.rb @@ -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. diff --git a/app/presenters/spot/base_presenter.rb b/app/presenters/spot/base_presenter.rb index 869a93ba6..defbdde20 100644 --- a/app/presenters/spot/base_presenter.rb +++ b/app/presenters/spot/base_presenter.rb @@ -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'}") @@ -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 diff --git a/app/views/catalog/_index_header_list_default.html.erb b/app/views/catalog/_index_header_list_default.html.erb new file mode 100644 index 000000000..bd00b6d4b --- /dev/null +++ b/app/views/catalog/_index_header_list_default.html.erb @@ -0,0 +1,8 @@ +
+

<%= link_to(document.title_or_label, document) %>

+ <% if display_info_alert?(document) %> +
+ <%= document_access_display_text(document).html_safe %> +
+ <% end %> +
diff --git a/app/views/catalog/_index_list_default.html.erb b/app/views/catalog/_index_list_default.html.erb index e7c9f7ba7..8cbd1ac99 100644 --- a/app/views/catalog/_index_list_default.html.erb +++ b/app/views/catalog/_index_list_default.html.erb @@ -15,12 +15,12 @@
<%= document.permalink %>
<% end %> - - <% highlight_values = extracted_text_highlight_values_for(document) %> - <% if highlight_values.length > 0 -%> -
-

<%= highlight_values.join(' ... ').html_safe %>

-
- <% end -%> + <% highlight_values = extracted_text_highlight_values_for(document) %> + <% unless highlight_values.length.zero? -%> +
+

<%= highlight_values.join(' ... ').html_safe %>

+
+ <% end -%> + diff --git a/app/views/hyrax/base/_form_visibility_component.html.erb b/app/views/hyrax/base/_form_visibility_component.html.erb new file mode 100644 index 000000000..daebc3aa4 --- /dev/null +++ b/app/views/hyrax/base/_form_visibility_component.html.erb @@ -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 %> +
+ Visibility + +
+<% end %> diff --git a/app/views/hyrax/base/_items_table.html.erb b/app/views/hyrax/base/_items_table.html.erb index 22964e4e8..ed6bedea9 100644 --- a/app/views/hyrax/base/_items_table.html.erb +++ b/app/views/hyrax/base/_items_table.html.erb @@ -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) %>
@@ -15,15 +14,23 @@ <%= type %> - <%= link_to(member.link_name, contextual_path(member, presenter)) %> + + <% if presenter.metadata_only? -%> + <%= member.first_title %> + <% else %> + <%= link_to(member.link_name, contextual_path(member, presenter)) -%> + <% end %> + Uploaded <%= member.try(:date_uploaded) %> - <%= member.permission_badge %> + ><%= member.permission_badge %> + <% unless presenter.metadata_only? %> - <% 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 %> - + <% end %> + <% end %> diff --git a/app/views/hyrax/base/_metadata_and_viewer_panel.html.erb b/app/views/hyrax/base/_metadata_and_viewer_panel.html.erb index 2429a7290..f09345fa3 100644 --- a/app/views/hyrax/base/_metadata_and_viewer_panel.html.erb +++ b/app/views/hyrax/base/_metadata_and_viewer_panel.html.erb @@ -5,18 +5,27 @@
<%= render 'workflow_actions_widget', presenter: presenter %> +
<%= render 'show_actions', presenter: presenter %>
+
- <%= 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 %>
+ <%#
%> <%# render 'citations', presenter: presenter %> <%# render 'social_media' %> <%#
%>