Skip to content

Commit

Permalink
Merge branch 'main' into double_combo
Browse files Browse the repository at this point in the history
* main:
  prepare release 5.0.1
  fix blueimp file upload progress bars
  Pin sprockets to fix feature specs (#6762)
  move file related listeners to their own space (#6743)
  Fix “::Collection” definition with autoloading
  use the `Hyrax::FileSetFileService` to determine "primary file"
  make `default_workflow_spec.rb` order independent
  Fix typo for the raise statement
  chart: add support for startupProbe
  use `find_files(file_set: file_set)` in various specs
  avoid n+1 query on file_metadata delete
  ♻️ Liberating Factories
  Prevent current_ability from failing when SingleUseLink doesn't exist, and make current user available via current_ability
  Add failing tests for current_user in single use links viewer controller
  • Loading branch information
jeremyf committed Apr 2, 2024
2 parents a5a0ae9 + 351e32b commit 8150e4f
Show file tree
Hide file tree
Showing 65 changed files with 172 additions and 78 deletions.
6 changes: 6 additions & 0 deletions app/assets/stylesheets/hyrax/_file_upload.scss
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,9 @@
padding-bottom: 10px;
}
}

// fix blueimp jQuery-File-Upload display problems under Bootstrap 4+
// found here: https://stackoverflow.com/a/48162651
.fade.in {
opacity: 1
}
2 changes: 1 addition & 1 deletion app/controllers/hyrax/file_sets_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ def wants_to_revert_valkyrie?
end

def file_metadata
@file_metadata ||= Hyrax.query_service.custom_queries.find_file_metadata_by(id: curation_concern.original_file_id)
@file_metadata ||= Hyrax.config.file_set_file_service.primary_file_for(file_set: file_set)
end

# Override this method to add additional response formats to your local app
Expand Down
11 changes: 9 additions & 2 deletions app/controllers/hyrax/single_use_links_viewer_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,13 @@ def asset
end

def current_ability
@current_ability ||= SingleUseLinksViewerController::Ability.new current_user, single_use_link
link_instance = nil
begin
link_instance = single_use_link
rescue ActiveRecord::RecordNotFound
Rails.logger.debug("Single user link was not found while getting current ability")
end
@current_ability ||= SingleUseLinksViewerController::Ability.new current_user, link_instance
end

def render_single_use_error(exception)
Expand All @@ -102,9 +108,10 @@ class Ability
include CanCan::Ability

attr_reader :single_use_link
attr_reader :current_user

def initialize(user, single_use_link)
@user = user || ::User.new
@current_user = user || ::User.new
return unless single_use_link

@single_use_link = single_use_link
Expand Down
14 changes: 13 additions & 1 deletion app/models/collection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,16 @@

# Provide plain collection model if not defined by the application.
# Needed until Hyrax internals do not assume its existence.
class ::Collection < Hyrax.config.collection_class; end unless '::Collection'.safe_constantize
class ::Collection < Hyrax.config.collection_class; end unless ActiveSupport::Dependencies.then do |deps|
# In autoloading environments, when referencing +::Collection+ from the
# initializer, make sure that +safe_constantize+ wouldn’t just try loading
# this file again (which would produce a runtime error). Do this by manually
# searching for the file which should define +::Collection+ and checking if it
# is the one being currently loaded.
break true if Object.const_defined?(:Collection)
file_path = deps.search_for_file("collection")
expanded = File.expand_path(file_path)
expanded.delete_suffix!(".rb")
break false if deps.loading.include?(expanded)
'::Collection'.safe_constantize
end
11 changes: 10 additions & 1 deletion app/services/hyrax/file_set_file_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,16 @@ def initialize(file_set:, query_service: Hyrax.query_service)
end

##
# Return the Hyrax::FileMetadata which should be considered “primary” for
# Return the {Hyrax::FileMetadata} which should be considered “primary” for
# indexing and version‐tracking.
#
# @return [Hyrax::FileMetadata]
def self.primary_file_for(file_set:, query_service: Hyrax.query_service)
new(file_set: file_set, query_service: query_service).primary_file
end

##
# Return the {Hyrax::FileMetadata} which should be considered “primary” for
# indexing and version‐tracking.
#
# If +file_set.original_file_id+ is defined, it will be used; otherwise,
Expand Down
39 changes: 39 additions & 0 deletions app/services/hyrax/listeners/file_listener.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# frozen_string_literal: true

module Hyrax
module Listeners
##
# Listens for events related to Files ({Valkyrie::StorageAdapter::File})
class FileListener
##
# Called when 'file.characterized' event is published;
# allows post-characterization handling, like derivatives generation.
#
# @param [Dry::Events::Event] event
# @return [void]
def on_file_characterized(event)
file_set = event[:file_set]

case file_set
when ActiveFedora::Base # ActiveFedora
CreateDerivativesJob
.perform_later(file_set, event[:file_id], event[:path_hint])
else
ValkyrieCreateDerivativesJob
.perform_later(file_set.id.to_s, event[:file_id])
end
end

##
# Called when 'file.uploaded' event is published
# @param [Dry::Events::Event] event
# @return [void]
def on_file_uploaded(event)
# Run characterization for original file only
return unless event[:metadata]&.original_file?

ValkyrieCharacterizationJob.perform_later(event[:metadata].id.to_s)
end
end
end
end
30 changes: 0 additions & 30 deletions app/services/hyrax/listeners/file_metadata_listener.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,6 @@ module Listeners
##
# Listens for events related to {Hyrax::FileMetadata}
class FileMetadataListener
##
# Called when 'file.characterized' event is published;
# allows post-characterization handling, like derivatives generation.
#
# @param [Dry::Events::Event] event
# @return [void]
def on_file_characterized(event)
file_set = event[:file_set]

case file_set
when ActiveFedora::Base # ActiveFedora
CreateDerivativesJob
.perform_later(file_set, event[:file_id], event[:path_hint])
else
ValkyrieCreateDerivativesJob
.perform_later(file_set.id.to_s, event[:file_id])
end
end

##
# Called when 'file.metadata.updated' event is published; reindexes a
# {Hyrax::FileSet} when a file claiming to be its `pcdm_use:OriginalFile`
Expand All @@ -41,17 +22,6 @@ def on_file_metadata_updated(event)
"encountered an error #{err.message}. should this " \
"object be in a FileSet #{event[:metadata]}"
end

##
# Called when 'file.uploaded' event is published
# @param [Dry::Events::Event] event
# @return [void]
def on_file_uploaded(event)
# Run characterization for original file only
return unless event[:metadata]&.original_file?

ValkyrieCharacterizationJob.perform_later(event[:metadata].id.to_s)
end
end
end
end
4 changes: 2 additions & 2 deletions app/services/hyrax/lock_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ def lock(key)
rescue ConnectionPool::TimeoutError => err
Hyrax.logger.error(err.message)
raise(ConnectionPool::TimeoutError,
"Failed to aquire a lock from Redlock due to a Redis connection " /
"timeout: #{err}. If you are using Redis via `ConnectionPool` " /
"Failed to acquire a lock from Redlock due to a Redis connection " \
"timeout: #{err}. If you are using Redis via `ConnectionPool` " \
"you may wish to increase the pool size.")
end

Expand Down
7 changes: 5 additions & 2 deletions app/services/hyrax/valkyrie_upload.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@ def self.file(
attr_reader :storage_adapter
##
# @param [Valkyrie::StorageAdapter] storage_adapter
def initialize(storage_adapter: Hyrax.storage_adapter)
# @param [Class] file_set_file_service implementer of {Hyrax::FileSetFileService}
def initialize(storage_adapter: Hyrax.storage_adapter, file_set_file_service: Hyrax.config.file_set_file_service)
@storage_adapter = storage_adapter
@file_set_file_service = file_set_file_service
end

def upload(filename:, file_set:, io:, use: Hyrax::FileMetadata::Use::ORIGINAL_FILE, user: nil, mime_type: nil) # rubocop:disable Metrics/AbcSize
Expand Down Expand Up @@ -67,7 +69,8 @@ def upload(filename:, file_set:, io:, use: Hyrax::FileMetadata::Use::ORIGINAL_FI
end

def version_upload(file_set:, io:, user:)
file_metadata = Hyrax.query_service.custom_queries.find_file_metadata_by(id: file_set.original_file_id)
file_metadata = @file_set_file_service.primary_file_for(file_set: file_set)

Hyrax::VersioningService.create(file_metadata, user, io)
Hyrax.publisher.publish("file.uploaded", metadata: file_metadata)
ContentNewVersionEventJob.perform_later(file_set, user)
Expand Down
18 changes: 9 additions & 9 deletions app/views/hyrax/uploads/_js_templates.html.erb
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
<!-- The template to display files available for upload -->
<% fade_class_if_not_test = Rails.env.test? ? 'show' : 'fade show' %>
<% fade_class_if_not_test = Rails.env.test? ? '' : 'fade' %>
<script id="template-upload" type="text/x-tmpl">
{% for (var i=0, file; file=o.files[i]; i++) { %}
<tr class="template-upload <%= fade_class_if_not_test %>">
<span>
<td>
<span class="preview"></span>
</span>
<span>
</td>
<td>
<p class="name">{%=file.name%}</p>
<strong class="error text-danger"></strong>
</span>
<span>
</td>
<td>
<p class="size">Processing...</p>
<div class="progress" role="progressbar" aria-valuemin="0" aria-valuemax="100" aria-valuenow="0"><div class="progress-bar progress-bar-striped progress-bar-animated bg-success" style="width:0%;"></div></div>
</span>
<span class="text-right">
</td>
<td class="text-right">
{% if (!i && !o.options.autoUpload) { %}
<button class="btn btn-primary start" disabled>
<span class="fa fa-upload"></span>
Expand All @@ -27,7 +27,7 @@
<span><%= t('helpers.action.cancel') %></span>
</button>
{% } %}
</span>
</td>
</tr>
{% } %}
</script>
Expand Down
6 changes: 3 additions & 3 deletions app/views/hyrax/uploads/_js_templates_branding.html.erb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<!-- The template to display files available for upload -->
<script id="template-upload" type="text/x-tmpl">
{% for (var i=0, file; file=o.files[i]; i++) { %}
<tr class="template-upload fade show">
<tr class="template-upload fade">
<td>
<span class="preview"></span>
</td>
Expand Down Expand Up @@ -37,7 +37,7 @@
<!-- The template to display the banner once upload is complete -->
<script id="template-download" type="text/x-tmpl">
{% for (var i=0, file; file=o.files[i]; i++) { %}
<span class="template-download fade show">
<span class="template-download fade">
<div id="banner">
<div class="row branding-banner-row">
<div class="col-sm-3">
Expand Down Expand Up @@ -69,7 +69,7 @@
<!-- The template to display logo in the table once upload is complete -->
<script id="logo-template-download" type="text/x-tmpl">
{% for (var i=0, file; file=o.files[i]; i++) { %}
<span class="template-download fade show">
<span class="template-download fade">
<div class="row branding-logo-row">
<div class="col-sm-3">
<span class="preview">
Expand Down
2 changes: 1 addition & 1 deletion app/views/hyrax/uploads/_js_templates_versioning.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!-- The template to display files available for upload -->
<% fade_class_if_not_test = Rails.env.test? ? 'show' : 'fade show' %>
<% fade_class_if_not_test = Rails.env.test? ? '' : 'fade' %>
<script id="versioning-template-upload" type="text/x-tmpl">
{% for (var i=0, file; file=o.files[i]; i++) { %}
<tr class="template-upload <%= fade_class_if_not_test %>">
Expand Down
2 changes: 1 addition & 1 deletion chart/hyrax/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apiVersion: v2
name: hyrax
description: An open-source, Samvera-powered digital repository system
type: application
version: 3.6.0
version: 3.7.0
appVersion: 5.0.0
dependencies:
- name: fcrepo
Expand Down
12 changes: 12 additions & 0 deletions chart/hyrax/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,18 @@ spec:
- name: http
containerPort: 3000
protocol: TCP
{{- if .Values.startupProbe.enabled }}
startupProbe:
initialDelaySeconds: {{ .Values.startupProbe.initialDelaySeconds | default 5 }}
timeoutSeconds: {{ .Values.startupProbe.timeoutSeconds | default 5 }}
failureThreshold: {{ .Values.startupProbe.failureThreshold | default 3 }}
periodSeconds: {{ .Values.startupProbe.periodSeconds | default 10}}
successThreshold: {{ .Values.startupProbe.successThreshold | default 1 }}
httpGet:
scheme: "HTTP"
path: {{ .Values.startupProbe.path | default "/" }}
port: 3000
{{- end }}
{{- if .Values.livenessProbe.enabled }}
livenessProbe:
initialDelaySeconds: {{ .Values.livenessProbe.initialDelaySeconds | default 5 }}
Expand Down
10 changes: 10 additions & 0 deletions chart/hyrax/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,16 @@ readinessProbe:
# failureThreshold: 6
# successThreshold: 1

# consider enabling if you are experiencing slow startup times
startupProbe:
enabled: false
# path: "/healthz"
# initialDelaySeconds: 30
# periodSeconds: 30
# timeoutSeconds: 5
# failureThreshold: 3
# successThreshold: 1

resources: {}

worker:
Expand Down
8 changes: 4 additions & 4 deletions documentation/developing-your-hyrax-based-app.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ You can also try [Running Hyrax-based application in local VM](https://github.co
During development, running only the dependent services in a container environment may be beneficial. This avoids potential headaches concerning file permissions and eases the use of debugging tools. The application generation instructions below use [Lando](https://lando.dev) to achieve this setup.

This document contains instructions specific to setting up an app with __Hyrax
v5.0.0__. If you are looking for instructions on installing a different
v5.0.1__. If you are looking for instructions on installing a different
version, be sure to select the appropriate branch or tag from the drop-down
menu above.

Expand Down Expand Up @@ -130,7 +130,7 @@ Rails requires that you have a JavaScript runtime installed (e.g. nodejs or ruby
Create a new Hyrax-based application by following these steps in order.

**NOTE:** Starting with Hyrax v5, the generated application will use [Valkyrie](https://github.com/samvera/valkyrie) for repository persistence.
Use of [ActiveFedora](https://github.com/samvera/active_fedora) (instead of Valkyrie) is deprecated, but it should still be possible to reconfigure the generated application to use it.
Use of [ActiveFedora](https://github.com/samvera/active_fedora) (instead of Valkyrie) is deprecated, but it should still be possible to reconfigure the generated application to use it.

### Development Prerequisites

Expand All @@ -145,10 +145,10 @@ These instructions assume the use of [Lando](https://lando.dev) and [Docker](htt

Generate a new Rails application using the template.

**NOTE:** `HYRAX_SKIP_WINGS` is needed here to avoid loading the Wings compatibility layer during the application generation process.
**NOTE:** `HYRAX_SKIP_WINGS` is needed here to avoid loading the Wings compatibility layer during the application generation process.

```shell
HYRAX_SKIP_WINGS=true rails _6.1.7.7_ new my_app --database=postgresql -m https://raw.githubusercontent.com/samvera/hyrax/hyrax-v5.0.0/template.rb
HYRAX_SKIP_WINGS=true rails _6.1.7.7_ new my_app --database=postgresql -m https://raw.githubusercontent.com/samvera/hyrax/hyrax-v5.0.1/template.rb
```

Generating a new Rails application using Hyrax's template above takes cares of a number of steps for you, including:
Expand Down
10 changes: 2 additions & 8 deletions hyrax.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,7 @@ SUMMARY
spec.homepage = "http://github.com/samvera/hyrax"

spec.files = `git ls-files`.split($OUTPUT_RECORD_SEPARATOR).reject do |f|
f == 'bin/rails' ||
# We want for downstream implementations to be able to leverage the various Hyrax factories.
# As such we need them to be available in the .gem file. See `./lib/hyrax/specs/factories.rb`
# for more details.
(File.dirname(f) =~ %r{\A"?spec\/?} &&
File.dirname(f) !~ %r{\A"?spec\/(factories|assets|support)\/?}
)
f == 'bin/rails' || File.dirname(f) =~ %r{\A"?spec\/?}
end
spec.executables = spec.files.grep(%r{^bin/}).map { |f| File.basename(f) }
spec.name = "hyrax"
Expand Down Expand Up @@ -91,7 +85,7 @@ SUMMARY
spec.add_dependency 'tinymce-rails', '~> 5.10'
spec.add_dependency 'valkyrie', '~> 3.1.1'
spec.add_dependency 'view_component', '~> 2.74.1' # Pin until blacklight is updated with workaround for https://github.com/ViewComponent/view_component/issues/1565
spec.add_dependency 'sprockets', '~> 3.7'
spec.add_dependency 'sprockets', '3.7.2' # 3.7.3 fails feature specs
spec.add_dependency 'sass-rails', '~> 6.0'
spec.add_dependency 'select2-rails', '~> 3.5'

Expand Down
11 changes: 11 additions & 0 deletions lib/hyrax/publisher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,16 @@ class Publisher

# @since 3.5.0
# @macro a_registered_event
# @note this event SHOULD be published file is characteried by the
# characterization service. Normally, this should happen close to
# when the `file.metadata.updated` event (since characterization
# typically involves updating the metadata). Listeners that intend
# to track updates to file metadata should listen on that event
# topic.
# The event payload MUST include a `:file_set` ({Hyrax::FileSet}),
# a `:file_id` (the id of the {Valkyrie::StorageAdapter::File}),
# and MAY have a `path_hint` for a local path / cache for the
# file.
register_event('file.characterized')

# @since 3.3.0
Expand Down Expand Up @@ -208,6 +218,7 @@ def default_listeners
@default_listeners ||=
[Hyrax::Listeners::ACLIndexListener.new,
Hyrax::Listeners::BatchNotificationListener.new,
Hyrax::Listeners::FileListener.new,
Hyrax::Listeners::FileMetadataListener.new,
Hyrax::Listeners::FileSetLifecycleListener.new,
Hyrax::Listeners::FileSetLifecycleNotificationListener.new,
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 8150e4f

Please sign in to comment.