hyrax 3.4.2 → 3.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (83) hide show
  1. checksums.yaml +4 -4
  2. data/app/actors/hyrax/actors/collections_membership_actor.rb +1 -1
  3. data/app/actors/hyrax/actors/embargo_actor.rb +11 -4
  4. data/app/actors/hyrax/actors/lease_actor.rb +11 -4
  5. data/app/assets/javascripts/hyrax/app.js.erb +1 -1
  6. data/app/assets/javascripts/hyrax/permissions/control.es6 +8 -1
  7. data/app/controllers/concerns/hyrax/embargoes_controller_behavior.rb +11 -2
  8. data/app/controllers/concerns/hyrax/leases_controller_behavior.rb +11 -2
  9. data/app/controllers/concerns/hyrax/manages_embargoes.rb +13 -1
  10. data/app/controllers/hyrax/dashboard/collections_controller.rb +1 -2
  11. data/app/controllers/hyrax/downloads_controller.rb +16 -1
  12. data/app/controllers/hyrax/file_sets_controller.rb +10 -1
  13. data/app/controllers/hyrax/permissions_controller.rb +1 -1
  14. data/app/controllers/hyrax/transfers_controller.rb +0 -2
  15. data/app/controllers/hyrax/workflow_actions_controller.rb +3 -2
  16. data/app/forms/hyrax/forms/dashboard/nest_collection_form.rb +2 -0
  17. data/app/forms/hyrax/forms/embargo.rb +13 -0
  18. data/app/forms/hyrax/forms/file_set_edit_form.rb +1 -1
  19. data/app/forms/hyrax/forms/file_set_form.rb +8 -35
  20. data/app/forms/hyrax/forms/lease.rb +13 -0
  21. data/app/forms/hyrax/forms/pcdm_object_form.rb +46 -0
  22. data/app/forms/hyrax/forms/resource_form.rb +36 -32
  23. data/app/forms/hyrax/forms/work_embargo_form.rb +35 -0
  24. data/app/forms/hyrax/forms/work_lease_form.rb +35 -0
  25. data/app/helpers/hyrax/embargo_helper.rb +11 -0
  26. data/app/helpers/hyrax/lease_helper.rb +11 -0
  27. data/app/indexers/hyrax/pcdm_collection_indexer.rb +1 -0
  28. data/app/indexers/hyrax/valkyrie_file_set_indexer.rb +2 -8
  29. data/app/jobs/content_event_job.rb +1 -1
  30. data/app/models/concerns/hyrax/collection_behavior.rb +2 -1
  31. data/app/models/concerns/hyrax/collection_nesting.rb +10 -1
  32. data/app/models/concerns/hyrax/file_set_behavior.rb +1 -0
  33. data/app/models/concerns/hyrax/work_behavior.rb +2 -1
  34. data/app/models/hyrax/embargo.rb +1 -1
  35. data/app/models/hyrax/file_set.rb +3 -3
  36. data/app/models/hyrax/lease.rb +1 -1
  37. data/app/models/proxy_deposit_request.rb +1 -1
  38. data/app/presenters/hyrax/permission_badge.rb +3 -2
  39. data/app/presenters/hyrax/version_list_presenter.rb +6 -1
  40. data/app/search_builders/hyrax/dashboard/nested_collections_search_builder.rb +13 -5
  41. data/app/services/hyrax/collections/nested_collection_query_service.rb +1 -1
  42. data/app/services/hyrax/edit_permissions_service.rb +21 -3
  43. data/app/services/hyrax/embargo_manager.rb +9 -0
  44. data/app/services/hyrax/file_set_file_service.rb +55 -0
  45. data/app/services/hyrax/lease_manager.rb +9 -0
  46. data/app/services/hyrax/user_stat_importer.rb +2 -0
  47. data/app/services/hyrax/versioning_service.rb +77 -9
  48. data/app/services/hyrax/visibility_propagator.rb +5 -5
  49. data/app/services/hyrax/work_resource_query_service.rb +45 -0
  50. data/app/views/hyrax/base/_form_progress.html.erb +1 -1
  51. data/app/views/hyrax/base/_form_visibility_component.html.erb +5 -1
  52. data/app/views/hyrax/embargoes/edit.html.erb +3 -3
  53. data/app/views/hyrax/file_sets/_permission.html.erb +1 -1
  54. data/app/views/hyrax/file_sets/_permission_form.html.erb +1 -6
  55. data/app/views/hyrax/file_sets/edit.html.erb +2 -2
  56. data/app/views/hyrax/leases/edit.html.erb +3 -3
  57. data/app/views/hyrax/transfers/new.html.erb +1 -1
  58. data/config/locales/hyrax.de.yml +2 -1
  59. data/config/locales/hyrax.en.yml +3 -0
  60. data/config/locales/hyrax.es.yml +1 -0
  61. data/config/locales/hyrax.fr.yml +2 -1
  62. data/config/locales/hyrax.it.yml +1 -0
  63. data/config/locales/hyrax.pt-BR.yml +1 -0
  64. data/config/locales/hyrax.zh.yml +1 -0
  65. data/config/metadata/file_set_metadata.yaml +130 -0
  66. data/documentation/developing-your-hyrax-based-app.md +2 -2
  67. data/documentation/legacyREADME.md +3 -3
  68. data/hyrax.gemspec +2 -0
  69. data/lib/generators/hyrax/templates/config/locales/hyrax.de.yml +1 -1
  70. data/lib/generators/hyrax/templates/config/locales/hyrax.en.yml +1 -1
  71. data/lib/generators/hyrax/templates/config/locales/hyrax.es.yml +1 -1
  72. data/lib/generators/hyrax/templates/config/locales/hyrax.fr.yml +1 -1
  73. data/lib/generators/hyrax/templates/config/locales/hyrax.it.yml +1 -1
  74. data/lib/generators/hyrax/templates/config/locales/hyrax.zh.yml +1 -1
  75. data/lib/hyrax/active_fedora_dummy_model.rb +13 -0
  76. data/lib/hyrax/configuration.rb +9 -2
  77. data/lib/hyrax/errors.rb +2 -0
  78. data/lib/hyrax/specs/shared_specs/factories/strategies/valkyrie_resource.rb +6 -0
  79. data/lib/hyrax/specs/shared_specs/indexers.rb +5 -0
  80. data/lib/hyrax/version.rb +1 -1
  81. data/lib/wings/valkyrie/storage.rb +6 -2
  82. data/template.rb +1 -1
  83. metadata +39 -3
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Hyrax
4
+ module Forms
5
+ ##
6
+ # Represents a lease for edit through a work. That is, this form can
7
+ # be used to wrap a Work in order to capture state changes related only to
8
+ # its lease, ignoring the work's other fields.
9
+ #
10
+ # @note this supports the edit functionality of
11
+ # +LeasesControllerBehavior+.
12
+ class WorkLeaseForm < Hyrax::ChangeSet
13
+ property :lease, form: Hyrax::Forms::Lease, populator: :lease_populator, prepopulator: :lease_populator
14
+ property :lease_expiration_date, virtual: true, prepopulator: ->(_opts) { self.lease_expiration_date = model.lease&.lease_expiration_date }
15
+ property :visibility_after_lease, virtual: true, prepopulator: ->(_opts) { self.visibility_after_lease = model.lease&.visibility_after_lease }
16
+ property :visibility_during_lease, virtual: true, prepopulator: ->(_opts) { self.visibility_during_lease = model.lease&.visibility_during_lease }
17
+
18
+ def lease_populator(**)
19
+ self.lease = Hyrax::LeaseManager.lease_for(resource: model)
20
+ end
21
+
22
+ ##
23
+ # @return [String]
24
+ def human_readable_type
25
+ model.to_model.human_readable_type
26
+ end
27
+
28
+ ##
29
+ # @return [ActiveModel::Name]
30
+ def model_name
31
+ model.to_model.model_name
32
+ end
33
+ end
34
+ end
35
+ end
@@ -40,5 +40,16 @@ module Hyrax
40
40
  Hyrax::EmbargoManager.new(resource: resource).enforced?
41
41
  end
42
42
  end
43
+
44
+ ##
45
+ # @since 3.5.0
46
+ #
47
+ # @param [#embargo_history, #embargo] resource
48
+ #
49
+ # @return [Array]
50
+ def embargo_history(resource)
51
+ resource.try(:embargo_history) ||
52
+ Array(resource.embargo&.embargo_history)
53
+ end
43
54
  end
44
55
  end
@@ -40,5 +40,16 @@ module Hyrax
40
40
  Hyrax::LeaseManager.new(resource: resource).enforced?
41
41
  end
42
42
  end
43
+
44
+ ##
45
+ # @since 3.5.0
46
+ #
47
+ # @param [#lease_history, #lease] resource
48
+ #
49
+ # @return [Array]
50
+ def lease_history(resource)
51
+ resource.try(:lease_history) ||
52
+ Array(resource.lease&.lease_history)
53
+ end
43
54
  end
44
55
  end
@@ -16,6 +16,7 @@ module Hyrax
16
16
  super.tap do |index_document|
17
17
  index_document[Hyrax.config.collection_type_index_field.to_sym] = Array(resource.try(:collection_type_gid)&.to_s)
18
18
  index_document[:generic_type_sim] = ['Collection']
19
+ index_document[:member_of_collection_ids_ssim] = resource.member_of_collection_ids.map(&:to_s)
19
20
  index_document[:depositor_ssim] = [resource.depositor]
20
21
  index_document[:depositor_tesim] = [resource.depositor]
21
22
  end
@@ -9,7 +9,7 @@ module Hyrax
9
9
  include Hyrax::VisibilityIndexer
10
10
  include Hyrax::ThumbnailIndexer
11
11
  include Hyrax::Indexer(:core_metadata)
12
- include Hyrax::Indexer(:basic_metadata)
12
+ include Hyrax::Indexer(:file_set_metadata)
13
13
 
14
14
  def to_solr # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity
15
15
  super.tap do |solr_doc| # rubocop:disable Metrics/BlockLength
@@ -23,7 +23,7 @@ module Hyrax
23
23
  solr_doc['hasRelatedImage_ssim'] = resource.thumbnail_id.to_s
24
24
 
25
25
  # Add in metadata from the original file.
26
- file_metadata = original_file
26
+ file_metadata = Hyrax::FileSetFileService.new(file_set: resource).original_file
27
27
  return solr_doc unless file_metadata
28
28
 
29
29
  # Label is the actual file name. It's not editable by the user.
@@ -99,12 +99,6 @@ module Hyrax
99
99
 
100
100
  private
101
101
 
102
- def original_file
103
- Hyrax.custom_queries.find_original_file(file_set: resource)
104
- rescue Valkyrie::Persistence::ObjectNotFoundError
105
- Hyrax.custom_queries.find_files(file_set: resource).first
106
- end
107
-
108
102
  def file_format(file)
109
103
  if file.mime_type.present? && file.format_label.present?
110
104
  "#{file.mime_type.split('/').last} (#{file.format_label.join(', ')})"
@@ -18,6 +18,6 @@ class ContentEventJob < EventJob
18
18
 
19
19
  # log the event to the users profile stream
20
20
  def log_user_event(depositor)
21
- depositor.log_profile_event(event)
21
+ depositor&.log_profile_event(event)
22
22
  end
23
23
  end
@@ -10,7 +10,8 @@ module Hyrax
10
10
  include Hyrax::HumanReadableType
11
11
  include Hyrax::HasRepresentative
12
12
  include Hyrax::Permissions
13
- include Hyrax::CollectionNesting
13
+ include(Hyrax::CollectionNesting) unless
14
+ Hyrax.config.use_solr_graph_for_collection_nesting
14
15
 
15
16
  included do
16
17
  validates_with HasOneTitleValidator
@@ -3,11 +3,20 @@ module Hyrax
3
3
  # Responsible for adding the necessary callbacks for updating the nested collection information
4
4
  # This is part of the after update index because it is a potentially very expensive process.
5
5
  #
6
- # @todo Consider extracting the update_index callback to ActiveFedora::Base
6
+ # @deprecation deprecated for removal in 4.0.0; nested reindexing is replaced by solr
7
+ # graph query. if you want to drop this behavior now, you can set
8
+ # +HYRAX_USE_SOLR_GRAPH_NESTING+ to +true+ in the environment.
7
9
  module CollectionNesting
8
10
  extend ActiveSupport::Concern
9
11
 
10
12
  included do
13
+ Deprecation.warn "Hyrax::CollectionNesting is deprecated for removal in " \
14
+ "4.0.0. Nested reindexing behavior can be replaced " \
15
+ "by a Solr graph traversal query. Legacy nested " \
16
+ "indexing behavior is retained by default, but can be " \
17
+ "replaced with the 4.0.0 default by setting " \
18
+ "HYRAX_USE_SOLR_GRAPH_NESTING to `true` in the environment."
19
+
11
20
  extend ActiveModel::Callbacks
12
21
  include ActiveModel::Validations::Callbacks
13
22
 
@@ -35,6 +35,7 @@ module Hyrax
35
35
 
36
36
  # Cast to a SolrDocument by querying from Solr
37
37
  def to_presenter
38
+ Deprecation.warn "Method #to_presenter will be removed in Hyrax 5.0. Use Hyrax::FileSetsController#presenter.solr_document or `@presenter.solr_document` from a view instead."
38
39
  CatalogController.new.fetch(id).last
39
40
  end
40
41
  end
@@ -21,7 +21,8 @@ module Hyrax
21
21
  include ProxyDeposit
22
22
  include Works::Metadata
23
23
  include WithEvents
24
- include Hyrax::CollectionNesting
24
+ include(Hyrax::CollectionNesting) unless
25
+ Hyrax.config.use_solr_graph_for_collection_nesting
25
26
 
26
27
  included do
27
28
  property :owner, predicate: RDF::URI.new('http://opaquenamespace.org/ns/hydra/owner'), multiple: false
@@ -15,7 +15,7 @@ module Hyrax
15
15
  attribute :embargo_history, Valkyrie::Types::Array
16
16
 
17
17
  def active?
18
- (embargo_release_date.present? && Time.zone.today < embargo_release_date)
18
+ (embargo_release_date.present? && Hyrax::TimeService.time_in_utc < embargo_release_date)
19
19
  end
20
20
  end
21
21
  end
@@ -31,7 +31,7 @@ module Hyrax
31
31
  # @see https://wiki.duraspace.org/display/samvera/Hydra%3A%3AWorks+Shared+Modeling
32
32
  class FileSet < Hyrax::Resource
33
33
  include Hyrax::Schema(:core_metadata)
34
- include Hyrax::Schema(:basic_metadata)
34
+ include Hyrax::Schema(:file_set_metadata)
35
35
 
36
36
  def self.model_name(name_class: Hyrax::Name)
37
37
  @_model_name ||= name_class.new(self, nil, 'FileSet')
@@ -42,8 +42,8 @@ module Hyrax
42
42
 
43
43
  attribute :file_ids, Valkyrie::Types::Array.of(Valkyrie::Types::ID) # id for FileMetadata resources
44
44
  attribute :thumbnail_id, Valkyrie::Types::ID.optional # id for FileMetadata resource
45
- attribute :original_file_id, Valkyrie::Types::ID # id for FileMetadata resource
46
- attribute :extracted_text_id, Valkyrie::Types::ID # id for FileMetadata resource
45
+ attribute :original_file_id, Valkyrie::Types::ID.optional # id for FileMetadata resource
46
+ attribute :extracted_text_id, Valkyrie::Types::ID.optional # id for FileMetadata resource
47
47
 
48
48
  ##
49
49
  # @return [Valkyrie::ID]
@@ -15,7 +15,7 @@ module Hyrax
15
15
  attribute :lease_history, Valkyrie::Types::Array
16
16
 
17
17
  def active?
18
- (lease_expiration_date.present? && Time.zone.today < lease_expiration_date)
18
+ (lease_expiration_date.present? && Hyrax::TimeService.time_in_utc < lease_expiration_date)
19
19
  end
20
20
  end
21
21
  end
@@ -7,7 +7,7 @@ class ProxyDepositRequest < ActiveRecord::Base
7
7
  include ActionView::Helpers::UrlHelper
8
8
 
9
9
  class_attribute :work_query_service_class
10
- self.work_query_service_class = Hyrax::WorkQueryService
10
+ self.work_query_service_class = Hyrax.config.use_valkyrie? ? Hyrax::WorkResourceQueryService : Hyrax::WorkQueryService
11
11
 
12
12
  delegate :deleted_work?, :work, :to_s, to: :work_query_service
13
13
 
@@ -24,14 +24,15 @@ module Hyrax
24
24
  private
25
25
 
26
26
  def dom_label_class
27
- VISIBILITY_LABEL_CLASS.fetch(@visibility.to_sym, 'label-info')
27
+ VISIBILITY_LABEL_CLASS.fetch(@visibility&.to_sym, 'label-info')
28
28
  end
29
29
 
30
30
  def text
31
31
  if registered?
32
32
  Institution.name
33
33
  else
34
- I18n.t("hyrax.visibility.#{@visibility}.text")
34
+ visibility_key = @visibility || 'unknown'
35
+ I18n.t("hyrax.visibility.#{visibility_key}.text")
35
36
  end
36
37
  end
37
38
 
@@ -19,7 +19,12 @@ module Hyrax
19
19
  #
20
20
  # @raise [ArgumentError] if we can't build an enu
21
21
  def self.for(file_set:)
22
- new(file_set.original_file&.versions&.all.to_a)
22
+ original_file = if file_set.respond_to?(:original_file)
23
+ file_set.original_file
24
+ else
25
+ Hyrax::FileSetFileService.new(file_set: file_set).original_file
26
+ end
27
+ new(Hyrax::VersioningService.new(resource: original_file).versions)
23
28
  rescue NoMethodError
24
29
  raise ArgumentError
25
30
  end
@@ -26,11 +26,19 @@ module Hyrax
26
26
 
27
27
  def show_only_other_collections_of_the_same_collection_type(solr_parameters)
28
28
  solr_parameters[:fq] ||= []
29
- solr_parameters[:fq] += [
30
- "-" + Hyrax::SolrQueryBuilderService.construct_query_for_ids([limit_ids]),
31
- Hyrax::SolrQueryBuilderService.construct_query(Hyrax.config.collection_type_index_field => @collection.collection_type_gid)
32
- ]
33
- solr_parameters[:fq] += limit_clause if limit_clause # add limits to prevent illegal nesting arrangements
29
+ if Hyrax.config.use_solr_graph_for_collection_nesting
30
+ solr_parameters[:fq] += [
31
+ Hyrax::SolrQueryBuilderService.construct_query(Hyrax.config.collection_type_index_field => @collection.collection_type_gid),
32
+ "-{!graph from=id to=member_of_collection_ids_ssim#{' maxDepth=1' if @nest_direction == :as_parent}}id:#{@collection.id}",
33
+ "-{!graph to=id from=member_of_collection_ids_ssim#{' maxDepth=1' if @nest_direction == :as_child}}id:#{@collection.id}"
34
+ ]
35
+ else
36
+ solr_parameters[:fq] += [
37
+ "-" + Hyrax::SolrQueryBuilderService.construct_query_for_ids([limit_ids]),
38
+ Hyrax::SolrQueryBuilderService.construct_query(Hyrax.config.collection_type_index_field => @collection.collection_type_gid)
39
+ ]
40
+ solr_parameters[:fq] += limit_clause if limit_clause # add limits to prevent illegal nesting arrangements
41
+ end
34
42
  end
35
43
 
36
44
  private
@@ -86,7 +86,7 @@ module Hyrax
86
86
  # id is in the response. Useful for validation.
87
87
  # @param nest_direction [Symbol] :as_child or :as_parent
88
88
  def self.query_solr(collection:, access:, scope:, limit_to_id:, nest_direction:)
89
- nesting_attributes = NestingAttributes.new(id: collection.id.to_s, scope: scope)
89
+ nesting_attributes = (Hyrax.config.use_solr_graph_for_collection_nesting ? nil : NestingAttributes.new(id: collection.id.to_s, scope: scope))
90
90
  query_builder = Hyrax::Dashboard::NestedCollectionsSearchBuilder.new(
91
91
  access: access,
92
92
  collection: collection,
@@ -20,17 +20,35 @@ module Hyrax
20
20
  # @note
21
21
  # +form object.class = SimpleForm::FormBuilder+
22
22
  # For works (i.e. GenericWork):
23
- # * form object.object = Hyrax::GenericWorkForm
24
- # * form object.object.model = GenericWork
23
+ # * form_object.object = Hyrax::GenericWorkForm
24
+ # * form_object.object.model = GenericWork
25
25
  # * use the work itself
26
26
  # For file_sets:
27
- # * form object.object.class = FileSet
27
+ # * form_object.object.class = FileSet
28
+ # * use work the file_set is in
29
+ # For file set forms:
30
+ # * form_object.object.class = Hyrax::Forms::FileSetForm OR
31
+ # Hyrax::Forms::FileSetEditForm
32
+ # * form_object.object.model = FileSet
28
33
  # * use work the file_set is in
29
34
  # No other object types are supported by this view.
30
35
  def self.build_service_object_from(form:, ability:)
31
36
  if form.object.respond_to?(:model) && form.object.model.work?
37
+ # The provided form object is a work form.
32
38
  new(object: form.object, ability: ability)
39
+ elsif form.object.respond_to?(:model) && form.object.model.file_set?
40
+ # The provided form object is a FileSet form. For Valkyrie forms
41
+ # (+Hyrax::Forms::FileSetForm+), +:in_works_ids+ is prepopulated onto
42
+ # the form object itself. For +Hyrax::Forms::FileSetEditForm+, the
43
+ # +:in_works+ method is present on the wrapped +:model+.
44
+ if form.object.is_a?(Hyrax::Forms::FileSetForm)
45
+ object_id = form.object.in_works_ids.first
46
+ new(object: Hyrax.query_service.find_by(id: object_id), ability: ability)
47
+ else
48
+ new(object: form.object.model.in_works.first, ability: ability)
49
+ end
33
50
  elsif form.object.file_set?
51
+ # The provided form object is a FileSet.
34
52
  new(object: form.object.in_works.first, ability: ability)
35
53
  end
36
54
  end
@@ -161,6 +161,15 @@ module Hyrax
161
161
  resource.embargo || Embargo.new
162
162
  end
163
163
 
164
+ ##
165
+ # Drop the embargo by setting its release date to `nil`.
166
+ #
167
+ # @return [void]
168
+ def nullify
169
+ return unless under_embargo?
170
+ embargo.embargo_release_date = nil
171
+ end
172
+
164
173
  ##
165
174
  # Sets the visibility of the resource to the embargo's visibility condition.
166
175
  # no-op if the embargo period is current.
@@ -0,0 +1,55 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Hyrax
4
+ ##
5
+ # A service for accessing specific Hyrax::FileMetadata objects referenced by a
6
+ # Hyrax::FileSet.
7
+ class FileSetFileService
8
+ ##
9
+ # @!attribute [r] file_set
10
+ # @return [Hyrax::FileSet]
11
+ attr_reader :file_set
12
+
13
+ ##
14
+ # @!attribute [r] query_service
15
+ # @return [#find_by]
16
+ attr_reader :query_service
17
+
18
+ ##
19
+ # @param resource [Hyrax::FileSet]
20
+ def initialize(file_set:, query_service: Hyrax.query_service)
21
+ @query_service = query_service
22
+ @file_set = file_set
23
+ end
24
+
25
+ ##
26
+ # Return the Hyrax::FileMetadata which should be considered “original” for
27
+ # indexing and version‐tracking.
28
+ #
29
+ # If +file_set.original_file_id+ is defined, it will be used; otherwise,
30
+ # this requires a custom query. The ultimate fallback, if no
31
+ # pcdm:OriginalFile is associated with the :file_set, is to just use the
32
+ # first file in its :file_ids.
33
+ #
34
+ # @return [Hyrax::FileMetadata]
35
+ def original_file
36
+ if file_set.original_file_id
37
+ # Always just use original_file_id if it is defined.
38
+ #
39
+ # NOTE: This needs to use :find_file_metadata_by, not :find_by, because
40
+ # at time of writing the latter does not work in Wings.
41
+ query_service.custom_queries.find_file_metadata_by(id: file_set.original_file_id)
42
+ else
43
+ # Cache the fallback to avoid needing to do this query twice.
44
+ #
45
+ # See NOTE above regarding use of :find_file_metadata_by.
46
+ @original_file ||= begin
47
+ query_service.custom_queries.find_original_file(file_set: file_set)
48
+ rescue Valkyrie::Persistence::ObjectNotFoundError
49
+ fallback_id = file_set.file_ids.first
50
+ query_service.custom_queries.find_file_metadata_by(id: fallback_id) if fallback_id
51
+ end
52
+ end
53
+ end
54
+ end
55
+ end
@@ -89,6 +89,15 @@ module Hyrax
89
89
  resource.lease || Lease.new
90
90
  end
91
91
 
92
+ ##
93
+ # Drop the lease by setting its release date to `nil`.
94
+ #
95
+ # @return [void]
96
+ def nullify
97
+ return unless under_lease?
98
+ lease.lease_expiration_date = nil
99
+ end
100
+
92
101
  ##
93
102
  # @return [Boolean]
94
103
  def release
@@ -84,6 +84,8 @@ module Hyrax
84
84
  rescue StandardError => exception
85
85
  log_message fail_message
86
86
  log_message "Last exception #{exception}"
87
+ # Without returning false, we return the results of log_message; which is true.
88
+ false
87
89
  end
88
90
 
89
91
  def date_since_last_cache(user)
@@ -1,7 +1,80 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Hyrax
4
+ ##
5
+ # Provides methods for dealing with versions of files across both ActiveFedora
6
+ # and Valkyrie.
7
+ #
8
+ # Note that many of the methods pertaining to version creation are currently
9
+ # implemented as static methods.
4
10
  class VersioningService
11
+ ##
12
+ # @!attribute [rw] resource
13
+ # @return [ActiveFedora::File | Hyrax::FileMetadata | NilClass]
14
+ attr_accessor :resource
15
+
16
+ ##
17
+ # @!attribute [r] storage_adapter
18
+ # @return [#supports?]
19
+ attr_reader :storage_adapter
20
+
21
+ ##
22
+ # @param resource [ActiveFedora::File | Hyrax::FileMetadata | NilClass]
23
+ def initialize(resource:, storage_adapter: Hyrax.storage_adapter)
24
+ @storage_adapter = storage_adapter
25
+ self.resource = resource
26
+ end
27
+
28
+ ##
29
+ # Returns an array of versions for the resource associated with this
30
+ # Hyrax::VersioningService.
31
+ #
32
+ # If the resource is nil, or if it is a Hyrax::FileMetadata and versioning
33
+ # is not supported in the storage adapter, an empty array will be returned.
34
+ def versions
35
+ if resource.nil?
36
+ []
37
+ elsif resource.is_a?(Hyrax::FileMetadata)
38
+ if storage_adapter.try(:"supports?", :versions)
39
+ storage_adapter.find_versions(id: resource.file_identifier).to_a
40
+ else
41
+ []
42
+ end
43
+ else
44
+ resource.versions.all.to_a
45
+ end
46
+ end
47
+
48
+ ##
49
+ # Returns the latest version of the file associated with this
50
+ # Hyrax::VersioningService.
51
+ def latest_version
52
+ versions.last
53
+ end
54
+
55
+ ##
56
+ # Returns the file ID of the latest version of the file associated with this
57
+ # Hyrax::VersioningService, or the ID of the file resource itself if no
58
+ # latest version is defined.
59
+ #
60
+ # If the resource is nil, this method returns an empty string.
61
+ def versioned_file_id
62
+ latest = latest_version
63
+ if latest
64
+ if latest.respond_to?(:id)
65
+ latest.id
66
+ else
67
+ Hyrax.config.translate_uri_to_id.call(latest.uri)
68
+ end
69
+ elsif resource.nil?
70
+ ""
71
+ elsif resource.is_a?(Hyrax::FileMetadata)
72
+ resource.file_identifier
73
+ else
74
+ resource.id
75
+ end
76
+ end
77
+
5
78
  class << self
6
79
  # Make a version and record the version committer
7
80
  # @param [ActiveFedora::File | Hyrax::FileMetadata] content
@@ -11,19 +84,14 @@ module Hyrax
11
84
  perform_create(content, user, use_valkyrie)
12
85
  end
13
86
 
14
- # @param [ActiveFedora::File | Hyrax::FileMetadata] content
87
+ # @param [ActiveFedora::File | Hyrax::FileMetadata] file
15
88
  def latest_version_of(file)
16
- file.versions.last
89
+ Hyrax::VersioningService.new(resource: file).latest_version
17
90
  end
18
91
 
19
- # @param [ActiveFedora::File | Hyrax::FileMetadata] content
92
+ # @param [ActiveFedora::File | Hyrax::FileMetadata] file
20
93
  def versioned_file_id(file)
21
- versions = file.versions.all
22
- if versions.present?
23
- Hyrax.config.translate_uri_to_id.call(versions.last.uri)
24
- else
25
- file.id
26
- end
94
+ Hyrax::VersioningService.new(resource: file).versioned_file_id
27
95
  end
28
96
 
29
97
  # Record the version committer of the last version
@@ -15,13 +15,13 @@ module Hyrax
15
15
  when Hyrax::Resource # Valkyrie
16
16
  ResourceVisibilityPropagator.new(source: source)
17
17
  else
18
- NullVisibilityPropogator.new(source: source)
18
+ NullVisibilityPropagator.new(source: source)
19
19
  end
20
20
  end
21
21
 
22
22
  ##
23
- # Provides a null/logging implementation of the visibility propogator.
24
- class NullVisibilityPropogator
23
+ # Provides a null/logging implementation of the visibility propagator.
24
+ class NullVisibilityPropagator
25
25
  ##
26
26
  # @!attribute [rw] source
27
27
  # @return [#visibility]
@@ -36,8 +36,8 @@ module Hyrax
36
36
  ##
37
37
  # @return [void]
38
38
  # @raise [RuntimeError] if we're in development mode
39
- def propogate
40
- message = "Tried to propogate visibility to members of #{source} " \
39
+ def propagate
40
+ message = "Tried to propagate visibility to members of #{source} " \
41
41
  "but didn't know what kind of object it is. Model " \
42
42
  "name #{source.try(:model_name)}. Called from #{caller[0]}."
43
43
 
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+ module Hyrax
3
+ # Responsible for retrieving information based on the given work.
4
+ #
5
+ # @see ProxyDepositRequest
6
+ # @see SolrDocument
7
+ # @see Hyrax::SolrService
8
+ # @note This was extracted from the ProxyDepositRequest, which was coordinating lots of effort. It was also an ActiveRecord object that required lots of Fedora/Solr interactions.
9
+ class WorkResourceQueryService
10
+ # @param [String] id - The id of the work
11
+ def initialize(id:)
12
+ @id = id
13
+ end
14
+ attr_reader :id
15
+
16
+ # @return [Boolean] if the work has been deleted
17
+ def deleted_work?
18
+ Hyrax.query_service.find_by(id: id)
19
+ false
20
+ rescue Valkyrie::Persistence::ObjectNotFoundError
21
+ true
22
+ end
23
+
24
+ def work
25
+ # Need to ensure it is a work?
26
+ resource = Hyrax.query_service.find_by(id: id)
27
+ raise ModelMismatchError, "Expected work but got #{resource.class}" unless resource.work?
28
+ resource
29
+ end
30
+
31
+ def to_s
32
+ if deleted_work?
33
+ 'work not found'
34
+ else
35
+ solr_doc.to_s
36
+ end
37
+ end
38
+
39
+ private
40
+
41
+ def solr_doc
42
+ @solr_doc ||= ::SolrDocument.new(Hyrax::SolrService.search_by_id(id))
43
+ end
44
+ end
45
+ end
@@ -19,7 +19,7 @@
19
19
  </div>
20
20
 
21
21
  <div class="set-access-controls list-group-item">
22
- <%= render 'form_visibility_component', f: f %>
22
+ <%= render 'form_visibility_component', f: f, save_work: true %>
23
23
  </div>
24
24
  <% if Flipflop.proxy_deposit? && current_user.can_make_deposits_for.any? %>
25
25
  <div class="list-group-item">
@@ -4,7 +4,11 @@
4
4
  <%= render 'form_permission_under_lease', f: f %>
5
5
  <% else %>
6
6
  <fieldset>
7
- <legend class="legend-save-work"><%= t('.visibility') %></legend>
7
+ <% if local_assigns[:save_work] %>
8
+ <legend class="legend-save-work"><%= t('.visibility') %></legend>
9
+ <% else %>
10
+ <legend><%= t('.visibility') %><%= raw(t('.subtitle_html')) %></legend>
11
+ <% end %>
8
12
  <ul class="visibility">
9
13
  <li class="radio">
10
14
  <label>