hyrax 4.0.0.rc3 → 5.0.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (168) hide show
  1. checksums.yaml +4 -4
  2. data/.circleci/config.yml +116 -231
  3. data/.dassie/.env +3 -1
  4. data/.dassie/Gemfile +0 -2
  5. data/.dassie/config/analytics.yml +2 -2
  6. data/.dassie/config/environments/test.rb +1 -0
  7. data/.dassie/config/initializers/hyrax.rb +3 -1
  8. data/.dassie/config/initializers/redis_config.rb +0 -1
  9. data/.dassie/config/initializers/riiif.rb +13 -3
  10. data/.dassie/db/schema.rb +2 -2
  11. data/.dockerignore +6 -0
  12. data/.github/ISSUE_TEMPLATE.md +14 -9
  13. data/.github/PULL_REQUEST_TEMPLATE.md +25 -6
  14. data/.github/release.yml +5 -2
  15. data/.koppie/.env +3 -0
  16. data/.koppie/Gemfile +0 -2
  17. data/.koppie/README.md +11 -11
  18. data/.koppie/app/forms/collection_resource_form.rb +1 -0
  19. data/.koppie/app/indexers/collection_resource_indexer.rb +1 -0
  20. data/.koppie/app/models/collection_resource.rb +1 -0
  21. data/.koppie/config/analytics.yml +1 -0
  22. data/.koppie/config/environments/test.rb +1 -0
  23. data/.koppie/config/initializers/hyrax.rb +8 -2
  24. data/.koppie/config/initializers/redis_config.rb +0 -1
  25. data/.koppie/config/initializers/riiif.rb +13 -4
  26. data/.koppie/config/metadata/collection_resource.yaml +1 -128
  27. data/.koppie/yarn.lock +23 -23
  28. data/.regen +1 -1
  29. data/CONTAINERS.md +15 -15
  30. data/Dockerfile +6 -11
  31. data/app/actors/hyrax/actors/base_actor.rb +4 -3
  32. data/app/actors/hyrax/actors/embargo_actor.rb +5 -2
  33. data/app/actors/hyrax/actors/lease_actor.rb +5 -2
  34. data/app/assets/javascripts/hyrax/file_manager/sorting.es6 +3 -2
  35. data/app/controllers/concerns/hyrax/embargoes_controller_behavior.rb +1 -1
  36. data/app/controllers/concerns/hyrax/valkyrie_downloads_controller_behavior.rb +74 -0
  37. data/app/controllers/concerns/hyrax/works_controller_behavior.rb +14 -5
  38. data/app/controllers/hyrax/admin/workflows_controller.rb +48 -3
  39. data/app/controllers/hyrax/batch_edits_controller.rb +33 -4
  40. data/app/controllers/hyrax/downloads_controller.rb +8 -1
  41. data/app/controllers/hyrax/file_sets_controller.rb +1 -0
  42. data/app/forms/hyrax/forms/file_set_edit_form.rb +1 -1
  43. data/app/forms/hyrax/forms/permission_template_form.rb +2 -0
  44. data/app/forms/hyrax/forms/resource_batch_edit_form.rb +90 -0
  45. data/app/forms/hyrax/forms/work_embargo_form.rb +1 -0
  46. data/app/forms/hyrax/forms/work_form.rb +1 -1
  47. data/app/forms/hyrax/forms/work_lease_form.rb +1 -0
  48. data/app/helpers/hyrax/dashboard_helper_behavior.rb +17 -9
  49. data/app/helpers/hyrax/membership_helper.rb +13 -1
  50. data/app/helpers/hyrax/work_form_helper.rb +0 -107
  51. data/app/indexers/hyrax/file_set_indexer.rb +6 -0
  52. data/app/indexers/hyrax/pcdm_collection_indexer.rb +8 -0
  53. data/app/indexers/hyrax/valkyrie_file_set_indexer.rb +41 -5
  54. data/app/indexers/hyrax/valkyrie_work_indexer.rb +8 -2
  55. data/app/jobs/valkyrie_create_derivatives_job.rb +8 -7
  56. data/app/jobs/valkyrie_ingest_job.rb +0 -1
  57. data/app/models/admin_set.rb +1 -31
  58. data/app/models/concerns/hyrax/file_set/derivatives.rb +3 -2
  59. data/app/models/concerns/hyrax/solr_document_behavior.rb +1 -1
  60. data/app/models/hyrax/collection_type.rb +5 -14
  61. data/app/models/hyrax/file_metadata.rb +6 -7
  62. data/app/models/hyrax/file_set.rb +8 -0
  63. data/app/models/hyrax/resource.rb +30 -2
  64. data/app/presenters/hyrax/file_set_presenter.rb +6 -0
  65. data/app/presenters/hyrax/iiif_manifest_presenter.rb +3 -7
  66. data/app/presenters/hyrax/presenter_renderer.rb +0 -7
  67. data/app/presenters/hyrax/work_show_presenter.rb +6 -11
  68. data/app/search_builders/hyrax/file_set_search_builder.rb +1 -1
  69. data/app/search_builders/hyrax/valkyrie_abstract_type_relation.rb +37 -0
  70. data/app/search_builders/hyrax/valkyrie_work_relation.rb +9 -0
  71. data/app/services/hyrax/analytics/google.rb +23 -15
  72. data/app/services/hyrax/analytics/matomo.rb +4 -3
  73. data/app/services/hyrax/characterization/valkyrie_characterization_service.rb +11 -9
  74. data/app/services/hyrax/custom_queries/find_by_date_range.rb +55 -0
  75. data/app/services/hyrax/custom_queries/find_count_by.rb +62 -0
  76. data/app/services/hyrax/custom_queries/find_file_metadata.rb +1 -1
  77. data/app/services/hyrax/custom_queries/find_models_by_access.rb +59 -0
  78. data/app/services/hyrax/derivative_bucketed_storage.rb +25 -0
  79. data/app/services/hyrax/derivative_path.rb +14 -4
  80. data/app/services/hyrax/embargo_manager.rb +76 -10
  81. data/app/services/hyrax/file_set_derivatives_service.rb +3 -2
  82. data/app/services/hyrax/lease_manager.rb +88 -8
  83. data/app/services/hyrax/listeners/file_metadata_listener.rb +2 -2
  84. data/app/services/hyrax/listeners/workflow_listener.rb +8 -11
  85. data/app/services/hyrax/persist_directly_contained_output_file_service.rb +24 -2
  86. data/app/services/hyrax/solr_query_service.rb +7 -6
  87. data/app/services/hyrax/statistics/depositors/summary.rb +1 -1
  88. data/app/services/hyrax/statistics/over_time.rb +1 -1
  89. data/app/services/hyrax/statistics/users/over_time.rb +3 -1
  90. data/app/services/hyrax/statistics/valkyrie_query_service.rb +49 -0
  91. data/app/services/hyrax/statistics/works/count.rb +1 -1
  92. data/app/services/hyrax/thumbnail_path_service.rb +5 -0
  93. data/app/services/hyrax/valkyrie_persist_derivatives.rb +16 -11
  94. data/app/services/hyrax/valkyrie_upload.rb +5 -3
  95. data/app/services/hyrax/versioning_service.rb +1 -0
  96. data/app/services/hyrax/visibility_intention.rb +1 -4
  97. data/app/services/hyrax/visibility_propagator.rb +1 -1
  98. data/app/services/hyrax/workflow/actionable_objects.rb +28 -3
  99. data/app/services/hyrax/workflow/grant_edit_to_depositor.rb +1 -1
  100. data/app/services/hyrax/workflow/grant_read_to_depositor.rb +1 -1
  101. data/app/services/hyrax/workflow/permission_query.rb +23 -2
  102. data/app/views/hyrax/admin/workflows/_tabs.html.erb +9 -0
  103. data/app/views/hyrax/admin/workflows/index.html.erb +53 -76
  104. data/app/views/hyrax/base/_file_manager_members.html.erb +2 -2
  105. data/app/views/hyrax/base/_form.html.erb +0 -10
  106. data/app/views/hyrax/base/_form_files.html.erb +7 -2
  107. data/app/views/hyrax/base/_form_permission_embargo.html.erb +1 -1
  108. data/app/views/hyrax/base/_form_permission_lease.html.erb +1 -1
  109. data/app/views/hyrax/base/_form_visibility_component.html.erb +2 -2
  110. data/app/views/hyrax/base/_items.html.erb +1 -1
  111. data/app/views/hyrax/base/file_manager.html.erb +1 -1
  112. data/app/views/hyrax/base/show.json.jbuilder +2 -2
  113. data/app/views/hyrax/file_sets/_versioning.html.erb +1 -1
  114. data/app/views/hyrax/file_sets/show.html.erb +5 -3
  115. data/app/views/hyrax/homepage/_explore_collections.html.erb +1 -1
  116. data/chart/hyrax/Chart.yaml +18 -14
  117. data/chart/hyrax/README.md +34 -21
  118. data/chart/hyrax/templates/_helpers.tpl +26 -1
  119. data/chart/hyrax/templates/configmap-env.yaml +12 -2
  120. data/chart/hyrax/templates/secrets.yaml +1 -1
  121. data/chart/hyrax/values.yaml +36 -14
  122. data/config/initializers/listeners.rb +4 -10
  123. data/config/initializers/storage_adapter_initializer.rb +1 -1
  124. data/config/locales/hyrax.de.yml +11 -3
  125. data/config/locales/hyrax.en.yml +13 -2
  126. data/config/locales/hyrax.es.yml +4 -1
  127. data/config/locales/hyrax.fr.yml +4 -1
  128. data/config/locales/hyrax.it.yml +5 -2
  129. data/config/locales/hyrax.pt-BR.yml +9 -2
  130. data/config/locales/hyrax.zh.yml +4 -1
  131. data/config/metadata/file_set_metadata.yaml +1 -1
  132. data/docker-compose-koppie.yml +17 -4
  133. data/docker-compose.yml +19 -6
  134. data/documentation/developing-your-hyrax-based-app.md +6 -14
  135. data/documentation/legacyREADME.md +7 -5
  136. data/hyrax.gemspec +2 -2
  137. data/karma.conf.js +8 -9
  138. data/lib/generators/hyrax/templates/config/analytics.yml +1 -0
  139. data/lib/generators/hyrax/templates/config/initializers/hyrax.rb +1 -1
  140. data/lib/generators/hyrax/templates/config/initializers/redis_config.rb +0 -1
  141. data/lib/generators/hyrax/templates/config/initializers/riiif.rb +15 -5
  142. data/lib/hyrax/active_fedora_dummy_model.rb +6 -1
  143. data/lib/hyrax/configuration.rb +6 -0
  144. data/lib/hyrax/engine.rb +2 -0
  145. data/lib/hyrax/publisher.rb +19 -3
  146. data/lib/hyrax/specs/capybara.rb +9 -4
  147. data/lib/hyrax/transactions/container.rb +5 -0
  148. data/lib/hyrax/transactions/steps/add_file_sets.rb +6 -0
  149. data/lib/hyrax/transactions/steps/apply_permission_template.rb +40 -0
  150. data/lib/hyrax/transactions/steps/save.rb +21 -0
  151. data/lib/hyrax/transactions/work_create.rb +1 -0
  152. data/lib/hyrax/version.rb +1 -1
  153. data/lib/hyrax.rb +1 -0
  154. data/lib/wings/active_fedora_converter/default_work.rb +7 -2
  155. data/lib/wings/active_fedora_converter/file_metadata_node.rb +1 -1
  156. data/lib/wings/active_fedora_converter.rb +47 -11
  157. data/lib/wings/model_transformer.rb +23 -4
  158. data/lib/wings/setup.rb +21 -1
  159. data/lib/wings/valkyrie/persister.rb +4 -2
  160. data/package.json +3 -1
  161. data/template.rb +1 -1
  162. metadata +15 -10
  163. data/app/forms/hyrax/forms/file_manager_form.rb +0 -35
  164. data/app/services/hyrax/collections/migration_service.rb +0 -113
  165. data/app/views/hyrax/base/_form_collections_error.html.erb +0 -1
  166. data/app/views/hyrax/base/_form_in_works_error.html.erb +0 -3
  167. data/app/views/hyrax/base/_form_ordered_members_error.html.erb +0 -3
  168. data/app/views/hyrax/base/_form_visibility_error.html.erb +0 -19
@@ -0,0 +1,74 @@
1
+ # frozen_string_literal: true
2
+ module Hyrax
3
+ module ValkyrieDownloadsControllerBehavior
4
+ def show_valkyrie
5
+ file_set_id = params.require(:id)
6
+ file_set = Hyrax.query_service.find_by(id: file_set_id)
7
+ send_file_contents_valkyrie(file_set)
8
+ end
9
+
10
+ private
11
+
12
+ def send_file_contents_valkyrie(file_set)
13
+ response.headers["Accept-Ranges"] = "bytes"
14
+ self.status = 200
15
+ use = params.fetch(:file, :original_file).to_sym
16
+ file_metadata = find_file_metadata(file_set: file_set, use: use)
17
+ return unless stale?(last_modified: file_metadata.updated_at, template: false)
18
+
19
+ file = Hyrax.storage_adapter.find_by(id: file_metadata.file_identifier)
20
+ prepare_file_headers_valkyrie(metadata: file_metadata, file: file)
21
+
22
+ # Warning - using the range header will load the range selection in to memory
23
+ # this can cause memory bloat
24
+ if request.headers['Range']
25
+ file.rewind
26
+ send_data send_range_valkyrie(file: file), data_options(file_metadata)
27
+ else
28
+ send_file file.disk_path
29
+ end
30
+ end
31
+
32
+ def data_options(file_metadata)
33
+ {
34
+ type: file_metadata.mime_type,
35
+ filename: file_metadata.original_filename,
36
+ disposition: "inline",
37
+ status: status
38
+ }
39
+ end
40
+
41
+ def send_range_valkyrie(file:)
42
+ _, range = request.headers['Range'].split('bytes=')
43
+ from, to = range.split('-').map(&:to_i)
44
+ to = file.size - 1 unless to
45
+ length = to - from + 1
46
+ response.headers['Content-Range'] = "bytes #{from}-#{to}/#{file.size}"
47
+ response.headers['Content-Length'] = length.to_s
48
+ self.status = 206
49
+ file.read from # Seek to start of requested range
50
+ file.read length
51
+ end
52
+
53
+ def prepare_file_headers_valkyrie(metadata:, file:, inline: false)
54
+ inline_display = ActiveRecord::Type::Boolean.new.cast(params.fetch(:inline, inline))
55
+ response.headers["Content-Disposition"] = "#{inline_display ? 'inline' : 'attachment'}; filename=#{metadata.original_filename}"
56
+ response.headers["Content-Type"] = metadata.mime_type
57
+ response.headers["Content-Length"] ||= (file.try(:size) || metadata.size.first).to_s
58
+ # Prevent Rack::ETag from calculating a digest over body
59
+ response.headers["Last-Modified"] = metadata.updated_at.utc.strftime("%a, %d %b %Y %T GMT")
60
+ self.content_type = metadata.mime_type
61
+ end
62
+
63
+ def find_file_metadata(file_set:, use: :original_file)
64
+ use = :thumbnail_file if use == :thumbnail
65
+ begin
66
+ use = Hyrax::FileMetadata::Use.uri_for(use: use)
67
+ rescue ArgumentError
68
+ raise Hyrax::ObjectNotFoundError
69
+ end
70
+ results = Hyrax.custom_queries.find_many_file_metadata_by_use(resource: file_set, use: use)
71
+ results.first || raise(Hyrax::ObjectNotFoundError)
72
+ end
73
+ end
74
+ end
@@ -125,7 +125,7 @@ module Hyrax
125
125
  end
126
126
 
127
127
  def file_manager
128
- @form = Forms::FileManagerForm.new(curation_concern, current_ability)
128
+ @form = presenter
129
129
  end
130
130
 
131
131
  def inspect_work
@@ -180,15 +180,18 @@ module Hyrax
180
180
 
181
181
  ##
182
182
  # @return [#errors]
183
+ # rubocop:disable Metrics/MethodLength
183
184
  def create_valkyrie_work
184
185
  form = build_form
185
- return after_create_error(form_err_msg(form)) unless form.validate(params[hash_key_for_curation_concern])
186
+ # fallback to an empty hash to avoid: # NoMethodError: undefined method `has_key?` for nil:NilClass
187
+ original_input_params_for_form = params[hash_key_for_curation_concern] ? params[hash_key_for_curation_concern] : {}
188
+ return after_create_error(form_err_msg(form), original_input_params_for_form) unless form.validate(original_input_params_for_form)
186
189
 
187
190
  result =
188
191
  transactions['change_set.create_work']
189
192
  .with_step_args(
190
193
  'work_resource.add_to_parent' => { parent_id: params[:parent_id], user: current_user },
191
- 'work_resource.add_file_sets' => { uploaded_files: uploaded_files, file_set_params: params[hash_key_for_curation_concern][:file_set] },
194
+ 'work_resource.add_file_sets' => { uploaded_files: uploaded_files, file_set_params: original_input_params_for_form[:file_set] },
192
195
  'change_set.set_user_as_depositor' => { user: current_user },
193
196
  'work_resource.change_depositor' => { user: ::User.find_by_user_key(form.on_behalf_of) },
194
197
  'work_resource.save_acl' => { permissions_params: form.input_params["permissions"] }
@@ -197,6 +200,7 @@ module Hyrax
197
200
  @curation_concern = result.value_or { return after_create_error(transaction_err_msg(result)) }
198
201
  after_create_response
199
202
  end
203
+ # rubocop:enable Metrics/MethodLength
200
204
 
201
205
  def update_valkyrie_work
202
206
  form = build_form
@@ -370,10 +374,15 @@ module Hyrax
370
374
  end
371
375
  end
372
376
 
377
+ def format_error_messages(errors)
378
+ # the error may already be a string
379
+ errors.respond_to?(:messages) ? errors.messages.values.flatten.join("\n") : errors
380
+ end
381
+
373
382
  def after_create_error(errors, original_input_params_for_form = nil)
374
383
  respond_to do |wants|
375
384
  wants.html do
376
- flash[:error] = errors.to_s
385
+ flash[:error] = format_error_messages(errors)
377
386
  rebuild_form(original_input_params_for_form) if original_input_params_for_form.present?
378
387
  render 'new', status: :unprocessable_entity
379
388
  end
@@ -402,7 +411,7 @@ module Hyrax
402
411
  def after_update_error(errors)
403
412
  respond_to do |wants|
404
413
  wants.html do
405
- flash[:error] = errors.to_s
414
+ flash[:error] = format_error_messages(errors)
406
415
  build_form unless @form.is_a? Hyrax::ChangeSet
407
416
  render 'edit', status: :unprocessable_entity
408
417
  end
@@ -15,9 +15,8 @@ module Hyrax
15
15
  add_breadcrumb t(:'hyrax.dashboard.breadcrumbs.admin'), hyrax.dashboard_path
16
16
  add_breadcrumb t(:'hyrax.admin.sidebar.tasks'), '#'
17
17
  add_breadcrumb t(:'hyrax.admin.sidebar.workflow_review'), request.path
18
-
19
- @status_list = actionable_objects.reject(&:published?)
20
- @published_list = actionable_objects.select(&:published?)
18
+ assign_action_objects_params
19
+ @response = WorkflowResponse.new(actionable_objects.to_a, actionable_objects.total_count, current_page, per_page, under_review?)
21
20
  end
22
21
 
23
22
  private
@@ -30,5 +29,51 @@ module Hyrax
30
29
  @actionable_objects ||=
31
30
  Hyrax::Workflow::ActionableObjects.new(user: current_user)
32
31
  end
32
+
33
+ def current_page
34
+ @page ||= params.fetch('page', 1).to_i
35
+ end
36
+
37
+ def per_page
38
+ @per_page ||= params.fetch('per_page', 10).to_i
39
+ end
40
+
41
+ def assign_action_objects_params
42
+ actionable_objects.page = current_page
43
+ actionable_objects.per_page = per_page
44
+ actionable_objects.workflow_state_filter = (under_review? ? '!' : '') + deposited_workflow_state_name
45
+ end
46
+
47
+ def under_review?
48
+ @under_review = params['state'] != 'published'
49
+ end
50
+
51
+ class WorkflowResponse
52
+ attr_reader :total_count
53
+ attr_reader :current_page
54
+ attr_reader :per_page
55
+ attr_reader :docs
56
+ attr_reader :under_review
57
+
58
+ def initialize(docs, total_count, page, per_page, under_review)
59
+ @docs = docs
60
+ @total_count = total_count
61
+ @per_page = per_page.to_i
62
+ @current_page = page.to_i
63
+ @under_review = under_review
64
+ end
65
+
66
+ def total_pages
67
+ (total_count.to_f / per_page).ceil
68
+ end
69
+
70
+ def limit_value
71
+ docs.length
72
+ end
73
+
74
+ def viewing_under_review?
75
+ under_review
76
+ end
77
+ end
33
78
  end
34
79
  end
@@ -52,7 +52,7 @@ module Hyrax
52
52
  def update_document(obj)
53
53
  interpret_visiblity_params(obj)
54
54
  obj.attributes = work_params(admin_set_id: obj.admin_set_id).except(*visibility_params)
55
- obj.date_modified = Time.current.ctime
55
+ obj.date_modified = TimeService.time_in_utc
56
56
 
57
57
  InheritPermissionsJob.perform_now(obj)
58
58
  VisibilityCopyJob.perform_now(obj)
@@ -60,11 +60,30 @@ module Hyrax
60
60
  obj.save
61
61
  end
62
62
 
63
+ def valkyrie_update_document(obj)
64
+ form = form_class.new(obj, current_ability, nil)
65
+ return unless form.validate(params[form_class.model_class.model_name.param_key])
66
+
67
+ cleanup_form_fields form
68
+
69
+ result = transactions['change_set.update_work']
70
+ .with_step_args('work_resource.save_acl' => { permissions_params: form.input_params["permissions"] })
71
+ .call(form)
72
+ obj = result.value!
73
+
74
+ InheritPermissionsJob.perform_now(obj)
75
+ VisibilityCopyJob.perform_now(obj)
76
+ end
77
+
63
78
  def update
64
79
  case params["update_type"]
65
80
  when "update"
66
81
  batch.each do |doc_id|
67
- update_document(Hyrax.query_service.find_by_alternate_identifier(alternate_identifier: doc_id, use_valkyrie: false))
82
+ if Hyrax.config.use_valkyrie?
83
+ valkyrie_update_document(Hyrax.query_service.find_by(id: doc_id))
84
+ else
85
+ update_document(Hyrax.query_service.find_by_alternate_identifier(alternate_identifier: doc_id, use_valkyrie: false))
86
+ end
68
87
  end
69
88
  flash[:notice] = "Batch update complete"
70
89
  after_update
@@ -97,7 +116,7 @@ module Hyrax
97
116
  end
98
117
 
99
118
  def form_class
100
- Forms::BatchEditForm
119
+ Hyrax.config.use_valkyrie? ? Forms::ResourceBatchEditForm : Forms::BatchEditForm
101
120
  end
102
121
 
103
122
  def terms
@@ -105,7 +124,7 @@ module Hyrax
105
124
  end
106
125
 
107
126
  def work_params(extra_params = {})
108
- work_params = params[form_class.model_name.param_key] || ActionController::Parameters.new
127
+ work_params = params[form_class.model_class.model_name.param_key] || ActionController::Parameters.new
109
128
  form_class.model_attributes(work_params.merge(extra_params))
110
129
  end
111
130
 
@@ -135,5 +154,15 @@ module Hyrax
135
154
  redirect_to hyrax.dashboard_path
136
155
  end
137
156
  end
157
+
158
+ # Clean up form fields
159
+ # @param form Hyrax::Froms::ResourceBatchEditForm
160
+ def cleanup_form_fields(form)
161
+ form.lease = nil if form.lease && form.lease.fields['lease_expiration_date'].nil?
162
+ form.embargo = nil if form.embargo && form.embargo.fields['embargo_release_date'].nil?
163
+ form.fields.keys.each do |k|
164
+ form.fields[k] = nil if form.fields[k].is_a?(Array) && form.fields[k].blank?
165
+ end
166
+ end
138
167
  end
139
168
  end
@@ -3,6 +3,7 @@ module Hyrax
3
3
  class DownloadsController < ApplicationController
4
4
  include Hydra::Controller::DownloadBehavior
5
5
  include Hyrax::LocalFileDownloadsControllerBehavior
6
+ include Hyrax::ValkyrieDownloadsControllerBehavior
6
7
  include Hyrax::WorkflowsHelper # Provides #workflow_restriction?
7
8
 
8
9
  def self.default_content_path
@@ -12,6 +13,8 @@ module Hyrax
12
13
  # Render the 404 page if the file doesn't exist.
13
14
  # Otherwise renders the file.
14
15
  def show
16
+ return show_valkyrie if Hyrax.config.use_valkyrie?
17
+
15
18
  case file
16
19
  when ActiveFedora::File
17
20
  # For original files that are stored in fedora
@@ -39,7 +42,11 @@ module Hyrax
39
42
  end
40
43
 
41
44
  def file_set_parent(file_set_id)
42
- file_set = Hyrax.query_service.find_by_alternate_identifier(alternate_identifier: file_set_id, use_valkyrie: Hyrax.config.use_valkyrie?)
45
+ file_set = if defined?(Wings) && Hyrax.metadata_adapter.is_a?(Wings::Valkyrie::MetadataAdapter)
46
+ Hyrax.query_service.find_by_alternate_identifier(alternate_identifier: file_set_id, use_valkyrie: Hyrax.config.use_valkyrie?)
47
+ else
48
+ Hyrax.query_service.find_by(id: file_set_id)
49
+ end
43
50
  @parent ||=
44
51
  case file_set
45
52
  when Hyrax::Resource
@@ -171,6 +171,7 @@ module Hyrax
171
171
  respond_to do |wants|
172
172
  wants.html do
173
173
  initialize_edit_form
174
+ # TODO: return a valuable error message
174
175
  flash[:error] = "There was a problem processing your request."
175
176
  render 'edit', status: :unprocessable_entity
176
177
  end
@@ -6,7 +6,7 @@ module Hyrax::Forms
6
6
 
7
7
  delegate :depositor, :permissions, :human_readable_type, to: :model
8
8
 
9
- self.required_fields = [:title, :creator, :license]
9
+ self.required_fields = [:title, :creator]
10
10
 
11
11
  self.model_class = ::FileSet
12
12
 
@@ -266,6 +266,8 @@ module Hyrax
266
266
  # rubocop:disable Metrics/CyclomaticComplexity
267
267
  # rubocop:disable Metrics/PerceivedComplexity
268
268
  def permission_template_update_params
269
+ return attributes unless attributes.key?(:release_varies) || attributes.key?(:release_embargo)
270
+
269
271
  filtered_attributes = attributes.except(:release_varies, :release_embargo)
270
272
  # If 'varies' before date option selected, then set release_period='before' and save release_date as-is
271
273
  if attributes[:release_varies] == Hyrax::PermissionTemplate::RELEASE_TEXT_VALUE_BEFORE_DATE
@@ -0,0 +1,90 @@
1
+ # frozen_string_literal: true
2
+ module Hyrax
3
+ module Forms
4
+ class ResourceBatchEditForm < Hyrax::Forms::ResourceForm
5
+ include Hyrax::FormFields(:basic_metadata)
6
+
7
+ self.required_fields = []
8
+ self.model_class = Hyrax.primary_work_type
9
+
10
+ # Contains a list of titles of all the works in the batch
11
+ attr_accessor :names
12
+
13
+ # @param [Hyrax::Work] model the model backing the form
14
+ # @param [Ability] current_ability the user authorization model
15
+ # @param [Array<String>] batch_document_ids a list of document ids in the batch
16
+ def initialize(model, _current_ability, batch_document_ids)
17
+ @names = []
18
+ @batch_document_ids = batch_document_ids
19
+ if @batch_document_ids.present?
20
+ super(model.class.new(initialize_combined_fields))
21
+ else
22
+ super(model)
23
+ end
24
+ end
25
+
26
+ def terms
27
+ [:creator, :contributor, :description,
28
+ :keyword, :resource_type, :license, :publisher, :date_created,
29
+ :subject, :language, :identifier, :based_near,
30
+ :related_url]
31
+ end
32
+
33
+ attr_reader :batch_document_ids
34
+
35
+ # Returns a list of parameters we accept from the form
36
+ # rubocop:disable Metrics/MethodLength
37
+ def self.build_permitted_params
38
+ [{ creator: [] },
39
+ { contributor: [] },
40
+ { description: [] },
41
+ { keyword: [] },
42
+ { resource_type: [] },
43
+ { license: [] },
44
+ { publisher: [] },
45
+ { date_created: [] },
46
+ { subject: [] },
47
+ { language: [] },
48
+ { identifier: [] },
49
+ { based_near: [] },
50
+ { related_url: [] },
51
+ { permissions_attributes: [:type, :name, :access, :id, :_destroy] },
52
+ :on_behalf_of,
53
+ :version,
54
+ :add_works_to_collection,
55
+ :visibility_during_embargo,
56
+ :embargo_release_date,
57
+ :visibility_after_embargo,
58
+ :visibility_during_lease,
59
+ :lease_expiration_date,
60
+ :visibility_after_lease,
61
+ :visibility,
62
+ { based_near_attributes: [:id, :_destroy] }]
63
+ end
64
+ # rubocop:enable Metrics/MethodLength
65
+
66
+ # @param name [Symbol]
67
+ # @return [Symbol]
68
+ # @note Added for ActiveModel compatibility.
69
+ def column_for_attribute(name)
70
+ name
71
+ end
72
+
73
+ private
74
+
75
+ # override this method if you need to initialize more complex RDF assertions (b-nodes)
76
+ # @return [Hash<String, Array>] the list of unique values per field
77
+ def initialize_combined_fields
78
+ # For each of the files in the batch, set the attributes to be the concatenation of all the attributes
79
+ batch_document_ids.each_with_object({}) do |doc_id, combined_attributes|
80
+ work = Hyrax.query_service.find_by(id: doc_id)
81
+ terms.each do |field|
82
+ combined_attributes[field] ||= []
83
+ combined_attributes[field] = (combined_attributes[field] + work[field].to_a).uniq
84
+ end
85
+ names << work.to_s
86
+ end
87
+ end
88
+ end
89
+ end
90
+ end
@@ -11,6 +11,7 @@ module Hyrax
11
11
  # +EmbargoesControllerBehavior+.
12
12
  class WorkEmbargoForm < Hyrax::ChangeSet
13
13
  property :embargo, form: Hyrax::Forms::Embargo, populator: :embargo_populator, prepopulator: :embargo_populator
14
+ property :embargo_history, virtual: true, prepopulator: proc { |_opts| self.embargo_history = model.embargo&.embargo_history }
14
15
  property :embargo_release_date, virtual: true, prepopulator: proc { |_opts| self.embargo_release_date = model.embargo&.embargo_release_date }
15
16
  property :visibility_after_embargo, virtual: true, prepopulator: proc { |_opts| self.visibility_after_embargo = model.embargo&.visibility_after_embargo }
16
17
  property :visibility_during_embargo, virtual: true, prepopulator: proc { |_opts| self.visibility_during_embargo = model.embargo&.visibility_during_embargo }
@@ -158,7 +158,7 @@ module Hyrax
158
158
  # In particular we are discarding any access grant parameters for works that
159
159
  # are going into a mediated deposit workflow.
160
160
  def self.sanitize_params(form_params)
161
- admin_set_id = form_params[:admin_set_id]
161
+ admin_set_id = Array(form_params[:admin_set_id]).first
162
162
  return super if admin_set_id && workflow_for(admin_set_id: admin_set_id).allows_access_grant?
163
163
  params_without_permissions = permitted_params.reject { |arg| arg.respond_to?(:key?) && arg.key?(:permissions_attributes) }
164
164
  form_params.permit(*params_without_permissions)
@@ -11,6 +11,7 @@ module Hyrax
11
11
  # +LeasesControllerBehavior+.
12
12
  class WorkLeaseForm < Hyrax::ChangeSet
13
13
  property :lease, form: Hyrax::Forms::Lease, populator: :lease_populator, prepopulator: :lease_populator
14
+ property :lease_history, virtual: true, prepopulator: proc { |_opts| self.lease_history = model.lease&.lease_history }
14
15
  property :lease_expiration_date, virtual: true, prepopulator: proc { |_opts| self.lease_expiration_date = model.lease&.lease_expiration_date }
15
16
  property :visibility_after_lease, virtual: true, prepopulator: proc { |_opts| self.visibility_after_lease = model.lease&.visibility_after_lease }
16
17
  property :visibility_during_lease, virtual: true, prepopulator: proc { |_opts| self.visibility_during_lease = model.lease&.visibility_during_lease }
@@ -6,13 +6,13 @@ module Hyrax
6
6
  end
7
7
 
8
8
  # @param user [User]
9
- # @param where [Hash] applied as the where clause when querying the Hyrax::WorkRelation
10
- # @return [Integer] number of works matching the where that the user deposited
11
- # @see Hyrax::WorkRelation
12
- def number_of_works(user = current_user, where: { generic_type_sim: "Work" })
13
- field_pairs = field_pairs(user)
14
- field_pairs.merge!(where)
15
- Hyrax::SolrQueryService.new.with_field_pairs(field_pairs: field_pairs).count
9
+ # @return [Integer] number of works that the user deposited
10
+ def number_of_works(user = current_user)
11
+ Hyrax::SolrQueryService
12
+ .new
13
+ .with_field_pairs(field_pairs: field_pairs(user))
14
+ .with_generic_type(generic_type: 'Work')
15
+ .count
16
16
  rescue RSolr::Error::ConnectionRefused
17
17
  'n/a'
18
18
  end
@@ -20,7 +20,11 @@ module Hyrax
20
20
  # @param user [User]
21
21
  # @return [Integer] number of FileSets the user deposited
22
22
  def number_of_files(user = current_user)
23
- Hyrax::SolrQueryService.new.with_field_pairs(field_pairs: field_pairs(user)).count
23
+ Hyrax::SolrQueryService
24
+ .new
25
+ .with_field_pairs(field_pairs: field_pairs(user))
26
+ .with_generic_type(generic_type: 'FileSet')
27
+ .count
24
28
  rescue RSolr::Error::ConnectionRefused
25
29
  'n/a'
26
30
  end
@@ -28,7 +32,11 @@ module Hyrax
28
32
  # @param user [User]
29
33
  # @return [Integer] number of Collections the user created
30
34
  def number_of_collections(user = current_user)
31
- Hyrax::SolrQueryService.new.with_field_pairs(field_pairs: field_pairs(user)).count
35
+ Hyrax::SolrQueryService
36
+ .new
37
+ .with_field_pairs(field_pairs: field_pairs(user))
38
+ .with_generic_type(generic_type: 'Collection')
39
+ .count
32
40
  rescue RSolr::Error::ConnectionRefused
33
41
  'n/a'
34
42
  end
@@ -14,18 +14,30 @@ module Hyrax
14
14
  #
15
15
  # @see app/assets/javascripts/hyrax/relationships.js
16
16
  def member_of_collections_json(resource)
17
+ # this is where we return for dassie
17
18
  return resource.member_of_collections_json if
18
19
  resource.respond_to?(:member_of_collections_json)
19
20
 
20
21
  resource = resource.model if resource.respond_to?(:model)
21
22
 
22
- Hyrax.custom_queries.find_collections_for(resource: resource).map do |collection|
23
+ existing_collections_array = Hyrax.custom_queries.find_collections_for(resource: resource) + add_collection_from_params
24
+ existing_collections_array.map do |collection|
23
25
  { id: collection.id.to_s,
24
26
  label: collection.title.first,
25
27
  path: url_for(collection) }
26
28
  end.to_json
27
29
  end
28
30
 
31
+ def add_collection_from_params
32
+ # avoid errors when creating Valkyrie resources from Dashboard >> Works
33
+ return [] if controller.params[:add_works_to_collection].blank?
34
+
35
+ # new valkyrie works need the collection from params when depositing directly into an existing collection
36
+ return [Hyrax.metadata_adapter.query_service.find_by(id: Valkyrie::ID.new(controller.params[:add_works_to_collection]))] if Hyrax.config.use_valkyrie?
37
+
38
+ [::Collection.find(@controller.params[:add_works_to_collection])]
39
+ end
40
+
29
41
  ##
30
42
  # @param resource [#work_members_json]
31
43
  #
@@ -97,112 +97,5 @@ module Hyrax
97
97
  hash[presenter.title_or_label] = presenter.id
98
98
  end
99
99
  end
100
-
101
- ##
102
- # This helper retrieves errors based on form type.
103
- #
104
- # @param form [Hyrax::Forms::WorkForm] or Hyrax::ChangeSet
105
- # @return [String] specific error message
106
- def in_works_ids_errors_for(form:)
107
- case form
108
- when Hyrax::ChangeSet
109
- form.errors[:in_works_ids]
110
- else
111
- form.model.errors[:in_works_ids]
112
- end
113
- end
114
-
115
- ##
116
- # This helper retrieves errors based on form type.
117
- #
118
- # @param form [Hyrax::Forms::WorkForm] or Hyrax::ChangeSet
119
- # @return [String] specific error message
120
- def ordered_member_ids_errors_for(form:)
121
- case form
122
- when Hyrax::ChangeSet
123
- form.errors[:ordered_member_ids]
124
- else
125
- form.model.errors[:ordered_member_ids]
126
- end
127
- end
128
-
129
- ##
130
- # This helper retrieves errors based on form type.
131
- #
132
- # @param form [Hyrax::Forms::WorkForm] or Hyrax::ChangeSet
133
- # @return [String] specific error message
134
- def visibility_errors_for(form:)
135
- case form
136
- when Hyrax::ChangeSet
137
- form.errors[:visibility]
138
- else
139
- form.model.errors[:visibility]
140
- end
141
- end
142
-
143
- ##
144
- # This helper retrieves errors based on form type.
145
- #
146
- # @param form [Hyrax::Forms::WorkForm] or Hyrax::ChangeSet
147
- # @return [String] specific error message
148
- def embargo_release_date_errors_for(form:)
149
- case form
150
- when Hyrax::ChangeSet
151
- form.errors[:embargo_release_date]
152
- else
153
- form.model.errors[:embargo_release_date]
154
- end
155
- end
156
-
157
- ##
158
- # This helper retrieves errors based on form type.
159
- #
160
- # @param form [Hyrax::Forms::WorkForm] or Hyrax::ChangeSet
161
- # @return [String] specific error message
162
- def visibility_after_embargo_errors_for(form:)
163
- case form
164
- when Hyrax::ChangeSet
165
- form.errors[:visibility_after_embargo]
166
- else
167
- form.model.errors[:visibility_after_embargo]
168
- end
169
- end
170
-
171
- ##
172
- # This helper retrieves errors based on form type.
173
- #
174
- # @param form [Hyrax::Forms::WorkForm] or Hyrax::ChangeSet
175
- # @return [String] specific error message
176
- def lease_expiration_date_errors_for(form:)
177
- case form
178
- when Hyrax::ChangeSet
179
- form.errors[:lease_expiration_date_errors]
180
- else
181
- form.model.errors[:lease_expiration_date_errors]
182
- end
183
- end
184
-
185
- ##
186
- # This helper retrieves errors based on form type.
187
- #
188
- # @param form [Hyrax::Forms::WorkForm] or Hyrax::ChangeSet
189
- # @return [String] specific error message
190
- def visibility_after_lease_errors_for(form:)
191
- case form
192
- when Hyrax::ChangeSet
193
- form.errors[:visibility_after_lease]
194
- else
195
- form.model.errors[:visibility_after_lease]
196
- end
197
- end
198
-
199
- ##
200
- # This helper retrieves errors based on form type.
201
- #
202
- # @param form [Hyrax::Forms::WorkForm] or Hyrax::ChangeSet
203
- # @return [String] specific error message
204
- def full_collections_errors(form:)
205
- form.full_error(:collections) || form.full_error(:member_of_collection_ids)
206
- end
207
100
  end
208
101
  end
@@ -30,6 +30,7 @@ module Hyrax
30
30
  solr_doc['original_checksum_tesim'] = object.original_checksum
31
31
  solr_doc['alpha_channels_ssi'] = object.alpha_channels
32
32
  solr_doc['original_file_id_ssi'] = original_file_id
33
+ solr_doc['extracted_text_id_ssi'] = extracted_text_id
33
34
  solr_doc['generic_type_si'] = 'FileSet'
34
35
  end
35
36
  end
@@ -46,6 +47,11 @@ module Hyrax
46
47
  Hyrax::VersioningService.versioned_file_id object.original_file
47
48
  end
48
49
 
50
+ def extracted_text_id
51
+ return unless object.extracted_text
52
+ Hyrax::VersioningService.versioned_file_id object.extracted_text
53
+ end
54
+
49
55
  def file_format
50
56
  if object.mime_type.present? && object.format_label.present?
51
57
  "#{object.mime_type.split('/').last} (#{object.format_label.join(', ')})"