hyrax 3.4.1 → 3.4.2

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 (104) hide show
  1. checksums.yaml +4 -4
  2. data/.circleci/config.yml +26 -17
  3. data/.dassie/.env +1 -1
  4. data/.dassie/Gemfile +1 -1
  5. data/.dassie/app/forms/collection_resource_form.rb +8 -0
  6. data/.dassie/app/indexers/collection_resource_indexer.rb +8 -0
  7. data/.dassie/app/models/collection_resource.rb +35 -0
  8. data/.dassie/config/initializers/file_services.rb +4 -0
  9. data/.dassie/config/initializers/hyrax.rb +2 -1
  10. data/.dassie/config/metadata/collection_resource.yaml +23 -0
  11. data/.dassie/db/seeds.rb +2 -0
  12. data/.dassie/spec/forms/collection_resource_form_spec.rb +13 -0
  13. data/.dassie/spec/indexers/collection_resource_indexer_spec.rb +14 -0
  14. data/.dassie/spec/models/collection_resource_spec.rb +13 -0
  15. data/.regen +1 -1
  16. data/.rubocop.yml +1 -1
  17. data/.rubocop_fixme.yml +19 -2
  18. data/CONTAINERS.md +18 -13
  19. data/Dockerfile +2 -2
  20. data/app/assets/javascripts/hyrax/collections_v2.es6 +13 -0
  21. data/app/controllers/concerns/hyrax/collections_controller_behavior.rb +1 -3
  22. data/app/controllers/hyrax/dashboard/collections_controller.rb +159 -75
  23. data/app/controllers/hyrax/single_use_links_viewer_controller.rb +1 -1
  24. data/app/forms/hyrax/forms/collection_form.rb +1 -1
  25. data/app/forms/hyrax/forms/pcdm_collection_form.rb +29 -2
  26. data/app/forms/hyrax/forms/resource_form.rb +15 -1
  27. data/app/forms/hyrax/forms/widgets/admin_set_visibility.rb +1 -1
  28. data/app/indexers/hyrax/pcdm_collection_indexer.rb +0 -1
  29. data/app/jobs/characterize_job.rb +5 -1
  30. data/app/jobs/import_url_job.rb +4 -6
  31. data/app/jobs/valkyrie_ingest_job.rb +15 -77
  32. data/app/models/admin_set.rb +8 -0
  33. data/app/models/concerns/hyrax/collection_behavior.rb +1 -1
  34. data/app/models/concerns/hyrax/user.rb +11 -0
  35. data/app/models/concerns/hyrax/work_behavior.rb +1 -1
  36. data/app/models/featured_work_list.rb +0 -1
  37. data/app/models/hyrax/file_metadata.rb +32 -2
  38. data/app/models/hyrax/file_set.rb +1 -3
  39. data/app/models/hyrax/group.rb +19 -0
  40. data/app/models/hyrax/pcdm_collection.rb +0 -1
  41. data/app/models/job_io_wrapper.rb +1 -1
  42. data/app/presenters/hyrax/member_presenter_factory.rb +2 -4
  43. data/app/presenters/hyrax/work_show_presenter.rb +3 -3
  44. data/app/services/hyrax/access_control_list.rb +7 -6
  45. data/app/services/hyrax/adapters/nesting_index_adapter.rb +3 -3
  46. data/app/services/hyrax/characterization/valkyrie_characterization_service.rb +3 -5
  47. data/app/services/hyrax/collections/collection_member_service.rb +3 -5
  48. data/app/services/hyrax/listeners/file_metadata_listener.rb +11 -0
  49. data/app/services/hyrax/listeners/member_cleanup_listener.rb +14 -18
  50. data/app/services/hyrax/multiple_membership_checker.rb +2 -0
  51. data/app/services/hyrax/valkyrie_persist_derivatives.rb +50 -0
  52. data/app/services/hyrax/valkyrie_upload.rb +94 -0
  53. data/app/services/hyrax/workflow/workflow_importer.rb +7 -9
  54. data/app/services/hyrax/workflow/workflow_schema.rb +3 -5
  55. data/app/strategies/hyrax/strategies/yaml_strategy.rb +4 -6
  56. data/app/uploaders/hyrax/uploaded_file_uploader.rb +4 -4
  57. data/app/validators/hyrax/collection_membership_validator.rb +16 -15
  58. data/app/views/catalog/_index_header_list_default.html.erb +8 -1
  59. data/app/views/catalog/_thumbnail_list_default.html.erb +8 -3
  60. data/app/views/collections/edit_fields/_based_near.html.erb +7 -7
  61. data/app/views/hyrax/dashboard/collections/_form.html.erb +3 -2
  62. data/app/views/hyrax/dashboard/collections/_form_branding.html.erb +1 -0
  63. data/app/views/hyrax/dashboard/sidebar/_activity.html.erb +1 -1
  64. data/app/views/hyrax/my/works/_tabs.html.erb +6 -1
  65. data/chart/hyrax/Chart.yaml +10 -6
  66. data/chart/hyrax/templates/_helpers.tpl +4 -0
  67. data/chart/hyrax/templates/cron-embargo.yaml +5 -0
  68. data/chart/hyrax/templates/cron-lease.yaml +5 -0
  69. data/chart/hyrax/templates/deployment-worker.yaml +11 -0
  70. data/chart/hyrax/templates/ingress.yaml +7 -6
  71. data/chart/hyrax/values.yaml +152 -0
  72. data/config/features.rb +48 -50
  73. data/config/initializers/{valkryrie_storage.rb → storage_adapter_initializer.rb} +5 -0
  74. data/config/locales/hyrax.de.yml +12 -12
  75. data/docker-compose.yml +1 -0
  76. data/documentation/developing-your-hyrax-based-app.md +1 -1
  77. data/documentation/legacyREADME.md +1 -1
  78. data/hyrax.gemspec +5 -3
  79. data/lib/generators/hyrax/collection_resource/USAGE +20 -0
  80. data/lib/generators/hyrax/collection_resource/collection_resource_generator.rb +133 -0
  81. data/lib/generators/hyrax/collection_resource/templates/collection.rb.erb +34 -0
  82. data/lib/generators/hyrax/collection_resource/templates/collection_form.rb.erb +7 -0
  83. data/lib/generators/hyrax/collection_resource/templates/collection_form_spec.rb.erb +13 -0
  84. data/lib/generators/hyrax/collection_resource/templates/collection_indexer.rb.erb +7 -0
  85. data/lib/generators/hyrax/collection_resource/templates/collection_indexer_spec.rb.erb +13 -0
  86. data/lib/generators/hyrax/collection_resource/templates/collection_metadata.yaml +22 -0
  87. data/lib/generators/hyrax/collection_resource/templates/collection_spec.rb.erb +12 -0
  88. data/lib/generators/hyrax/install_generator.rb +9 -0
  89. data/lib/hyrax/configuration.rb +12 -0
  90. data/lib/hyrax/publisher.rb +4 -0
  91. data/lib/hyrax/specs/shared_specs/hydra_works.rb +0 -1
  92. data/lib/hyrax/transactions/collection_update.rb +2 -0
  93. data/lib/hyrax/transactions/container.rb +10 -0
  94. data/lib/hyrax/transactions/steps/save_collection_banner.rb +59 -0
  95. data/lib/hyrax/transactions/steps/save_collection_logo.rb +109 -0
  96. data/lib/hyrax/version.rb +1 -1
  97. data/lib/wings/active_fedora_converter/file_metadata_node.rb +48 -0
  98. data/lib/wings/active_fedora_converter/instance_builder.rb +68 -0
  99. data/lib/wings/active_fedora_converter.rb +3 -3
  100. data/lib/wings/services/custom_queries/find_file_metadata.rb +19 -8
  101. data/lib/wings/valkyrie/query_service.rb +4 -6
  102. data/template.rb +1 -1
  103. metadata +63 -13
  104. data/app/views/catalog/_index_header_list_hyrax_pcdm_collection.html.erb +0 -4
@@ -84,26 +84,13 @@ module Hyrax
84
84
  end
85
85
 
86
86
  def after_create
87
- if @collection.is_a?(ActiveFedora::Base)
88
- form
89
- set_default_permissions
90
- # if we are creating the new collection as a subcollection (via the nested collections controller),
91
- # we pass the parent_id through a hidden field in the form and link the two after the create.
92
- link_parent_collection(params[:parent_id]) unless params[:parent_id].nil?
93
- end
94
- respond_to do |format|
95
- Hyrax::SolrService.commit
96
- format.html { redirect_to edit_dashboard_collection_path(@collection), notice: t('hyrax.dashboard.my.action.collection_create_success') }
97
- format.json { render json: @collection, status: :created, location: dashboard_collection_path(@collection) }
98
- end
87
+ Deprecation.warn("Method `#after_create` will be removed in Hyrax 4.0.")
88
+ after_create_response # call private method for processing
99
89
  end
100
90
 
101
91
  def after_create_error
102
- form
103
- respond_to do |format|
104
- format.html { render action: 'new' }
105
- format.json { render json: @collection.errors, status: :unprocessable_entity }
106
- end
92
+ Deprecation.warn("Method `#after_create_error` will be removed in Hyrax 4.0.")
93
+ after_create_errors("") # call private method for processing
107
94
  end
108
95
 
109
96
  def create
@@ -112,57 +99,39 @@ module Hyrax
112
99
  # collection is saved without a value for `has_model.`
113
100
  @collection = Hyrax.config.collection_class.new
114
101
  authorize! :create, @collection
115
- return valkyrie_create if @collection.is_a?(Valkyrie::Resource)
116
102
 
117
- # Coming from the UI, a collection type gid should always be present. Coming from the API, if a collection type gid is not specified,
118
- # use the default collection type (provides backward compatibility with versions < Hyrax 2.1.0)
119
- @collection.collection_type_gid = params[:collection_type_gid].presence || default_collection_type.to_global_id
120
- @collection.attributes = collection_params.except(:members, :parent_id, :collection_type_gid)
121
- @collection.apply_depositor_metadata(current_user.user_key)
122
- @collection.visibility = Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_PRIVATE unless @collection.discoverable?
123
- if @collection.save
124
- after_create
125
- add_members_to_collection unless batch.empty?
103
+ case @collection
104
+ when ActiveFedora::Base
105
+ create_active_fedora_collection
126
106
  else
127
- after_create_error
107
+ create_valkyrie_collection
128
108
  end
129
109
  end
130
110
 
131
111
  def after_update
132
- respond_to do |format|
133
- format.html { redirect_to update_referer, notice: t('hyrax.dashboard.my.action.collection_update_success') }
134
- format.json { render json: @collection, status: :updated, location: dashboard_collection_path(@collection) }
135
- end
112
+ Deprecation.warn("Method `#after_update` will be removed in Hyrax 4.0.")
113
+ after_update_response # call private method for processing
136
114
  end
137
115
 
138
116
  def after_update_error
139
- form
140
- respond_to do |format|
141
- format.html { render action: 'edit' }
142
- format.json { render json: @collection.errors, status: :unprocessable_entity }
143
- end
117
+ Deprecation.warn("Method `#after_update_error` will be removed in Hyrax 4.0.")
118
+ after_update_errors(@collection.errors) # call private method for processing
144
119
  end
145
120
 
146
121
  def update
147
- unless params[:update_collection].nil?
148
- process_banner_input
149
- process_logo_input
150
- end
151
-
152
- process_member_changes
153
-
154
- return valkyrie_update if @collection.is_a?(Valkyrie::Resource)
155
-
156
- @collection.visibility = Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_PRIVATE unless @collection.discoverable?
157
- # we don't have to reindex the full graph when updating collection
158
- @collection.reindex_extent = Hyrax::Adapters::NestingIndexAdapter::LIMITED_REINDEX
159
- if @collection.update(collection_params.except(:members))
160
- after_update
122
+ case @collection
123
+ when ActiveFedora::Base
124
+ update_active_fedora_collection
161
125
  else
162
- after_update_error
126
+ update_valkyrie_collection
163
127
  end
164
128
  end
165
129
 
130
+ def process_branding
131
+ process_banner_input
132
+ process_logo_input
133
+ end
134
+
166
135
  def after_destroy(_id)
167
136
  # leaving id to avoid changing the method's parameters prior to release
168
137
  respond_to do |format|
@@ -215,28 +184,66 @@ module Hyrax
215
184
 
216
185
  private
217
186
 
218
- def valkyrie_create
219
- form.validate(collection_params) &&
220
- @collection = transactions['change_set.create_collection']
221
- .with_step_args(
222
- 'change_set.set_user_as_depositor' => { user: current_user },
223
- 'change_set.add_to_collections' => { collection_ids: Array(params[:parent_id]) },
224
- 'collection_resource.apply_collection_type_permissions' => { user: current_user }
225
- )
226
- .call(form)
227
- .value_or { return after_create_error }
187
+ def create_active_fedora_collection
188
+ # Coming from the UI, a collection type gid should always be present. Coming from the API, if a collection type gid is not specified,
189
+ # use the default collection type (provides backward compatibility with versions < Hyrax 2.1.0)
190
+ @collection.collection_type_gid = params[:collection_type_gid].presence || default_collection_type.to_global_id
191
+ @collection.attributes = collection_params.except(:members, :parent_id, :collection_type_gid)
192
+ @collection.apply_depositor_metadata(current_user.user_key)
193
+ @collection.visibility = Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_PRIVATE unless @collection.discoverable?
194
+ if @collection.save
195
+ after_create_response
196
+ else
197
+ after_create_errors(@collection.errors)
198
+ end
199
+ end
228
200
 
229
- after_create
230
- add_members_to_collection unless batch.empty?
231
- @collection
201
+ def create_valkyrie_collection
202
+ return after_create_errors(form_err_msg(form)) unless form.validate(collection_params)
203
+
204
+ result =
205
+ transactions['change_set.create_collection']
206
+ .with_step_args(
207
+ 'change_set.set_user_as_depositor' => { user: current_user },
208
+ 'change_set.add_to_collections' => { collection_ids: Array(params[:parent_id]) },
209
+ 'collection_resource.apply_collection_type_permissions' => { user: current_user }
210
+ )
211
+ .call(form)
212
+
213
+ @collection = result.value_or { return after_create_errors(result.failure.first) }
214
+ after_create_response
232
215
  end
233
216
 
234
- def valkyrie_update
235
- form.validate(collection_params) &&
236
- @collection = transactions['change_set.update_collection']
237
- .call(form)
238
- .value_or { return after_update_error }
239
- after_update
217
+ def update_active_fedora_collection
218
+ process_member_changes
219
+ process_branding
220
+
221
+ @collection.visibility = Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_PRIVATE unless @collection.discoverable?
222
+ # we don't have to reindex the full graph when updating collection
223
+ @collection.reindex_extent = Hyrax::Adapters::NestingIndexAdapter::LIMITED_REINDEX
224
+ if @collection.update(collection_params.except(:members))
225
+ after_update_response
226
+ else
227
+ after_update_errors(@collection.errors)
228
+ end
229
+ end
230
+
231
+ def update_valkyrie_collection
232
+ return after_update_errors(form_err_msg(form)) unless form.validate(collection_params)
233
+
234
+ result = transactions['change_set.update_collection']
235
+ .with_step_args(
236
+ 'collection_resource.save_collection_banner' => { update_banner_file_ids: params["banner_files"],
237
+ banner_unchanged_indicator: params["banner_unchanged"] },
238
+ 'collection_resource.save_collection_logo' => { update_logo_file_ids: params["logo_files"],
239
+ alttext_values: params["alttext"],
240
+ linkurl_values: params["linkurl"] }
241
+ )
242
+ .call(form)
243
+ @collection = result.value_or { return after_update_errors(result.failure.first) }
244
+
245
+ process_member_changes
246
+ after_update_response
240
247
  end
241
248
 
242
249
  def valkyrie_destroy
@@ -247,6 +254,14 @@ module Hyrax
247
254
  end
248
255
  end
249
256
 
257
+ def form_err_msg(form)
258
+ errmsg = []
259
+ form.errors.messages.each do |fld, err|
260
+ errmsg << "#{fld} #{err.to_sentence}"
261
+ end
262
+ errmsg.to_sentence
263
+ end
264
+
250
265
  def default_collection_type
251
266
  Hyrax::CollectionType.find_or_create_default_collection_type
252
267
  end
@@ -376,9 +391,7 @@ module Hyrax
376
391
  end
377
392
 
378
393
  def presenter
379
- @presenter ||= begin
380
- presenter_class.new(curation_concern, current_ability)
381
- end
394
+ @presenter ||= presenter_class.new(curation_concern, current_ability)
382
395
  end
383
396
 
384
397
  def curation_concern
@@ -499,7 +512,9 @@ module Hyrax
499
512
  @form ||=
500
513
  case @collection
501
514
  when Valkyrie::Resource
502
- Hyrax::Forms::ResourceForm.for(@collection)
515
+ form = Hyrax::Forms::ResourceForm.for(@collection)
516
+ form.prepopulate!
517
+ form
503
518
  else
504
519
  form_class.new(@collection, current_ability, repository)
505
520
  end
@@ -562,6 +577,75 @@ module Hyrax
562
577
  def valid_url?(url)
563
578
  (url =~ URI.regexp(['http', 'https']))
564
579
  end
580
+
581
+ def after_create_response
582
+ if @collection.is_a?(ActiveFedora::Base)
583
+ form
584
+ set_default_permissions
585
+ # if we are creating the new collection as a subcollection (via the nested collections controller),
586
+ # we pass the parent_id through a hidden field in the form and link the two after the create.
587
+ link_parent_collection(params[:parent_id]) unless params[:parent_id].nil?
588
+ end
589
+ respond_to do |format|
590
+ Hyrax::SolrService.commit
591
+ format.html { redirect_to edit_dashboard_collection_path(@collection), notice: t('hyrax.dashboard.my.action.collection_create_success') }
592
+ format.json { render json: @collection, status: :created, location: dashboard_collection_path(@collection) }
593
+ end
594
+ add_members_to_collection unless batch.empty?
595
+ end
596
+
597
+ def after_create_errors_for_active_fedora(errors)
598
+ form
599
+ respond_to do |format|
600
+ format.html do
601
+ flash[:error] = errors.to_s
602
+ render action: 'new'
603
+ end
604
+ format.json { render json: @collection.errors, status: :unprocessable_entity }
605
+ end
606
+ end
607
+
608
+ def after_create_errors(errors) # for valkyrie
609
+ return after_create_errors_for_active_fedora(errors) if @collection.is_a? ActiveFedora::Base
610
+ respond_to do |wants|
611
+ wants.html do
612
+ flash[:error] = errors.to_s
613
+ render 'new', status: :unprocessable_entity
614
+ end
615
+ wants.json do
616
+ render_json_response(response_type: :unprocessable_entity, options: { errors: errors })
617
+ end
618
+ end
619
+ end
620
+
621
+ def after_update_response
622
+ respond_to do |format|
623
+ format.html { redirect_to update_referer, notice: t('hyrax.dashboard.my.action.collection_update_success') }
624
+ format.json { render json: @collection, status: :updated, location: dashboard_collection_path(@collection) }
625
+ end
626
+ end
627
+
628
+ def after_update_errors_for_active_fedora(errors)
629
+ form
630
+ respond_to do |format|
631
+ format.html do
632
+ flash[:error] = errors.to_s
633
+ render action: 'edit'
634
+ end
635
+ format.json { render json: @collection.errors, status: :unprocessable_entity }
636
+ end
637
+ end
638
+
639
+ def after_update_errors(errors) # for valkyrie
640
+ return after_update_errors_for_active_fedora(errors) if @collection.is_a? ActiveFedora::Base
641
+ respond_to do |wants|
642
+ wants.html do
643
+ flash[:error] = errors.to_s
644
+ render 'edit', status: :unprocessable_entity
645
+ end
646
+ wants.json { render_json_response(response_type: :unprocessable_entity, options: { errors: errors }) }
647
+ end
648
+ end
565
649
  end
566
650
  end
567
651
  end
@@ -75,7 +75,7 @@ module Hyrax
75
75
 
76
76
  def render_single_use_error(exception)
77
77
  logger.error("Rendering PAGE due to exception: #{exception.inspect} - #{exception.backtrace if exception.respond_to? :backtrace}")
78
- render 'single_use_error', layout: "error", status: 404
78
+ render 'single_use_error', layout: "error", status: :not_found
79
79
  end
80
80
 
81
81
  def _prefixes
@@ -9,7 +9,7 @@ module Hyrax
9
9
  attr_reader :scope
10
10
 
11
11
  delegate :id, :depositor, :permissions, :human_readable_type, :member_ids, :nestable?,
12
- :alternative_title, to: :model
12
+ :alternative_title, :visibility, to: :model
13
13
 
14
14
  class_attribute :membership_service_class
15
15
 
@@ -6,7 +6,32 @@ module Hyrax
6
6
  # @api public
7
7
  # @see https://github.com/samvera/valkyrie/wiki/ChangeSets-and-Dirty-Tracking
8
8
  class PcdmCollectionForm < Valkyrie::ChangeSet # rubocop:disable Metrics/ClassLength
9
- property :title, required: true, primary: true
9
+ include Hyrax::FormFields(:core_metadata)
10
+
11
+ BannerInfoPrepopulator = lambda do |_options|
12
+ self.banner_info ||= begin
13
+ banner_info = CollectionBrandingInfo.where(collection_id: id.to_s, role: "banner")
14
+ banner_file = File.split(banner_info.first.local_path).last unless banner_info.empty?
15
+ alttext = banner_info.first.alt_text unless banner_info.empty?
16
+ file_location = banner_info.first.local_path unless banner_info.empty?
17
+ relative_path = "/" + banner_info.first.local_path.split("/")[-4..-1].join("/") unless banner_info.empty?
18
+ { file: banner_file, full_path: file_location, relative_path: relative_path, alttext: alttext }
19
+ end
20
+ end
21
+
22
+ LogoInfoPrepopulator = lambda do |_options|
23
+ self.logo_info ||= begin
24
+ logos_info = CollectionBrandingInfo.where(collection_id: id.to_s, role: "logo")
25
+
26
+ logos_info.map do |logo_info|
27
+ logo_file = File.split(logo_info.local_path).last
28
+ relative_path = "/" + logo_info.local_path.split("/")[-4..-1].join("/")
29
+ alttext = logo_info.alt_text
30
+ linkurl = logo_info.target_url
31
+ { file: logo_file, full_path: logo_info.local_path, relative_path: relative_path, alttext: alttext, linkurl: linkurl }
32
+ end
33
+ end
34
+ end
10
35
 
11
36
  property :human_readable_type, writable: false
12
37
  property :date_modified, readable: false
@@ -18,9 +43,11 @@ module Hyrax
18
43
 
19
44
  property :member_of_collection_ids, default: [], type: Valkyrie::Types::Array
20
45
 
21
- validates :title, presence: true
22
46
  validates :collection_type_gid, presence: true
23
47
 
48
+ property :banner_info, virtual: true, prepopulator: BannerInfoPrepopulator
49
+ property :logo_info, virtual: true, prepopulator: LogoInfoPrepopulator
50
+
24
51
  class << self
25
52
  def model_class
26
53
  Hyrax::PcdmCollection
@@ -99,7 +99,7 @@ module Hyrax
99
99
  property :in_works_ids, virtual: true, prepopulator: InWorksPrepopulator
100
100
  property :member_ids, default: [], type: Valkyrie::Types::Array
101
101
  property :member_of_collection_ids, default: [], type: Valkyrie::Types::Array
102
- property :member_of_collections_attributes, virtual: true
102
+ property :member_of_collections_attributes, virtual: true, populator: :in_collections_populator
103
103
  validates_with CollectionMembershipValidator
104
104
 
105
105
  property :representative_id, type: Valkyrie::Types::String
@@ -208,6 +208,20 @@ module Hyrax
208
208
 
209
209
  private
210
210
 
211
+ def in_collections_populator(fragment:, **_options)
212
+ adds = []
213
+ deletes = []
214
+ fragment.each do |_, h|
215
+ if h["_destroy"] == "true"
216
+ deletes << Valkyrie::ID.new(h["id"])
217
+ else
218
+ adds << Valkyrie::ID.new(h["id"])
219
+ end
220
+ end
221
+
222
+ self.member_of_collection_ids = ((member_of_collection_ids + adds) - deletes).uniq
223
+ end
224
+
211
225
  # https://trailblazer.to/2.1/docs/reform.html#reform-populators-populator-collections
212
226
  def permission_populator(collection:, index:, **)
213
227
  Hyrax::Forms::Permission.new(collection[index])
@@ -6,7 +6,7 @@ module Hyrax
6
6
  # Visibility options for permission templates
7
7
  def options
8
8
  i18n_prefix = "hyrax.admin.admin_sets.form_visibility.visibility"
9
- # Note: Visibility 'varies' = '' implies no constraints
9
+ # NOTE: Visibility 'varies' = '' implies no constraints
10
10
  [[Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_PUBLIC, I18n.t('.everyone', scope: i18n_prefix)],
11
11
  ['', I18n.t('.varies', scope: i18n_prefix)],
12
12
  [Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_AUTHENTICATED, I18n.t('.institution', scope: i18n_prefix)],
@@ -9,7 +9,6 @@ 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)
13
12
 
14
13
  self.thumbnail_path_service = CollectionThumbnailPathService
15
14
 
@@ -31,7 +31,11 @@ class CharacterizeJob < Hyrax::ApplicationJob
31
31
  raise "#{file_set.class.characterization_proxy} was not found for FileSet #{file_set.id}" unless file_set.characterization_proxy?
32
32
  filepath = Hyrax::WorkingDirectory.find_or_retrieve(file_id, file_set.id) unless filepath && File.exist?(filepath)
33
33
  characterize(file_set, file_id, filepath)
34
- CreateDerivativesJob.perform_later(file_set, file_id, filepath)
34
+
35
+ Hyrax.publisher.publish('file.characterized',
36
+ file_set: file_set,
37
+ file_id: file_id,
38
+ path_hint: filepath)
35
39
  end
36
40
 
37
41
  private
@@ -80,12 +80,10 @@ class ImportUrlJob < Hyrax::ApplicationJob
80
80
  Rails.logger.debug("ImportUrlJob: Copying <#{uri}> to #{dir}")
81
81
 
82
82
  File.open(File.join(dir, filename), 'wb') do |f|
83
- begin
84
- write_file(f)
85
- yield f
86
- rescue StandardError => e
87
- send_error(e.message)
88
- end
83
+ write_file(f)
84
+ yield f
85
+ rescue StandardError => e
86
+ send_error(e.message)
89
87
  end
90
88
  Rails.logger.debug("ImportUrlJob: Closing #{File.join(dir, filename)}")
91
89
  end
@@ -21,104 +21,42 @@ class ValkyrieIngestJob < Hyrax::ApplicationJob
21
21
  #
22
22
  # @param [Hyrax::UploadedFile] file
23
23
  # @param [RDF::URI] pcdm_use
24
-
25
24
  # @return [void]
26
25
  def ingest(file:, pcdm_use:)
27
26
  file_set_uri = Valkyrie::ID.new(file.file_set_uri)
28
27
  file_set = Hyrax.query_service.find_by(id: file_set_uri)
29
28
 
30
- updated_metadata = upload_file(file: file, file_set: file_set, pcdm_use: pcdm_use)
31
-
32
- add_file_to_file_set(file_set: file_set,
33
- file_metadata: updated_metadata,
34
- user: file.user)
29
+ updated_metadata = upload_file(
30
+ file: file,
31
+ file_set: file_set,
32
+ pcdm_use: pcdm_use,
33
+ user: file.user
34
+ )
35
35
 
36
36
  ValkyrieCreateDerivativesJob.perform_later(file_set.id.to_s, updated_metadata.id.to_s)
37
37
  end
38
38
 
39
- ##
40
- # @api private
41
- #
42
- # @param [Hyrax::FileSet] file_set the file set to add to
43
- # @param [Hyrax::FileMetadata] file_metadata the metadata object representing
44
- # the file to add
45
- # @param [::User] user the user performing the add
46
- #
47
- # @return [Hyrax::FileSet] updated file set
48
- def add_file_to_file_set(file_set:, file_metadata:, user:)
49
- file_set.file_ids << file_metadata.id
50
- set_file_use_ids(file_set, file_metadata)
51
-
52
- Hyrax.persister.save(resource: file_set)
53
- Hyrax.publisher.publish('object.membership.updated', object: file_set, user: user)
54
- end
55
-
56
39
  ##
57
40
  # @api private
58
41
  #
59
42
  # @param [Hyrax::UploadedFile] file
60
43
  # @param [Hyrax::FileSet] file_set
61
44
  # @param [RDF::URI] pcdm_use the use/type to apply to the created FileMetadata
45
+ # @param [User] user
62
46
  #
63
47
  # @return [Hyrax::FileMetadata] the metadata representing the uploaded file
64
- def upload_file(file:, file_set:, pcdm_use:) # rubocop:disable Metrics/MethodLength
48
+ def upload_file(file:, file_set:, pcdm_use:, user: nil)
65
49
  carrier_wave_sanitized_file = file.uploader.file
66
50
  # Pull file, since carrierwave files don't respond to a proper IO #read. See
67
51
  # https://github.com/carrierwaveuploader/carrierwave/issues/1959
68
52
  file_io = carrier_wave_sanitized_file.to_file
69
- uploaded = Hyrax.storage_adapter
70
- .upload(resource: file_set,
71
- file: file_io,
72
- original_filename: carrier_wave_sanitized_file.original_filename)
73
-
74
- file_metadata = find_or_create_metadata(id: uploaded.id, file: carrier_wave_sanitized_file)
75
-
76
- file_metadata.type << pcdm_use
77
- file_metadata.file_set_id = file.file_set_uri
78
- file_metadata.file_identifier = uploaded.id
79
- file_metadata.size = uploaded.size
80
53
 
81
- saved_metadata = Hyrax.persister.save(resource: file_metadata)
82
- Hyrax.publisher.publish("object.file.uploaded", metadata: saved_metadata)
83
- file_io.close
84
-
85
- if pcdm_use == Hyrax::FileMetadata::Use::ORIGINAL_FILE
86
- # Set file set label.
87
- reset_title = file_set.title.first == file_set.label
88
- # set title to label if that's how it was before this characterization
89
- file_set.title = file_metadata.original_filename if reset_title
90
- # always set the label to the original_name
91
- file_set.label = file_metadata.original_filename
92
- end
93
-
94
- saved_metadata
95
- end
96
-
97
- ##
98
- # @api private
99
- def find_or_create_metadata(id:, file:)
100
- Hyrax.custom_queries.find_file_metadata_by(id: id)
101
- rescue Valkyrie::Persistence::ObjectNotFoundError => e
102
- Hyrax.logger.warn "Failed to find existing metadata for #{id}:"
103
- Hyrax.logger.warn e.message
104
- Hyrax.logger.warn "Creating Hyrax::FileMetadata now"
105
- Hyrax::FileMetadata.for(file: file)
106
- end
107
-
108
- ##
109
- # @api private
110
- def set_file_use_ids(file_set, file_metadata)
111
- file_metadata.type.each do |type|
112
- case type
113
- when Hyrax::FileMetadata::Use::ORIGINAL_FILE
114
- file_set.original_file_id = file_metadata.id
115
- when Hyrax::FileMetadata::Use::THUMBNAIL
116
- file_set.thumbnail_id = file_metadata.id
117
- when Hyrax::FileMetadata::Use::EXTRACTED_TEXT
118
- file_set.extracted_text_id = file_metadata.id
119
- else
120
- Rails.logger.warn "Unknown file use #{file_metadata.type} specified for #{file_metadata.file_identifier}"
121
- end
122
- end
54
+ ::Hyrax::ValkyrieUpload.file(
55
+ io: file_io,
56
+ filename: carrier_wave_sanitized_file.original_filename,
57
+ file_set: file_set,
58
+ use: pcdm_use,
59
+ user: user
60
+ )
123
61
  end
124
62
  end
@@ -97,6 +97,14 @@ class AdminSet < ActiveFedora::Base
97
97
  permission_template.reset_access_controls_for(collection: self)
98
98
  end
99
99
 
100
+ # @api public
101
+ #
102
+ # return an id for the AdminSet.
103
+ # defaults to calling Hyrax::Noid, but needs a fall back if noid is off
104
+ def assign_id
105
+ super || SecureRandom.uuid
106
+ end
107
+
100
108
  private
101
109
 
102
110
  def destroy_permission_template
@@ -87,7 +87,7 @@ module Hyrax
87
87
 
88
88
  module ClassMethods
89
89
  # This governs which partial to draw when you render this type of object
90
- def _to_partial_path #:nodoc:
90
+ def _to_partial_path # :nodoc:
91
91
  @_to_partial_path ||= begin
92
92
  element = ActiveSupport::Inflector.underscore(ActiveSupport::Inflector.demodulize(name))
93
93
  collection = ActiveSupport::Inflector.tableize(name)
@@ -53,6 +53,13 @@ module Hyrax::User
53
53
  public_send(self.class.user_key_field)
54
54
  end
55
55
 
56
+ ##
57
+ # @return [String] a local identifier for this user; for use (e.g.) in ACL
58
+ # data
59
+ def agent_key
60
+ user_key
61
+ end
62
+
56
63
  # Look for, in order:
57
64
  # A cached version of the agent
58
65
  # A non-cached version (direct read of the database)
@@ -177,6 +184,10 @@ module Hyrax::User
177
184
  User.find_by_user_key(user_key) || User.create!(user_key_field => user_key, password: Devise.friendly_token[0, 20])
178
185
  end
179
186
 
187
+ def from_agent_key(key)
188
+ User.find_by_user_key(key)
189
+ end
190
+
180
191
  def from_url_component(component)
181
192
  User.find_by_user_key(component.gsub(/-dot-/, '.'))
182
193
  end
@@ -34,7 +34,7 @@ module Hyrax
34
34
 
35
35
  module ClassMethods
36
36
  # This governs which partial to draw when you render this type of object
37
- def _to_partial_path #:nodoc:
37
+ def _to_partial_path # :nodoc:
38
38
  @_to_partial_path ||= begin
39
39
  element = ActiveSupport::Inflector.underscore(ActiveSupport::Inflector.demodulize(name))
40
40
  collection = ActiveSupport::Inflector.tableize(name)
@@ -18,7 +18,6 @@ class FeaturedWorkList
18
18
  @works = FeaturedWork.all
19
19
  add_solr_document_to_works
20
20
  @works = @works.reject do |work|
21
- work.destroy if work.presenter.blank?
22
21
  work.presenter.blank?
23
22
  end
24
23
  end