hyrax 3.0.0 → 3.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) hide show
  1. checksums.yaml +4 -4
  2. data/.dassie/config/initializers/riiif.rb +22 -20
  3. data/.dassie/package.json +3 -5
  4. data/Dockerfile +34 -14
  5. data/app/controllers/hyrax/dashboard/collections_controller.rb +2 -4
  6. data/app/forms/hyrax/forms/collection_form.rb +5 -3
  7. data/app/indexers/hyrax/valkyrie_indexer.rb +2 -1
  8. data/app/presenters/hyrax/collection_presenter.rb +10 -14
  9. data/app/services/hyrax/listeners.rb +2 -0
  10. data/app/services/hyrax/listeners/member_cleanup_listener.rb +26 -0
  11. data/app/services/hyrax/listeners/object_lifecycle_listener.rb +1 -1
  12. data/app/services/hyrax/listeners/trophy_cleanup_listener.rb +17 -0
  13. data/app/services/hyrax/persist_derivatives.rb +3 -1
  14. data/app/services/hyrax/thumbnail_path_service.rb +1 -1
  15. data/app/services/hyrax/visibility_propagator.rb +30 -1
  16. data/app/views/hyrax/collections/show.html.erb +1 -1
  17. data/app/views/hyrax/dashboard/collections/_form_branding.html.erb +1 -1
  18. data/app/views/hyrax/file_sets/_actions.html.erb +10 -0
  19. data/chart/hyrax/Chart.yaml +2 -2
  20. data/chart/hyrax/templates/_helpers.tpl +8 -0
  21. data/chart/hyrax/templates/branding-pvc.yaml +14 -0
  22. data/chart/hyrax/templates/configmap-env.yaml +8 -1
  23. data/chart/hyrax/templates/deployment-worker.yaml +92 -0
  24. data/chart/hyrax/templates/deployment.yaml +42 -0
  25. data/chart/hyrax/templates/derivatives-pvc.yaml +14 -0
  26. data/chart/hyrax/templates/secrets.yaml +1 -0
  27. data/chart/hyrax/templates/uploads-pvc.yaml +14 -0
  28. data/chart/hyrax/values.yaml +31 -0
  29. data/config/features.rb +47 -43
  30. data/config/initializers/listeners.rb +2 -0
  31. data/documentation/developing-your-hyrax-based-app.md +4 -4
  32. data/documentation/legacyREADME.md +4 -4
  33. data/lib/generators/hyrax/templates/config/initializers/riiif.rb +22 -20
  34. data/lib/hyrax/configuration.rb +8 -0
  35. data/lib/hyrax/engine.rb +1 -1
  36. data/lib/hyrax/valkyrie_can_can_adapter.rb +2 -0
  37. data/lib/hyrax/version.rb +1 -1
  38. data/lib/wings/converter_value_mapper.rb +2 -2
  39. data/lib/wings/valkyrie/persister.rb +7 -5
  40. data/lib/wings/valkyrie/query_service.rb +60 -17
  41. data/template.rb +1 -1
  42. metadata +8 -2
@@ -367,6 +367,14 @@ module Hyrax
367
367
  @banner_image ||= 'https://user-images.githubusercontent.com/101482/29949206-ffa60d2c-8e67-11e7-988d-4910b8787d56.jpg'
368
368
  end
369
369
 
370
+ ##
371
+ # @return [Boolean]
372
+ def disable_wings
373
+ return @disable_wings unless @disable_wings.nil?
374
+ ActiveModel::Type::Boolean.new.cast(ENV.fetch('HYRAX_SKIP_WINGS', false))
375
+ end
376
+ attr_writer :disable_wings
377
+
370
378
  attr_writer :display_media_download_link
371
379
  # @return [Boolean]
372
380
  def display_media_download_link?
data/lib/hyrax/engine.rb CHANGED
@@ -82,7 +82,7 @@ module Hyrax
82
82
 
83
83
  initializer 'requires' do
84
84
  require 'power_converters'
85
- require 'wings'
85
+ require 'wings' unless Hyrax.config.disable_wings
86
86
  end
87
87
 
88
88
  initializer 'routing' do
@@ -20,6 +20,8 @@ module Hyrax
20
20
  # @raise Hyrax::ObjectNotFoundError
21
21
  def self.find(_model_class, id)
22
22
  Hyrax.query_service.find_by_alternate_identifier(alternate_identifier: id)
23
+ rescue Valkyrie::Persistence::ObjectNotFoundError => err
24
+ raise Hyrax::ObjectNotFoundError, err.message
23
25
  end
24
26
  end
25
27
  end
data/lib/hyrax/version.rb CHANGED
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module Hyrax
3
- VERSION = '3.0.0'
3
+ VERSION = '3.0.1'
4
4
  end
@@ -73,7 +73,7 @@ module Wings
73
73
  end
74
74
 
75
75
  def result
76
- collections = value.last.map { |id| ActiveFedora::Base.find(id.id) }
76
+ collections = value.last.map { |id| ActiveFedora::Base.find(id.to_s) }
77
77
  [:member_of_collections, collections]
78
78
  end
79
79
  end
@@ -86,7 +86,7 @@ module Wings
86
86
  end
87
87
 
88
88
  def result
89
- members = value.last.map { |id| ActiveFedora::Base.find(id.id) }
89
+ members = value.last.map { |id| ActiveFedora::Base.find(id.to_s) }
90
90
  [:members, members]
91
91
  end
92
92
  end
@@ -41,9 +41,10 @@ module Wings
41
41
  # @param [Valkyrie::Resource] resource
42
42
  # @return [Valkyrie::Resource] the persisted/updated resource
43
43
  def save_all(resources:)
44
- resources.map do |resource|
45
- save(resource: resource)
46
- end
44
+ resources.map { |resource| save(resource: resource) }
45
+ rescue ::Valkyrie::Persistence::StaleObjectError => _err
46
+ raise(::Valkyrie::Persistence::StaleObjectError,
47
+ "One or more resources have been updated by another process.")
47
48
  end
48
49
 
49
50
  # Deletes a resource persisted using ActiveFedora
@@ -51,7 +52,7 @@ module Wings
51
52
  # @return [Valkyrie::Resource] the deleted resource
52
53
  def delete(resource:)
53
54
  af_object = ActiveFedora::Base.new
54
- af_object.id = resource.alternate_ids.first.to_s
55
+ af_object.id = resource.id
55
56
  af_object.delete
56
57
  resource
57
58
  end
@@ -84,7 +85,8 @@ module Wings
84
85
  etag_lock_token_valid?(af_object: af_object, resource: resource) &&
85
86
  last_modified_lock_token_valid?(af_object: af_object, resource: resource)
86
87
 
87
- raise(::Valkyrie::Persistence::StaleObjectError, resource.id.to_s)
88
+ raise(::Valkyrie::Persistence::StaleObjectError,
89
+ "The object #{resource.id} has been updated by another process.")
88
90
  end
89
91
 
90
92
  ##
@@ -2,16 +2,32 @@
2
2
 
3
3
  module Wings
4
4
  module Valkyrie
5
+ ##
6
+ # @note does not support duplicates!
5
7
  class QueryService
6
8
  attr_reader :adapter
7
9
  extend Forwardable
8
10
  def_delegator :adapter, :resource_factory
9
11
 
10
- # @param adapter [Wings::Valkyrie::MetadataAdapter] The adapter which holds the resource_factory for this query_service.
12
+ ##
13
+ # @param adapter [Wings::Valkyrie::MetadataAdapter] The adapter which
14
+ # holds the resource_factory for this query_service.
11
15
  def initialize(adapter:)
12
16
  @adapter = adapter
13
17
  end
14
18
 
19
+ ##
20
+ # @param :model [Class]
21
+ #
22
+ # @return [Integer]
23
+ def count_all_of_model(model:)
24
+ ActiveFedora::Base
25
+ .where(has_model_ssim: [model_class_for(model).to_rdf_representation,
26
+ model.new.internal_resource.to_s])
27
+ .count
28
+ end
29
+
30
+ ##
15
31
  # WARNING: In general, prefer find_by_alternate_identifier over this
16
32
  # method.
17
33
  #
@@ -23,14 +39,17 @@ module Wings
23
39
  # start getting ObjectNotFoundErrors instead of the objects you wanted
24
40
  #
25
41
  # Find a record using a Valkyrie ID, and map it to a Valkyrie Resource
42
+ #
26
43
  # @param [Valkyrie::ID, String] id
27
44
  # @return [Valkyrie::Resource]
28
- # @raise [Hyrax::ObjectNotFoundError]
45
+ # @raise [Valkyrie::Persistence::ObjectNotFoundError]
29
46
  def find_by(id:)
30
47
  find_by_alternate_identifier(alternate_identifier: id)
31
48
  end
32
49
 
50
+ ##
33
51
  # Find all work/collection records, and map to Valkyrie Resources
52
+ #
34
53
  # @return [Array<Valkyrie::Resource>]
35
54
  def find_all
36
55
  ::ActiveFedora::Base.all.map do |obj|
@@ -38,7 +57,10 @@ module Wings
38
57
  end
39
58
  end
40
59
 
41
- # Find all work/collection records of a given model, and map to Valkyrie Resources
60
+ ##
61
+ # Find all work/collection records of a given model, and map to Valkyrie
62
+ # Resources
63
+ #
42
64
  # @param model [Class]
43
65
  # @return [Array<Valkyrie::Resource>]
44
66
  def find_all_of_model(model:)
@@ -73,11 +95,14 @@ module Wings
73
95
  end
74
96
  end
75
97
 
98
+ ##
76
99
  # Find a record using an alternate ID, and map it to a Valkyrie Resource
100
+ #
77
101
  # @param [Valkyrie::ID, String] id
78
102
  # @param [boolean] optionally return ActiveFedora object/errors
103
+ #
79
104
  # @return [Valkyrie::Resource]
80
- # @raise [Hyrax::ObjectNotFoundError]
105
+ # @raise [Valkyrie::Persistence::ObjectNotFoundError]
81
106
  def find_by_alternate_identifier(alternate_identifier:, use_valkyrie: true)
82
107
  raise(ArgumentError, 'id must be a Valkyrie::ID') unless
83
108
  alternate_identifier.respond_to?(:to_str)
@@ -87,12 +112,15 @@ module Wings
87
112
  use_valkyrie ? resource_factory.to_resource(object: af_object) : af_object
88
113
  rescue ActiveFedora::ObjectNotFoundError, Ldp::Gone => err
89
114
  raise err unless use_valkyrie
90
- raise Hyrax::ObjectNotFoundError
115
+ raise ::Valkyrie::Persistence::ObjectNotFoundError
91
116
  end
92
117
 
118
+ ##
93
119
  # Find all members of a given resource, and map to Valkyrie Resources
120
+ #
94
121
  # @param resource [Valkyrie::Resource]
95
122
  # @param model [Class]
123
+ #
96
124
  # @return [Array<Valkyrie::Resource>]
97
125
  def find_members(resource:, model: nil)
98
126
  return [] if resource.try(:member_ids).blank?
@@ -103,21 +131,27 @@ module Wings
103
131
  .select { |member_resource| model_class_for(member_resource.class) == find_model }
104
132
  end
105
133
 
134
+ ##
106
135
  # Find the Valkyrie Resources referenced by another Valkyrie Resource
136
+ #
107
137
  # @param resource [<Valkyrie::Resource>]
108
138
  # @param property [Symbol] the property holding the references to another resource
109
139
  # @return [Array<Valkyrie::Resource>]
110
- def find_references_by(resource:, property:)
111
- object = resource_factory.from_resource(resource: resource)
112
- object.send(property).map do |reference|
113
- af_id = find_id_for(reference)
114
- resource_factory.to_resource(object: ::ActiveFedora::Base.find(af_id))
140
+ def find_references_by(resource:, property:, model: nil)
141
+ return find_many_by_ids(ids: Array(resource.send(property))) unless model
142
+
143
+ results = resource.public_send(property).map do |reference|
144
+ resource_factory.to_resource(object: ::ActiveFedora::Base.find(reference))
115
145
  end
146
+
147
+ results.select { |r| r.class.name == model.name }
116
148
  rescue ActiveFedora::ObjectNotFoundError
117
149
  []
118
150
  end
119
151
 
152
+ ##
120
153
  # Get all resources which link to a resource or id with a given property.
154
+ #
121
155
  # @param resource [Valkyrie::Resource] The resource which is being referenced by
122
156
  # other resources.
123
157
  # @param resource [Valkyrie::ID] The id of the resource which is being referenced by
@@ -129,30 +163,37 @@ module Wings
129
163
  # @return [Array<Valkyrie::Resource>] All resources in the persistence backend
130
164
  # which have the ID of the given `resource` in their `property` property. Not
131
165
  # in order.
132
- def find_inverse_references_by(resource: nil, id: nil, property:)
166
+ def find_inverse_references_by(resource: nil, id: nil, model: nil, property:)
133
167
  raise ArgumentError, "Provide resource or id" unless resource || id
134
- id ||= resource.alternate_ids.first
168
+ id ||= resource.id
135
169
  raise ArgumentError, "Resource has no id; is it persisted?" unless id
136
- uri = Hyrax::Base.id_to_uri(id.to_s)
137
- ActiveFedora::Base.where("+(#{property}_ssim: \"#{uri}\" OR #{property}_ssim: \"#{id}\")").map do |obj|
170
+
171
+ active_fedora_model = model ? model_class_for(model) : ActiveFedora::Base
172
+
173
+ uri = active_fedora_model.id_to_uri(id.to_s)
174
+ active_fedora_model.where("+(#{property}_ssim: \"#{uri}\" OR #{property}_ssim: \"#{id}\")").map do |obj|
138
175
  resource_factory.to_resource(object: obj)
139
176
  end
140
177
  end
141
178
 
179
+ ##
142
180
  # Find all parents of a given resource.
181
+ #
143
182
  # @param resource [Valkyrie::Resource] The resource whose parents are being searched
144
183
  # for.
145
184
  # @return [Array<Valkyrie::Resource>] All resources which are parents of the given
146
185
  # `resource`. This means the resource's `id` appears in their `member_ids`
147
186
  # array.
148
187
  def find_parents(resource:)
149
- id = resource.alternate_ids.first
150
- ActiveFedora::Base.where("member_ids_ssim: \"#{id}\"").map do |obj|
188
+ ActiveFedora::Base.where("member_ids_ssim: \"#{resource.id}\"").map do |obj|
151
189
  resource_factory.to_resource(object: obj)
152
190
  end
153
191
  end
154
192
 
155
- # Constructs a Valkyrie::Persistence::CustomQueryContainer using this query service
193
+ ##
194
+ # Constructs a Valkyrie::Persistence::CustomQueryContainer using this
195
+ # query service
196
+ #
156
197
  # @return [Valkyrie::Persistence::CustomQueryContainer]
157
198
  def custom_queries
158
199
  @custom_queries ||= ::Valkyrie::Persistence::CustomQueryContainer.new(query_service: self)
@@ -160,7 +201,9 @@ module Wings
160
201
 
161
202
  private
162
203
 
204
+ ##
163
205
  # Determines whether or not an Object is a Valkyrie ID
206
+ #
164
207
  # @param [Object] id
165
208
  # @raise [ArgumentError]
166
209
  def validate_id(id)
data/template.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
  # Hack for https://github.com/rails/rails/issues/35153
3
3
  gsub_file 'Gemfile', /^gem ["']sqlite3["']$/, 'gem "sqlite3", "~> 1.3.0"'
4
- gem 'hyrax', '3.0.0'
4
+ gem 'hyrax', '3.0.1'
5
5
  run 'bundle install'
6
6
  generate 'hyrax:install', '-f'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hyrax
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.0
4
+ version: 3.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Justin Coyne
@@ -14,7 +14,7 @@ authors:
14
14
  autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
- date: 2021-03-24 00:00:00.000000000 Z
17
+ date: 2021-03-31 00:00:00.000000000 Z
18
18
  dependencies:
19
19
  - !ruby/object:Gem::Dependency
20
20
  name: rails
@@ -2108,9 +2108,11 @@ files:
2108
2108
  - app/services/hyrax/listeners/batch_notification_listener.rb
2109
2109
  - app/services/hyrax/listeners/file_set_lifecycle_listener.rb
2110
2110
  - app/services/hyrax/listeners/file_set_lifecycle_notification_listener.rb
2111
+ - app/services/hyrax/listeners/member_cleanup_listener.rb
2111
2112
  - app/services/hyrax/listeners/metadata_index_listener.rb
2112
2113
  - app/services/hyrax/listeners/object_lifecycle_listener.rb
2113
2114
  - app/services/hyrax/listeners/proxy_deposit_listener.rb
2115
+ - app/services/hyrax/listeners/trophy_cleanup_listener.rb
2114
2116
  - app/services/hyrax/listeners/workflow_listener.rb
2115
2117
  - app/services/hyrax/local_file_service.rb
2116
2118
  - app/services/hyrax/lock_manager.rb
@@ -2608,16 +2610,20 @@ files:
2608
2610
  - chart/hyrax/README.md
2609
2611
  - chart/hyrax/templates/NOTES.txt
2610
2612
  - chart/hyrax/templates/_helpers.tpl
2613
+ - chart/hyrax/templates/branding-pvc.yaml
2611
2614
  - chart/hyrax/templates/configmap-env.yaml
2612
2615
  - chart/hyrax/templates/cron-embargo.yaml
2613
2616
  - chart/hyrax/templates/cron-lease.yaml
2617
+ - chart/hyrax/templates/deployment-worker.yaml
2614
2618
  - chart/hyrax/templates/deployment.yaml
2619
+ - chart/hyrax/templates/derivatives-pvc.yaml
2615
2620
  - chart/hyrax/templates/hpa.yaml
2616
2621
  - chart/hyrax/templates/ingress.yaml
2617
2622
  - chart/hyrax/templates/secrets.yaml
2618
2623
  - chart/hyrax/templates/service.yaml
2619
2624
  - chart/hyrax/templates/serviceaccount.yaml
2620
2625
  - chart/hyrax/templates/tests/test-connection.yaml
2626
+ - chart/hyrax/templates/uploads-pvc.yaml
2621
2627
  - chart/hyrax/values.yaml
2622
2628
  - config/brakeman.ignore
2623
2629
  - config/features.rb