Skip to content

Commit

Permalink
Merge pull request #995 from UNC-Libraries/hyc-1737-class2
Browse files Browse the repository at this point in the history
HYC-1737 - Hyrax 4 class override updates
  • Loading branch information
sharonluong authored Sep 7, 2023
2 parents 42b9ecd + efe382f commit c088be3
Show file tree
Hide file tree
Showing 27 changed files with 174 additions and 398 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
/tmp/*
!/log/.keep
!/tmp/.keep
tmp

# Ignore Byebug command history file.
.byebug_history
Expand Down
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ gem 'execjs', '2.8.1'
gem 'httparty', '~>0.21.0'
gem 'hydra-editor', '~> 6.0'
gem 'hydra-role-management', '~> 1.0'
gem 'hyrax', git: 'https://github.com/UNC-Libraries/hyrax.git', tag: 'hyrax-v4.0.0'
gem 'hyrax', git: 'https://github.com/UNC-Libraries/hyrax.git', branch: 'unc-hyrax-4-development'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.11.2'
# Use jquery as the JavaScript library
Expand Down
10 changes: 5 additions & 5 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
GIT
remote: https://github.com/UNC-Libraries/hyrax.git
revision: 815e0abaacf9f331a5640c5d6129661d01eadf75
tag: hyrax-v4.0.0
revision: bd2aa55168e8c6e4205c08d3d21b3342c8264fab
branch: unc-hyrax-4-development
specs:
hyrax (4.0.0)
active-fedora (~> 14.0)
Expand Down Expand Up @@ -154,7 +154,7 @@ GEM
awesome_nested_set (3.5.0)
activerecord (>= 4.0.0, < 7.1)
aws-eventstream (1.2.0)
aws-partitions (1.810.0)
aws-partitions (1.815.0)
aws-sdk-core (3.181.0)
aws-eventstream (~> 1, >= 1.0.2)
aws-partitions (~> 1, >= 1.651.0)
Expand All @@ -163,7 +163,7 @@ GEM
aws-sdk-kms (1.71.0)
aws-sdk-core (~> 3, >= 3.177.0)
aws-sigv4 (~> 1.1)
aws-sdk-s3 (1.133.0)
aws-sdk-s3 (1.134.0)
aws-sdk-core (~> 3, >= 3.181.0)
aws-sdk-kms (~> 1)
aws-sigv4 (~> 1.6)
Expand Down Expand Up @@ -412,7 +412,7 @@ GEM
retriable (>= 2.0, < 4.a)
rexml
webrick
google-apis-drive_v3 (0.43.0)
google-apis-drive_v3 (0.44.0)
google-apis-core (>= 0.11.0, < 2.a)
googleauth (1.7.0)
faraday (>= 0.17.3, < 3.a)
Expand Down
27 changes: 3 additions & 24 deletions app/controllers/concerns/hyrax/controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,28 +35,6 @@ def default_url_options
super.merge(locale: I18n.locale)
end

##
# @deprecated provides short-term compatibility with Blacklight 6
# @return [Class<Blacklight::SearchBuilder>]
def search_builder_class
return super if defined?(super)
Deprecation.warn('Avoid direct calls to `#search_builder_class`; this' \
' method provides short-term compatibility to' \
' Blacklight 6 clients.')
blacklight_config.search_builder_class
end

##
# @deprecated provides short-term compatibility with Blacklight 6
# @return [Blacklight::AbstractRepository]
def repository
return super if defined?(super)
Deprecation.warn('Avoid direct calls to `#repository`; this method' \
' provides short-term compatibility to Blacklight 6 ' \
' clients.')
blacklight_config.repository
end

# @note for Blacklight 6/7 compatibility
def search_results(*args)
return super if defined?(super) # use the upstream if present (e.g. in BL 6)
Expand All @@ -66,13 +44,14 @@ def search_results(*args)

##
# @note for Blacklight 6/7 compatibility
def search_service(**search_params)
def search_service(*args, **search_params)
search_params.merge!(args.last) if args.last.is_a?(Hash)
return super if defined?(super) && search_params.empty?

search_service_class.new(config: blacklight_config,
scope: self,
user_params: search_params,
search_builder_class: search_builder_class)
search_builder_class: blacklight_config.search_builder_class)
end

private
Expand Down
7 changes: 4 additions & 3 deletions app/jobs/create_derivatives_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,18 @@ def perform(file_set, file_id, filepath = nil)
end
return if file_set.video? && !Hyrax.config.enable_ffmpeg

filename = Hyrax::WorkingDirectory.find_or_retrieve(file_id, file_set.id, filepath)
# Ensure a fresh copy of the repo file's latest version is being worked on, if no filepath is directly provided
filepath = Hyrax::WorkingDirectory.copy_repository_resource_to_working_directory(Hydra::PCDM::File.find(file_id), file_set.id) unless filepath && File.exist?(filepath)

file_set.create_derivatives(filename)
file_set.create_derivatives(filepath)

# Reload from Fedora and reindex for thumbnail and extracted text
file_set.reload
file_set.update_index
file_set.parent.update_index if parent_needs_reindex?(file_set)

# [hyc-override] this is the last job, so cleanup the uploaded file
cleanup_uploaded_file(filename)
cleanup_uploaded_file(filepath) unless filepath.nil?
end

# [hyc-override] Deletes the uploaded file if it is in the uploaded_files dir
Expand Down
16 changes: 5 additions & 11 deletions app/overrides/actors/hyrax/actors/file_actor_override.rb
Original file line number Diff line number Diff line change
@@ -1,18 +1,8 @@
# frozen_string_literal: true
# https://github.com/samvera/hyrax/blob/v3.4.2/app/actors/hyrax/actors/file_actor.rb
# https://github.com/samvera/hyrax/blob/hyrax-v4.0.0/app/actors/hyrax/actors/file_actor.rb
Hyrax::Actors::FileActor.class_eval do

alias_method :original_ingest_file, :ingest_file
def ingest_file(io)
original_ingest_file(io)
rescue ActiveFedora::RecordInvalid => error
# [hyc-override] rescue and log the error, finally return false after logging
Rails.logger.error("Could not save FileSet with id: #{file_set.id} after adding file due to error: #{error}")
false
end

def perform_ingest_file_through_active_fedora(io)
# Skip versioning because versions will be minted by VersionCommitter as necessary during save_characterize_and_record_committer.
Hydra::Works::AddFileToFileSet.call(file_set,
io,
relation,
Expand All @@ -25,5 +15,9 @@ def perform_ingest_file_through_active_fedora(io)
# [hyc-override] Invoke longleaf registration
RegisterToLongleafJob.perform_later(repository_file.checksum.value)
CharacterizeJob.perform_later(file_set, repository_file.id, pathhint(io))
rescue ActiveFedora::RecordInvalid => error
# [hyc-override] rescue and log the error, finally return false after logging
Rails.logger.error("Could not save FileSet with id: #{file_set.id} after adding file due to error: #{error}")
false
end
end
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true
# [hyc-override] Overriding to allow updated content jobs to run immediately so file reference isn't lost
# https://github.com/samvera/hyrax/blob/v2.9.6/app/actors/hyrax/actors/file_set_actor.rb
# https://github.com/samvera/hyrax/blob/hyrax-v4.0.0/app/actors/hyrax/actors/file_set_actor.rb
Hyrax::Actors::FileSetActor.class_eval do
# Spawns synchronous IngestJob with user notification afterward
# @param [Hyrax::UploadedFile, File, ActionDigest::HTTP::UploadedFile] file the file uploaded by the user
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true
# https://github.com/samvera/hyrax/blob/3.5/app/controllers/hyrax/file_sets_controller.rb
# https://github.com/samvera/hyrax/blob/hyrax-v4.0.0/app/controllers/hyrax/file_sets_controller.rb

Hyrax::FileSetsController.class_eval do
# [hyc-override] Only allow deletions by admins
Expand Down
11 changes: 0 additions & 11 deletions app/overrides/controllers/hyrax/my/works_controller_override.rb

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true
# [hyc-override] Overriding to remove :based_near (location) from form. Gives error if populated
# https://github.com/samvera/hyrax/blob/v2.9.6/app/forms/hyrax/forms/collection_form.rb
# https://github.com/samvera/hyrax/blob/hyrax-v4.0.0/app/forms/hyrax/forms/collection_form.rb
Hyrax::Forms::CollectionForm.class_eval do
self.terms -= [:based_near]

Expand Down
2 changes: 1 addition & 1 deletion app/overrides/helpers/hyrax/work_form_helper_override.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true
# https://github.com/samvera/hyrax/blob/v3.4.2/app/helpers/hyrax/work_form_helper.rb
# https://github.com/samvera/hyrax/blob/hyrax-v4.0.0/app/helpers/hyrax/work_form_helper.rb
Hyrax::WorkFormHelper.module_eval do
def form_tabs_for(form:)
if form.instance_of? Hyrax::Forms::BatchUploadForm
Expand Down
10 changes: 10 additions & 0 deletions app/overrides/jobs/change_depositor_event_job_override.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# frozen_string_literal: true
# https://github.com/samvera/hyrax/blob/hyrax-v4.0.0/app/jobs/change_depositor_event_job.rb
Hyrax::ChangeDepositorEventJob.class_eval do
# [hyc-override] Overriding to make depositor a facet search and not link to user profile
def action
proxy_link = link_to(repo_object.proxy_depositor, search_catalog_path(f: { depositor_ssim: [repo_object.proxy_depositor] }))
new_user_link = link_to(depositor, search_catalog_path(f: { depositor_ssim: [depositor] }))
"User #{proxy_link} has transferred #{link_to_work repo_object.title.first} to user #{new_user_link}"
end
end
11 changes: 0 additions & 11 deletions app/overrides/jobs/content_depositor_change_event_job_override.rb

This file was deleted.

39 changes: 0 additions & 39 deletions app/overrides/models/file_download_stat_override.rb

This file was deleted.

26 changes: 1 addition & 25 deletions app/overrides/models/hyrax/statistic_override.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true
# https://github.com/samvera/hyrax/blob/v2.9.6/app/models/hyrax/statistic.rb
# https://github.com/samvera/hyrax/blob/hyrax-v4.0.0/app/models/hyrax/statistic.rb
Hyrax::Statistic.class_eval do
class << self
# [hyc-override]
Expand All @@ -12,30 +12,6 @@ def raise_timeouts=(value)
@@raise_timeouts = value
end

# [hyc-override] add old id to filter query if work was migrated
# Hyrax::Download is sent to Hyrax::Analytics.profile as #hyrax__download
# see Legato::ProfileMethods.method_name_from_klass
def ga_statistics(start_date, object)
path = polymorphic_path(object)
profile = Hyrax::Analytics.profile
unless profile
Rails.logger.error('Google Analytics profile has not been established. Unable to fetch statistics.')
return []
end

# check if work was migrated
redirect_path = BoxcToHycRedirectService.redirect_lookup('new_path', path.split('/')[-1])

path = "#{path}|/record/uuid:#{redirect_path['uuid']}" if redirect_path

# [hyc-override] https://github.com/samvera/hyrax/issues/5955
profile.hyrax__pageview(sort: 'date',
start_date: start_date,
end_date: Date.yesterday,
limit: 10_000)
.for_path(path)
end

private

# [hyc-override] add error handling for timeouts
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
# frozen_string_literal: true
# [hyc-override] Overriding helper in order to add doi to citation
# https://github.com/samvera/hyrax/blob/v3.4.2/app/presenters/hyrax/work_show_presenter.rb
# https://github.com/samvera/hyrax/blob/hyrax-v4.0.0/app/presenters/hyrax/work_show_presenter.rb
Hyrax::WorkShowPresenter.class_eval do
# delegating just :doi seems to exclude the other fields, so pull all fields in from original file
delegate :title, :date_created, :date_issued, :description, :doi, :creator, :place_of_publication,
:creator_display, :contributor, :subject, :publisher, :language, :embargo_release_date,
:lease_expiration_date, :license, :source, :rights_statement, :thumbnail_id, :representative_id,
:rendering_ids, :member_of_collection_ids, :alternative_title, to: :solr_document
:rendering_ids, :member_of_collection_ids, :alternative_title, :bibliographic_citation, to: :solr_document

# [hyc-override] Add default scholarly? method
# Indicates if the work is considered scholarly according to google scholar
# This method is not defined in hyrax, but it is referenced by GoogleScholarPresenter
def scholarly?
Expand Down
32 changes: 32 additions & 0 deletions app/overrides/presenters/hyrax/workflow_presenter_override.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# frozen_string_literal: true
# [hyc-override] https://github.com/samvera/hyrax/tree/hyrax-v4.0.0/app/presenters/hyrax/workflow_presenter.rb
Hyrax::WorkflowPresenter.class_eval do
def actions
# [hyc-override] Hide panel from non-admins if the workflow action is to withdraw/delete the work
return [] unless sipity_entity && current_ability && (current_ability.current_user.admin? || state != 'pending_deletion')
actions = Hyrax::Workflow::PermissionQuery.scope_permitted_workflow_actions_available_for_current_state(entity: sipity_entity, user: current_ability.current_user)
actions.map { |action| [action.name, action_label(action)] }
end

# [hyc-override] Add check to display message to MFA workflow depositor
def is_mfa_in_review?
return false unless sipity_entity

sipity_entity&.workflow_name == 'art_mfa_deposit' && state == 'pending_review'
end

# [hyc-override] Add check to display attach works button to MFA workflow depositor
def is_mfa?
return false unless sipity_entity

sipity_entity&.workflow_name == 'art_mfa_deposit'
end

# [hyc-override] Add permission checks to hide withdrawn files
def in_workflow_state?(test_states = [])
return false unless state && !test_states.blank?

test_state_regex = test_states.join('|').gsub(/\s+/, '.+')
!/#{test_state_regex}/.match(state).nil?
end
end
4 changes: 2 additions & 2 deletions app/overrides/services/hyrax/solr_query_service_override.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# https://github.com/samvera/hyrax/blob/v3.5.0/app/services/hyrax/solr_query_service.rb
# frozen_string_literal: true
Hyrax::SolrQueryService.module_eval do
def get(*args)
solr_service.post(build, *args)
def get(**args)
solr_service.post(build, **args)
end
end
Loading

0 comments on commit c088be3

Please sign in to comment.