Skip to content

Commit

Permalink
Merge branch 'main' into blacklight_advanced_and_range
Browse files Browse the repository at this point in the history
  • Loading branch information
kirkkwang authored Sep 25, 2023
2 parents 15d3136 + 58d68d1 commit ebe15ca
Show file tree
Hide file tree
Showing 23 changed files with 398 additions and 14 deletions.
25 changes: 25 additions & 0 deletions app/actors/hyrax/environment.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# frozen_string_literal: true

# OVERRIDE Hyrax 2.9 to add in import flag
module Hyrax
module Actors
class Environment
# @param [ActiveFedora::Base] curation_concern work to operate on
# @param [Ability] current_ability the authorizations of the acting user
# @param [ActionController::Parameters] attributes user provided form attributes
def initialize(curation_concern, current_ability, attributes, importing = false)
@curation_concern = curation_concern
@current_ability = current_ability
@attributes = attributes.to_h.with_indifferent_access
@importing = importing
end

attr_reader :curation_concern, :current_ability, :attributes, :importing

# @return [User] the user from the current_ability
def user
current_ability.current_user
end
end
end
end
14 changes: 14 additions & 0 deletions app/factories/bulkrax/object_factory_decorator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# frozen_string_literal: true

# Add ability to mark environment as from bulk import
module Bulkrax
module ObjectFactoryDecorator
# @param [Hash] attrs the attributes to put in the environment
# @return [Hyrax::Actors::Environment]
def environment(attrs)
Hyrax::Actors::Environment.new(object, Ability.new(@user), attrs, true)
end
end
end

::Bulkrax::ObjectFactory.prepend(Bulkrax::ObjectFactoryDecorator)
4 changes: 4 additions & 0 deletions app/jobs/application_job.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
# frozen_string_literal: true

class ApplicationJob < ActiveJob::Base
# limit to 5 attempts
retry_on StandardError, wait: :exponentially_longer, attempts: 5 do |_job, _exception|
# Log error, do nothing, etc.
end
end
3 changes: 1 addition & 2 deletions app/jobs/reindex_collections_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
class ReindexCollectionsJob < ApplicationJob
def perform
Collection.find_each do |collection|
collection.try(:reindex_extent=, Hyrax::Adapters::NestingIndexAdapter::LIMITED_REINDEX)
collection.update_index
ReindexItemJob.perform_later(collection)
end
end
end
9 changes: 9 additions & 0 deletions app/jobs/reindex_file_sets_job.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# frozen_string_literal: true

class ReindexFileSetsJob < ApplicationJob
def perform
FileSet.find_each do |file_set|
ReindexItemJob.perform_later(file_set)
end
end
end
7 changes: 7 additions & 0 deletions app/jobs/reindex_item_job.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# frozen_string_literal: true

class ReindexItemJob < ApplicationJob
def perform(item)
item.update_index
end
end
6 changes: 4 additions & 2 deletions app/jobs/reindex_works_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

class ReindexWorksJob < ApplicationJob
def perform
Hyrax.config.registered_curation_concern_types.each do |work_type|
work_type.constantize.find_each(&:update_index)
Site.instance.available_works.each do |work_type|
work_type.constantize.find_each do |work|
ReindexItemJob.perform_later(work)
end
end
end
end
3 changes: 2 additions & 1 deletion app/middleware/account_elevator.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
# frozen_string_literal: true

require 'apartment/elevators/generic'
# Apartment middleware for switching tenants based on the
# CNAME entry for an account.
class AccountElevator < Apartment::Elevators::Generic
include AccountSwitch
# @return [String] The tenant to switch to
def parse_tenant_name(request)
account = Account.from_request(request)

account || Account.new.reset! # reset everything if no account is present
account&.tenant
end
end
20 changes: 20 additions & 0 deletions app/views/devise/passwords/new.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<h2 class="text-center">Forgot your password?</h2>
<div class="row center-block">
<div class="col-md-6 col-md-offset-3">
<%= form_for(resource, as: resource_name, url: password_path(resource_name), html: { method: :post }) do |f| %>
<%= render "devise/shared/error_messages", resource: resource %>

<div class="form-group">
<%= f.label :email %><br />
<%= f.email_field :email, autofocus: true, autocomplete: "email", class: "form-control" %>
</div>

<div class="form-group text-center">
<%= f.submit "Send me reset password instructions", class: 'btn btn-primary' %>
</div>
<% end %>
<div class="text-center">
<%= render "devise/shared/links" %>
</div>
</div>
</div>
26 changes: 26 additions & 0 deletions app/views/devise/registrations/registrations/new.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<h2 class="text-center pt-40 pb-40"><%= t(".sign_up_header") %></h2>
<div class="row center-block">
<div class="col-md-8 col-md-offset-2">
<%= simple_form_for(resource, as: resource_name, url: registration_path(resource_name), html: { class: 'form-horizontal' }) do |f| %>
<small>
<%= f.error_notification %>
</small>

<div class="form-inputs">
<%= f.input :display_name, required: true, wrapper: :inline %>
<%= f.input :email, required: true, autofocus: true, wrapper: :inline %>
<%= f.input :password, required: true, wrapper: :inline %>
<%= f.input :password_confirmation, required: true, wrapper: :inline %>
</div>

<div class="form-group text-center">
<%= render 'devise/shared/links' %>
</div>
<div class="text-center pb-40">
<%= f.button :submit, t(".sign_up") %>
</div>
</div>
<% end %>
</div>
</div>

31 changes: 31 additions & 0 deletions app/views/devise/sessions/new.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@

<h2 class="text-center">Log in</h2>
<div class="row center-block">
<div class="col-md-6 col-md-offset-3">
<%= form_for(resource, as: resource_name, url: session_path(resource_name), class: "form-horizontal") do |f| %>
<div class="form-group">
<%= f.label :email %><br />
<%= f.email_field :email, autofocus: true, class: "form-control" %>
</div>

<div class="form-group">
<%= f.label :password, class: "control-label" %><br />
<%= f.password_field :password, autocomplete: "off", class: "form-control" %>
</div>

<% if devise_mapping.rememberable? -%>
<div class="form-group text-center">
<%= f.check_box :remember_me %>
<%= f.label :remember_me, class: "control-label" %>
</div>
<% end -%>

<div class="form-group text-center">
<%= f.submit "Log in", class: 'btn btn-primary' %>
</div>
<% end %>
<div class="text-center">
<%= render "devise/shared/links" %>
</div>
</div>
</div>
2 changes: 1 addition & 1 deletion app/views/devise/shared/_links.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<% end -%>
<%- if devise_mapping.recoverable? && controller_name != 'passwords' %>
<%= link_to t(".forgot_your_password"), new_password_path(resource_name) %><br />
<%= link_to t(".forgot_your_password"), new_password_path(resource_name), class: 'lh-40' %><br />
<% end -%>
<%- if devise_mapping.confirmable? && controller_name != 'confirmations' %>
Expand Down
56 changes: 48 additions & 8 deletions config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,34 @@
Bundler.require(*groups)

module Hyku
# Providing a common method to ensure consistent UTF-8 encoding. Also removing the tricksy Byte
# Order Marker character which is an invisible 0 space character.
#
# @note In testing, we encountered errors with the file's character encoding
# (e.g. `Encoding::UndefinedConversionError`). The following will force the encoding to
# UTF-8 and replace any invalid or undefined characters from the original encoding with a
# "?".
#
# Given that we still have the original, and this is a derivative, the forced encoding
# should be acceptable.
#
# @param [String]
# @return [String]
#
# @see https://sentry.io/organizations/scientist-inc/issues/3773392603/?project=6745020&query=is%3Aunresolved&referrer=issue-stream
# @see https://github.com/samvera-labs/bulkrax/pull/689
# @see https://github.com/samvera-labs/bulkrax/issues/688
# @see https://github.com/scientist-softserv/adventist-dl/issues/179
def self.utf_8_encode(string)
string
.encode(Encoding.find('UTF-8'), invalid: :replace, undef: :replace, replace: "?")
.delete("\xEF\xBB\xBF")
end

class Application < Rails::Application
# Add this line to load the lib folder first because we need
config.autoload_paths.unshift("#{Rails.root}/lib")

# Settings in config/environments/* take precedence over those specified here.
# Application configuration should go into files in config/initializers
# -- all .rb files in that directory are automatically loaded.
Expand All @@ -33,22 +60,33 @@ class Application < Rails::Application
end

config.to_prepare do
# Allows us to use decorator files in the app directory

# Add any extra services before IiifPrint::PluggableDerivativeService to enable processing
Hyrax::DerivativeService.services = [IiifPrint::PluggableDerivativeService]

# When you are ready to use the derivative rodeo instead of the pluggable uncomment the
# following and comment out the preceding Hyrax::DerivativeService.service
#
# Hyrax::DerivativeService.services = [
# Adventist::TextFileTextExtractionService,
# IiifPrint::DerivativeRodeoService,
# Hyrax::FileSetDerivativesService]

DerivativeRodeo::Generators::HocrGenerator.additional_tessearct_options = "-l eng_best"

# Allows us to use decorator files
Dir.glob(File.join(File.dirname(__FILE__), "../app/**/*_decorator*.rb")).sort.each do |c|
Rails.configuration.cache_classes ? require(c) : load(c)
end
end

config.to_prepare do
# Allows us to use decorator files in the app directory
Dir.glob(File.join(File.dirname(__FILE__), "../lib/**/*_decorator*.rb")).sort.each do |c|
Rails.configuration.cache_classes ? require(c) : load(c)
end
end

# OAI additions
Dir.glob(File.join(File.dirname(__FILE__), "../lib/oai/**/*.rb")).sort.each do |c|
Rails.configuration.cache_classes ? require(c) : load(c)
# OAI additions
Dir.glob(File.join(File.dirname(__FILE__), "../lib/oai/**/*.rb")).sort.each do |c|
Rails.configuration.cache_classes ? require(c) : load(c)
end
end

# resolve reloading issue in dev mode
Expand All @@ -67,6 +105,8 @@ class Application < Rails::Application
Object.include(AccountSwitch)
end

# copies tinymce assets directly into public/assets
config.tinymce.install = :copy
##
# Psych Allow YAML Classes
#
Expand Down
1 change: 1 addition & 0 deletions config/database.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

login: &login
adapter: <%= ENV['DB_ADAPTER'] || 'postgresql' %>
schema_search_path: "public,shared_extensions"
host: <%= ENV['DB_HOST'] %>
username: <%= ENV['DB_USER'] %>
password: <%= ENV['DB_PASSWORD'] %>
Expand Down
1 change: 1 addition & 0 deletions config/fedora.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ production:
password: fedoraAdmin
url: http://<%= ENV['FCREPO_HOST'] || 'localhost' %>:<%= ENV['FCREPO_PORT'] || 8080 %>/<%= ENV['FCREPO_REST_PATH'] || 'rest' %>
base_path: <%= ENV['FCREPO_BASE_PATH'] || '/prod' %>
request: { timeout: 600, open_timeout: 60}
11 changes: 11 additions & 0 deletions config/initializers/active_fedora_override.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Based on https://github.com/samvera/hyrax/issues/4581#issuecomment-843085122

# Monkey-patch to short circuit ActiveModel::Dirty which attempts to load the whole master files ordered list when calling nodes_will_change!
# This leads to a stack level too deep exception when attempting to delete a master file from a media object on the manage files step.
# See https://github.com/samvera/active_fedora/pull/1312/commits/7c8bbbefdacefd655a2ca653f5950c991e1dc999#diff-28356c4daa0d55cbaf97e4269869f510R100-R103
ActiveFedora::Aggregation::ListSource.class_eval do
def attribute_will_change!(attr)
return super unless attr == 'nodes'
attributes_changed_by_setter[:nodes] = true
end
end
2 changes: 2 additions & 0 deletions config/initializers/apartment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
# Any schemas added here will be available along with your selected Tenant.
#
# config.persistent_schemas = %w{ hstore }
config.persistent_schemas = ['shared_extensions']


# <== PostgreSQL only options
#
Expand Down
20 changes: 20 additions & 0 deletions lib/active_fedora/solr_service_decorator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# frozen_string_literal: true

# OVERRIDE: class ActiveFedora::SolrService from Fedora 12.1.1
module ActiveFedora
module SolrServiceDecorator
# Get the count of records that match the query
# @param [String] query a solr query
# @param [Hash] args arguments to pass through to `args' param of SolrService.query
# (note that :rows will be overwritten to 0)
# @return [Integer] number of records matching
#
# OVERRIDE: use `post` rather than `get` to handle larger query sizes
def count(query, args = {})
args = args.merge(rows: 0)
SolrService.post(query, args)['response']['numFound'].to_i
end
end
end

ActiveFedora::SolrService.singleton_class.send(:prepend, ActiveFedora::SolrServiceDecorator)
28 changes: 28 additions & 0 deletions lib/hydra/derivatives/processors/image_decorator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# frozen_string_literal: true

# Fix PDF tripple issue

module Hydra
module Derivatives
module Processors
module ImageDecorator
protected

# When resizing images, it is necessary to flatten any layers, otherwise the background
# may be completely black. This happens especially with PDFs. See https://github.com/samvera/hydra-derivatives/issues/110
def create_resized_image
create_image do |xfrm|
if size
xfrm.combine_options do |i|
i.flatten
i.resize(size)
end
end
end
end
end
end
end
end

::Hydra::Derivatives::Processors::Image.prepend(Hydra::Derivatives::Processors::ImageDecorator)
17 changes: 17 additions & 0 deletions lib/iiif_manifest/manifest_builder/canvas_builder_decorator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# frozen_string_literal: true

# OVERRIDE IIIFManifest v0.5.0 to use the parent's title as the label instead of the filename

module IIIFManifest
module ManifestBuilderDecorator
module CanvasBuilderDecorator
def apply_record_properties
canvas['@id'] = path
canvas.label = record['parent_title_tesim']&.first || record.to_s
end
end
end
end

IIIFManifest::ManifestBuilder.prepend(IIIFManifest::ManifestBuilderDecorator)
IIIFManifest::ManifestBuilder::CanvasBuilder.prepend(IIIFManifest::ManifestBuilder::CanvasBuilderDecorator)
Loading

0 comments on commit ebe15ca

Please sign in to comment.