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

[HOLD] Upgrade to Blacklight 8 #4230

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 4 additions & 4 deletions .rubocop_todo.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ gem 'view_component', '~> 2.74.1' # TODO: ?? Unpin when bug in 2.75.0 is fixed
gem 'zip_tricks'

# Stanford related gems
gem 'blacklight', '~> 7.25', '< 7.34' # Avoid 7.34 until we have time to troubleshoot test failures
gem 'blacklight', '~> 8.0'
gem 'blacklight-hierarchy', '~> 6.1'
gem 'dor-services-client', '~> 13.0'
gem 'dor-workflow-client', '~> 6.0'
Expand Down
10 changes: 4 additions & 6 deletions Gemfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 0 additions & 13 deletions app/components/blacklight_modal_component.html.erb

This file was deleted.

8 changes: 0 additions & 8 deletions app/components/blacklight_modal_component.rb

This file was deleted.

2 changes: 1 addition & 1 deletion app/components/document_component.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

class DocumentComponent < Blacklight::DocumentComponent
def initialize(document: nil, **kwargs)
def initialize(document: nil, document_counter: nil, **kwargs)
super
end

Expand Down
3 changes: 1 addition & 2 deletions app/components/edit_modal_component.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
# frozen_string_literal: true

# This models the component that appears when you click one of the blue buttons to modify an object.
# It does not depend on the BlacklightModalComponent, which has a bunch of jquery javascript for
# doing the ajax. That javascript prevents us from showing errors after a form is submitted.
# It does not depend on the Blacklight::System::ModalComponent, which does not use Turbo.
class EditModalComponent < ApplicationComponent
renders_one :header
renders_one :body
Expand Down
6 changes: 6 additions & 0 deletions app/components/search/sidebar_component.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<%= render Blacklight::Search::SidebarComponent.new(blacklight_config:,
response:,
view_config:) %>
<% unless helpers.has_search_parameters? || params[:all] %>
<%= link_to 'Show more facets', root_path(all: true), class: 'btn btn-primary' %>
<% end %>
13 changes: 13 additions & 0 deletions app/components/search/sidebar_component.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# frozen_string_literal: true

class Search
class SidebarComponent < Blacklight::Component
def initialize(blacklight_config:, response:, view_config:)
@blacklight_config = blacklight_config
@response = response
@view_config = view_config
end

attr_reader :blacklight_config, :response, :view_config
end
end
2 changes: 1 addition & 1 deletion app/controllers/bulk_jobs_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def self.local_prefixes
private

def find(id)
search_service.fetch(id).last
search_service.fetch(id)
end

# Given a DRUID, loads any metadata bulk upload information associated with that DRUID into a hash.
Expand Down
86 changes: 37 additions & 49 deletions app/controllers/catalog_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

class CatalogController < ApplicationController
include Blacklight::Catalog
helper ArgoHelper
include DateFacetConfigurations
include ArgoHelper

before_action :limit_facets_on_home_page, only: [:index]

Expand All @@ -15,8 +15,12 @@ class CatalogController < ApplicationController
# https://github.com/projectblacklight/blacklight/issues/1324 and more recent issues in Aug 2021 with large solr queries being sent over GET
config.http_method = :post

# Configure the SearchState to know that "druids_only", is part of the state we care about.
config.search_state_fields << :druids_only
# Configure the SearchState to know which params are part of the state we care about.
config.search_state_fields += %i[druids_only id commit registration apo_id
size item_id time apo description druids all raw access_location
controlled_digital_lending download_access view_access workflow_id csv_file
new_apo_id current_resource_type new_content_type new_resource_type
viewing_direction collection data tag to what who]

# common helper method since search results and reports share most of this config
BlacklightConfigHelper.add_common_default_solr_params_to_config! config
Expand All @@ -26,6 +30,8 @@ class CatalogController < ApplicationController
# When we test with solr 6 we can have:
# config.document_solr_path = 'get'
config.index.document_presenter_class = ArgoIndexPresenter
config.index.sidebar_component = Search::SidebarComponent

config.show.document_presenter_class = ArgoShowPresenter

config.index.display_type_field = SolrDocument::FIELD_CONTENT_TYPE
Expand Down Expand Up @@ -58,28 +64,19 @@ class CatalogController < ApplicationController
# to get the hierarchy.
config.add_facet_field 'exploded_tag_ssim', label: 'Tag', limit: 9999,
component: LazyTagFacetComponent,
unless: lambda { |controller, _config, _response|
controller.params[:no_tags]
}
config.add_facet_field 'objectType_ssim', label: 'Object Type', component: true, limit: 10
config.add_facet_field SolrDocument::FIELD_CONTENT_TYPE, label: 'Content Type', component: true, limit: 10
config.add_facet_field 'content_file_mimetypes_ssim', label: 'MIME Types', component: true, limit: 10, home: false
config.add_facet_field 'content_file_roles_ssim', label: 'File Role', component: true, limit: 10, home: false
config.add_facet_field 'rights_descriptions_ssim', label: 'Access Rights', component: true, limit: 1000,
sort: 'index', home: false
config.add_facet_field SolrDocument::FIELD_LICENSE, label: 'License', component: true, limit: 10, home: false
config.add_facet_field SolrDocument::FIELD_COLLECTION_TITLE, label: 'Collection', component: true, limit: 10,
more_limit: 9999, sort: 'index'
config.add_facet_field 'nonhydrus_apo_title_ssim', label: 'Admin Policy', component: true, limit: 10,
more_limit: 9999, sort: 'index'
config.add_facet_field 'hydrus_apo_title_ssim', label: 'Hydrus Admin Policy', component: true, limit: 10,
more_limit: 9999, sort: 'index', home: false
config.add_facet_field SolrDocument::FIELD_CURRENT_VERSION, label: 'Version', component: true, limit: 10,
home: false
config.add_facet_field 'processing_status_text_ssi', label: 'Processing Status', component: true, limit: 10,
home: false
unless: ->(controller, _config, _response) { controller.params[:no_tags] }
config.add_facet_field 'objectType_ssim', label: 'Object Type', limit: 10
config.add_facet_field SolrDocument::FIELD_CONTENT_TYPE, label: 'Content Type', limit: 10
config.add_facet_field 'content_file_mimetypes_ssim', label: 'MIME Types', limit: 10, home: false
config.add_facet_field 'content_file_roles_ssim', label: 'File Role', limit: 10, home: false
config.add_facet_field 'rights_descriptions_ssim', label: 'Access Rights', limit: 1000, sort: 'index', home: false
config.add_facet_field SolrDocument::FIELD_LICENSE, label: 'License', limit: 10, home: false
config.add_facet_field SolrDocument::FIELD_COLLECTION_TITLE, label: 'Collection', limit: 10, more_limit: 9999, sort: 'index'
config.add_facet_field 'nonhydrus_apo_title_ssim', label: 'Admin Policy', limit: 10, more_limit: 9999, sort: 'index'
config.add_facet_field 'hydrus_apo_title_ssim', label: 'Hydrus Admin Policy', limit: 10, more_limit: 9999, sort: 'index', home: false
config.add_facet_field SolrDocument::FIELD_CURRENT_VERSION, label: 'Version', limit: 10, home: false
config.add_facet_field 'processing_status_text_ssi', label: 'Processing Status', limit: 10, home: false
config.add_facet_field 'released_to_earthworks',
component: true,
query: {
week: {
label: 'Last week',
Expand All @@ -103,7 +100,6 @@ class CatalogController < ApplicationController
}
}
config.add_facet_field 'released_to_searchworks',
component: true,
query: {
week: {
label: 'Last week',
Expand Down Expand Up @@ -137,48 +133,40 @@ class CatalogController < ApplicationController
component: Blacklight::Hierarchy::FacetFieldListComponent,
limit: 9999,
home: false

config.add_facet_field 'metadata_source_ssim', label: 'Metadata Source', home: false,
component: true
config.add_facet_field 'metadata_source_ssim', label: 'Metadata Source', home: false

# common method since search results and reports all do the same configuration
add_common_date_facet_fields_to_config! config

config.add_facet_field SolrDocument::FIELD_CONSTITUENTS, label: 'Virtual Objects', home: false,
component: true,
query: {
has_constituents: { label: 'Virtual Objects', fq: "#{SolrDocument::FIELD_CONSTITUENTS}:*" }
}

# This will help us find records that need to be fixed before we can move to cocina.
config.add_facet_field 'data_quality_ssim', label: 'Data Quality', home: false, component: true
config.add_facet_field 'data_quality_ssim', label: 'Data Quality', home: false

config.add_facet_field 'identifiers', label: 'Identifiers',
component: true,
query: {
has_orcids: { label: 'Has contributor ORCIDs',
fq: '+contributor_orcids_ssim:*' },
has_orcids: { label: 'Has contributor ORCIDs', fq: '+contributor_orcids_ssim:*' },
has_doi: { label: 'Has DOI', fq: '+doi_ssim:*' },
has_barcode: { label: 'Has barcode', fq: '+barcode_id_ssim:*' }
}

config.add_facet_field 'empties', label: 'Empty Fields', home: false,
component: true,
query: {
no_mods_typeOfResource_ssim: { label: 'No MODS typeOfResource',
fq: '-mods_typeOfResource_ssim:*' },
no_mods_typeOfResource_ssim: { label: 'No MODS typeOfResource', fq: '-mods_typeOfResource_ssim:*' },
no_sw_format: { label: 'No SW Resource Type', fq: '-sw_format_ssim:*' }
}

config.add_facet_field 'sw_format_ssim', label: 'SW Resource Type', component: true, limit: 10, home: false
config.add_facet_field 'sw_pub_date_facet_ssi', label: 'SW Date', component: true, limit: 10, home: false
config.add_facet_field 'topic_ssim', label: 'SW Topic', component: true, limit: 10, home: false
config.add_facet_field 'sw_subject_geographic_ssim', label: 'SW Region', component: true, limit: 10, home: false
config.add_facet_field 'sw_subject_temporal_ssim', label: 'SW Era', component: true, limit: 10, home: false
config.add_facet_field 'sw_genre_ssim', label: 'SW Genre', component: true, limit: 10, home: false
config.add_facet_field 'sw_language_ssim', label: 'SW Language', component: true, limit: 10, home: false
config.add_facet_field 'mods_typeOfResource_ssim', label: 'MODS Resource Type', component: true, limit: 10,
home: false
config.add_facet_field 'sw_format_ssim', label: 'SW Resource Type', limit: 10, home: false
config.add_facet_field 'sw_pub_date_facet_ssi', label: 'SW Date', limit: 10, home: false
config.add_facet_field 'topic_ssim', label: 'SW Topic', limit: 10, home: false
config.add_facet_field 'sw_subject_geographic_ssim', label: 'SW Region', limit: 10, home: false
config.add_facet_field 'sw_subject_temporal_ssim', label: 'SW Era', limit: 10, home: false
config.add_facet_field 'sw_genre_ssim', label: 'SW Genre', limit: 10, home: false
config.add_facet_field 'sw_language_ssim', label: 'SW Language', limit: 10, home: false
config.add_facet_field 'mods_typeOfResource_ssim', label: 'MODS Resource Type', limit: 10, home: false
# Adding the facet field allows it to be queried (e.g., from value_helper)
config.add_facet_field 'is_governed_by_ssim', if: false
config.add_facet_field 'is_member_of_collection_ssim', if: false
Expand Down Expand Up @@ -221,16 +209,16 @@ def index
end

def lazy_tag_facet
(response,) = search_service.search_results
facet_config = facet_configuration_for_field('exploded_tag_ssim')
response = search_service.search_results
facet_config = helpers.facet_configuration_for_field('exploded_tag_ssim')
display_facet = response.aggregations[facet_config.field]
@facet_field_presenter = facet_config.presenter.new(facet_config, display_facet, view_context)
render partial: 'lazy_tag_facet'
end

def show
params[:id] = Druid.new(params[:id]).with_namespace
_deprecated_response, @document = search_service.fetch(params[:id])
@document = search_service.fetch(params[:id])

@cocina = Repository.find_lite(params[:id], structural: false)
if @cocina.instance_of?(NilModel)
Expand Down Expand Up @@ -271,7 +259,7 @@ def limit_facets_on_home_page
end

# do not add the druids_only search param to the blacklight search history (used in bulk actions only)
def blacklisted_search_session_params
def nonpersisted_search_session_params
super << :druids_only
end

Expand Down
2 changes: 1 addition & 1 deletion app/controllers/manage_releases_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class ManageReleasesController < ApplicationController
def show
cocina = Repository.find(params[:item_id])
authorize! :update, cocina
_, @document = search_service.fetch params[:item_id]
@document = search_service.fetch(params[:item_id])
@bulk_action = BulkAction.new

respond_to do |format|
Expand Down
5 changes: 0 additions & 5 deletions app/controllers/registrations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,6 @@ def form_create
def csv_create
@registration_form = CsvRegistrationForm.new(nil)
if @registration_form.validate(create_params) && @registration_form.save
# # strip the CSRF token, and the parameters that happened to be in the bulk job creation form
# # this can be removed when this is resolved: https://github.com/projectblacklight/blacklight/issues/2683
# search_state_subset = search_state.to_h.except(:authenticity_token, :druids, :druids_only, :description)
# path_params = Blacklight::Parameters.sanitize(search_state_subset)
# redirect_to bulk_actions_path(path_params), status: :see_other, notice: success_message
redirect_to bulk_actions_path, status: :see_other, notice: 'Register druids job was successfully created.'
else
prepopulate
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/report_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def reset

# This draws the full page that supports the workflow grid
def workflow_grid
(@response, _deprecated_document_list) = search_service.search_results
@response = search_service.search_results
return unless request.headers['X-Requester'] == 'frontend'

# This is triggered by javascript that refreshes the data every 10s
Expand Down
1 change: 0 additions & 1 deletion app/forms/apo_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ def default_collection_objects
@default_collection_objects ||=
@search_service
.fetch(default_collections, rows: default_collections.size)
.last
.sort_by do |solr_doc|
solr_doc.label.downcase
end
Expand Down
11 changes: 11 additions & 0 deletions app/helpers/argo_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,20 @@

# Overrides for Blacklight helpers
module ArgoHelper
include Blacklight::DocumentHelperBehavior
include BlacklightHelper
include ValueHelper

def document_presenter(document)
super.tap do |presenter|
presenter.view_token = @verified_token_with_expiration if presenter.respond_to? :view_token
if presenter.respond_to? :cocina
presenter.cocina = @cocina
presenter.state_service = StateService.new(@cocina)
end
end
end

# This overrides a blacklight helper so that the page is full-width
def container_classes
return super if controller_name == 'apo'
Expand Down
11 changes: 0 additions & 11 deletions app/helpers/items_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,6 @@ def stacks_url_full_size(druid, file_name)
"#{Settings.stacks_file_url}/#{druid}/#{ERB::Util.url_encode(file_name)}"
end

# Overriding blacklight so we can pass @cocina to the presenter
def document_presenter(document)
super.tap do |presenter|
presenter.view_token = @verified_token_with_expiration if presenter.respond_to? :view_token
if presenter.respond_to? :cocina
presenter.cocina = @cocina
presenter.state_service = StateService.new(@cocina)
end
end
end

def license_options
[['none', '']] + Constants::LICENSE_OPTIONS.map { |attributes| [attributes.fetch(:label), attributes.fetch(:uri)] }
end
Expand Down
Loading