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
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9b16b002450d8ab2e549a1e79a558df2cdcc5a4f906d5cad461a010de5d3083d
4
- data.tar.gz: e31cfe1456a09806f220c3a80582c708ea04707fb927dce8bcd1fa897d738c94
3
+ metadata.gz: 98e61b637b4f510e877e88c3f2f8020a411b7d83cd0c074e142f666fbda964f1
4
+ data.tar.gz: 17a8be1a76c9755d5e8b2b1387e907c2d70722809cdb28a62088d913dc584384
5
5
  SHA512:
6
- metadata.gz: c559a06ad78eb3b2e13ab6f11cc7fd0a5ee94a0da1670b0c67557610cf0d65fde294a6998ce46c634bff1a24ad3a17d6eb4755ec7ddf87e7c339ef7c46a0e717
7
- data.tar.gz: d95bd5690258a422be6913a1fb7bed33c225288948c74d6864ec3f7740d4791fd7dcca321b89f81efc33083048965102635281ff5b0de815701125a95c8e24f7
6
+ metadata.gz: 445d46c5b5b5ee45ea4262e1809e92356f9536f2f919af929b9d33fafcc13c584ae0ff1c6c2b27cac8ffbcdf35f9be6fd9a726b9bf5c9cafc0632fbd8596a90c
7
+ data.tar.gz: d5d5ca3a839a02af1fec27d262eb8301a5880a07caba29b9ce383b37a7c7aea098e57f3ddf9c3fbc1582f5a9ffa227e7d0fc3702833a645ae86b7ab94745a2f9
@@ -70,7 +70,7 @@ module Hyrax
70
70
  # along side the FileSets on the show page
71
71
  def add(env, id)
72
72
  collection = Hyrax.config.collection_class.find(id)
73
- collection.reindex_extent = Hyrax::Adapters::NestingIndexAdapter::LIMITED_REINDEX
73
+ collection.try(:reindex_extent=, Hyrax::Adapters::NestingIndexAdapter::LIMITED_REINDEX)
74
74
 
75
75
  return unless env.current_ability.can?(:deposit, collection)
76
76
  env.curation_concern.member_of_collections << collection
@@ -12,10 +12,17 @@ module Hyrax
12
12
  # Update the visibility of the work to match the correct state of the embargo, then clear the embargo date, etc.
13
13
  # Saves the embargo and the work
14
14
  def destroy
15
- work.embargo_visibility! # If the embargo has lapsed, update the current visibility.
16
- work.deactivate_embargo!
17
- work.embargo.save!
18
- work.save!
15
+ case work
16
+ when Valkyrie::Resource
17
+ embargo_manager = Hyrax::EmbargoManager.new(resource: work)
18
+ embargo_manager.release && Hyrax::AccessControlList(work).save
19
+ embargo_manager.nullify
20
+ else
21
+ work.embargo_visibility! # If the embargo has lapsed, update the current visibility.
22
+ work.deactivate_embargo!
23
+ work.embargo.save!
24
+ work.save!
25
+ end
19
26
  end
20
27
  end
21
28
  end
@@ -12,10 +12,17 @@ module Hyrax
12
12
  # Update the visibility of the work to match the correct state of the lease, then clear the lease date, etc.
13
13
  # Saves the lease and the work
14
14
  def destroy
15
- work.lease_visibility! # If the lease has lapsed, update the current visibility.
16
- work.deactivate_lease!
17
- work.lease.save!
18
- work.save!
15
+ case work
16
+ when Valkyrie::Resource
17
+ lease_manager = Hyrax::LeaseManager.new(resource: work)
18
+ lease_manager.release && Hyrax::AccessControlList(work).save
19
+ lease_manager.nullify
20
+ else
21
+ work.lease_visibility! # If the lease has lapsed, update the current visibility.
22
+ work.deactivate_lease!
23
+ work.lease.save!
24
+ work.save!
25
+ end
19
26
  end
20
27
  end
21
28
  end
@@ -104,7 +104,7 @@ Hyrax = {
104
104
  // On the edit work page
105
105
  new PermissionsControl($("#share"), 'tmpl-work-grant');
106
106
  // On the edit fileset page
107
- new PermissionsControl($("#permission"), 'tmpl-file-set-grant');
107
+ new PermissionsControl($("#permission"), 'tmpl-file-set-grant', { with_visibility_component: true });
108
108
  // On the batch edit page
109
109
  new PermissionsControl($("#form_permissions"), 'tmpl-work-grant');
110
110
  // On the edit collection page
@@ -1,6 +1,7 @@
1
1
  import { Registry } from './registry'
2
2
  import { UserControls } from './user_controls'
3
3
  import { GroupControls } from './group_controls'
4
+ import VisibilityComponent from '../save_work/visibility_component'
4
5
 
5
6
  export default class PermissionsControl {
6
7
  /**
@@ -8,7 +9,8 @@ export default class PermissionsControl {
8
9
  * @param {jQuery} element the jquery selector for the permissions container
9
10
  * @param {String} template_id the identifier of the template for the added elements
10
11
  */
11
- constructor(element, template_id) {
12
+ constructor(element, template_id, options = {}) {
13
+ const { with_visibility_component } = options
12
14
  if (element.length === 0) {
13
15
  return
14
16
  }
@@ -17,6 +19,11 @@ export default class PermissionsControl {
17
19
  this.registry = new Registry(this.element, this.object_name(), template_id)
18
20
  this.user_controls = new UserControls(this.element, this.registry)
19
21
  this.group_controls = new GroupControls(this.element, this.registry)
22
+ if (with_visibility_component) {
23
+ this.visibility_component = new VisibilityComponent(this.element)
24
+ } else {
25
+ this.visibility_component = null
26
+ }
20
27
  }
21
28
 
22
29
  // retrieve object_name the name of the object to create
@@ -15,8 +15,8 @@ module Hyrax
15
15
  # Removes a single embargo
16
16
  def destroy
17
17
  Hyrax::Actors::EmbargoActor.new(curation_concern).destroy
18
- flash[:notice] = curation_concern.embargo_history.last
19
- if curation_concern.work? && curation_concern.file_sets.present?
18
+ flash[:notice] = embargo_history(curation_concern)
19
+ if curation_concern.work? && work_has_file_set_members?(curation_concern)
20
20
  redirect_to confirm_permission_path
21
21
  else
22
22
  redirect_to edit_embargo_path
@@ -60,10 +60,19 @@ module Hyrax
60
60
  end
61
61
 
62
62
  def edit
63
+ @curation_concern = Hyrax::Forms::WorkEmbargoForm.new(curation_concern).prepopulate! if
64
+ Hyrax.config.use_valkyrie?
63
65
  add_breadcrumb t(:'hyrax.controls.home'), root_path
64
66
  add_breadcrumb t(:'hyrax.dashboard.breadcrumbs.admin'), hyrax.dashboard_path
65
67
  add_breadcrumb t(:'hyrax.embargoes.index.manage_embargoes'), hyrax.embargoes_path
66
68
  add_breadcrumb t(:'hyrax.embargoes.edit.embargo_update'), '#'
67
69
  end
70
+
71
+ private
72
+
73
+ def embargo_history(concern)
74
+ concern.try(:embargo_history) ||
75
+ concern.try(:embargo)&.embargo_history
76
+ end
68
77
  end
69
78
  end
@@ -15,8 +15,8 @@ module Hyrax
15
15
  # Removes a single lease
16
16
  def destroy
17
17
  Hyrax::Actors::LeaseActor.new(curation_concern).destroy
18
- flash[:notice] = curation_concern.lease_history.last
19
- if curation_concern.work? && curation_concern.file_sets.present?
18
+ flash[:notice] = lease_history(curation_concern)&.last
19
+ if curation_concern.work? && work_has_file_set_members?(curation_concern)
20
20
  redirect_to confirm_permission_path
21
21
  else
22
22
  redirect_to edit_lease_path
@@ -51,10 +51,19 @@ module Hyrax
51
51
  end
52
52
 
53
53
  def edit
54
+ @curation_concern = Hyrax::Forms::WorkLeaseForm.new(curation_concern).prepopulate! if
55
+ Hyrax.config.use_valkyrie?
54
56
  add_breadcrumb t(:'hyrax.controls.home'), root_path
55
57
  add_breadcrumb t(:'hyrax.dashboard.breadcrumbs.admin'), hyrax.dashboard_path
56
58
  add_breadcrumb t(:'hyrax.leases.index.manage_leases'), hyrax.leases_path
57
59
  add_breadcrumb t(:'hyrax.leases.edit.lease_update'), '#'
58
60
  end
61
+
62
+ private
63
+
64
+ def lease_history(concern)
65
+ concern.try(:lease_history) ||
66
+ concern.try(:lease)&.lease_history
67
+ end
59
68
  end
60
69
  end
@@ -6,7 +6,8 @@ module Hyrax
6
6
  included do
7
7
  attr_accessor :curation_concern
8
8
  helper_method :curation_concern
9
- load_and_authorize_resource class: ActiveFedora::Base, instance_name: :curation_concern
9
+ base_class = Hyrax.config.use_valkyrie? ? Hyrax::Resource : ActiveFedora::Base
10
+ load_and_authorize_resource class: base_class, instance_name: :curation_concern, except: [:index]
10
11
  end
11
12
 
12
13
  # This is an override of Hyrax::ApplicationController
@@ -15,5 +16,16 @@ module Hyrax
15
16
  end
16
17
 
17
18
  def edit; end
19
+
20
+ private
21
+
22
+ def work_has_file_set_members?(work)
23
+ case work
24
+ when Valkyrie::Resource
25
+ Hyrax.custom_queries.find_child_file_set_ids(resource: work).any?
26
+ else
27
+ work.file_sets.present?
28
+ end
29
+ end
18
30
  end
19
31
  end
@@ -220,7 +220,7 @@ module Hyrax
220
220
 
221
221
  @collection.visibility = Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_PRIVATE unless @collection.discoverable?
222
222
  # we don't have to reindex the full graph when updating collection
223
- @collection.reindex_extent = Hyrax::Adapters::NestingIndexAdapter::LIMITED_REINDEX
223
+ @collection.try(:reindex_extent=, Hyrax::Adapters::NestingIndexAdapter::LIMITED_REINDEX)
224
224
  if @collection.update(collection_params.except(:members))
225
225
  after_update_response
226
226
  else
@@ -422,7 +422,6 @@ module Hyrax
422
422
  params.permit(collection: {})[:collection]
423
423
  .merge(params.permit(:collection_type_gid)
424
424
  .with_defaults(collection_type_gid: default_collection_type_gid))
425
- .merge(member_of_collection_ids: Array(params[:parent_id]))
426
425
  end
427
426
  end
428
427
 
@@ -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::WorkflowsHelper # Provides #workflow_restriction?
6
7
 
7
8
  def self.default_content_path
8
9
  :original_file
@@ -37,12 +38,26 @@ module Hyrax
37
38
  { type: mime_type_for(file), disposition: 'inline' }
38
39
  end
39
40
 
41
+ 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?)
43
+ @parent ||=
44
+ case file_set
45
+ when Hyrax::Resource
46
+ Hyrax.query_service.find_parents(resource: file_set).first
47
+ else
48
+ file_set.parent
49
+ end
50
+ end
51
+
40
52
  # Customize the :read ability in your Ability class, or override this method.
41
53
  # Hydra::Ability#download_permissions can't be used in this case because it assumes
42
54
  # that files are in a LDP basic container, and thus, included in the asset's uri.
43
55
  def authorize_download!
44
56
  authorize! :download, params[asset_param_key]
45
- rescue CanCan::AccessDenied
57
+ # Deny access if the work containing this file is restricted by a workflow
58
+ return unless workflow_restriction?(file_set_parent(params[asset_param_key]), ability: current_ability)
59
+ raise Hyrax::WorkflowAuthorizationException
60
+ rescue CanCan::AccessDenied, Hyrax::WorkflowAuthorizationException
46
61
  unauthorized_image = Rails.root.join("app", "assets", "images", "unauthorized.png")
47
62
  send_file unauthorized_image, status: :unauthorized
48
63
  end
@@ -10,6 +10,7 @@ module Hyrax
10
10
  before_action :authenticate_user!, except: [:show, :citation, :stats]
11
11
  load_and_authorize_resource class: ::FileSet, except: :show
12
12
  before_action :build_breadcrumbs, only: [:show, :edit, :stats]
13
+ before_action :presenter
13
14
 
14
15
  # provides the help_text view method
15
16
  helper PermissionsHelper
@@ -191,7 +192,15 @@ module Hyrax
191
192
  def initialize_edit_form
192
193
  guard_for_workflow_restriction_on!(parent: parent)
193
194
 
194
- @version_list = Hyrax::VersionListPresenter.for(file_set: @file_set)
195
+ case file_set
196
+ when Hyrax::Resource
197
+ @form = Hyrax::Forms::ResourceForm.for(file_set)
198
+ @form.prepopulate!
199
+ else
200
+ @form = form_class.new(file_set)
201
+ @form[:visibility] = file_set.visibility # workaround for hydra-head < 12
202
+ end
203
+ @version_list = Hyrax::VersionListPresenter.for(file_set: file_set)
195
204
  @groups = current_user.groups
196
205
  end
197
206
 
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
  module Hyrax
3
3
  class PermissionsController < ApplicationController
4
- load_resource class: ActiveFedora::Base, instance_name: :curation_concern
4
+ load_resource class: Hyrax::Resource, instance_name: :curation_concern
5
5
 
6
6
  attr_reader :curation_concern
7
7
  helper_method :curation_concern
@@ -23,7 +23,6 @@ module Hyrax
23
23
  add_breadcrumb t(:'hyrax.controls.home'), root_path
24
24
  add_breadcrumb t(:'hyrax.dashboard.breadcrumbs.admin'), hyrax.dashboard_path
25
25
  add_breadcrumb t(:'hyrax.transfers.new.header'), hyrax.new_work_transfer_path
26
- @work = Hyrax::WorkRelation.new.find(params[:id])
27
26
  end
28
27
 
29
28
  def create
@@ -31,7 +30,6 @@ module Hyrax
31
30
  if @proxy_deposit_request.save
32
31
  redirect_to hyrax.transfers_path, notice: "Transfer request created"
33
32
  else
34
- @work = Hyrax::WorkRelation.new.find(params[:id])
35
33
  render :new
36
34
  end
37
35
  end
@@ -9,7 +9,8 @@ module Hyrax
9
9
  # @return [Hyrax::Resource]
10
10
  attr_reader :curation_concern
11
11
 
12
- load_resource class: Hyrax::Resource, instance_name: :curation_concern
12
+ resource_klass = Hyrax.config.use_valkyrie? ? Hyrax::Resource : ActiveFedora::Base
13
+ load_resource class: resource_klass, instance_name: :curation_concern
13
14
  before_action :authenticate_user!
14
15
 
15
16
  def update
@@ -39,7 +40,7 @@ module Hyrax
39
40
 
40
41
  def after_update_response
41
42
  respond_to do |wants|
42
- wants.html { redirect_to [main_app, curation_concern], notice: "The #{curation_concern.human_readable_type} has been updated." }
43
+ wants.html { redirect_to [main_app, curation_concern], notice: "The #{curation_concern.class.human_readable_type} has been updated." }
43
44
  wants.json { render 'hyrax/base/show', status: :ok, location: polymorphic_path([main_app, curation_concern]) }
44
45
  end
45
46
  end
@@ -109,7 +109,9 @@ module Hyrax
109
109
  # needed to make the determination are too expensive to do for every possible
110
110
  # collection, so we only test for this situation prior to saving the new
111
111
  # relationship.
112
+ # note: the graph indexer does not care about nesting depth
112
113
  def nesting_within_maximum_depth
114
+ return true if Hyrax.config.use_solr_graph_for_collection_nesting
113
115
  return true if query_service.valid_combined_nesting_depth?(parent: parent, child: child, scope: context)
114
116
  errors.add(:collection, :exceeds_maximum_nesting_depth)
115
117
  false
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+ module Hyrax
3
+ module Forms
4
+ ##
5
+ # Nested form for embargos.
6
+ class Embargo < Hyrax::ChangeSet
7
+ property :visibility_after_embargo
8
+ property :visibility_during_embargo
9
+ property :embargo_release_date
10
+ property :embargo_history, default: []
11
+ end
12
+ end
13
+ end
@@ -4,7 +4,7 @@ module Hyrax::Forms
4
4
  include HydraEditor::Form
5
5
  include HydraEditor::Form::Permissions
6
6
 
7
- delegate :depositor, :permissions, to: :model
7
+ delegate :depositor, :permissions, :human_readable_type, to: :model
8
8
 
9
9
  self.required_fields = [:title, :creator, :license]
10
10
 
@@ -3,44 +3,17 @@
3
3
  module Hyrax
4
4
  module Forms
5
5
  ##
6
- # @api public
7
- class FileSetForm < Hyrax::ChangeSet
6
+ # A form for +Hyrax::FileSet+s.
7
+ class FileSetForm < Hyrax::Forms::ResourceForm
8
8
  include Hyrax::FormFields(:core_metadata)
9
9
 
10
- class << self
11
- ##
12
- # @return [Array<Symbol>] list of required field names as symbols
13
- def required_fields
14
- definitions
15
- .select { |_, definition| definition[:required] }
16
- .keys.map(&:to_sym)
17
- end
18
- end
10
+ # The fields in +:file_set_metadata+ were hardcoded into this form in a
11
+ # previous version of Hyrax, but ideally in the future this metadata will
12
+ # be configurable.
13
+ include Hyrax::FormFields(:file_set_metadata)
19
14
 
20
- property :creator, required: true
21
- property :license, required: true
22
-
23
- property :based_near
24
- property :contributor
25
- property :date_created
26
- property :description
27
- property :identifier
28
- property :keyword
29
- property :language
30
- property :publisher
31
- property :related_url
32
- property :subject
33
-
34
- property :permissions, virtual: true
35
- property :visibility, default: VisibilityIntention::PRIVATE
36
-
37
- # virtual properties for embargo/lease;
38
- property :embargo_release_date, virtual: true
39
- property :visibility_after_embargo, virtual: true
40
- property :visibility_during_embargo, virtual: true
41
- property :lease_expiration_date, virtual: true
42
- property :visibility_after_lease, virtual: true
43
- property :visibility_during_lease, virtual: true
15
+ property :representative_id, type: Valkyrie::Types::String
16
+ property :thumbnail_id, type: Valkyrie::Types::String
44
17
  end
45
18
  end
46
19
  end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+ module Hyrax
3
+ module Forms
4
+ ##
5
+ # Nested form for leases.
6
+ class Lease < Hyrax::ChangeSet
7
+ property :visibility_after_lease
8
+ property :visibility_during_lease
9
+ property :lease_expiration_date
10
+ property :lease_history, default: []
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,46 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Hyrax
4
+ module Forms
5
+ ##
6
+ # A form for PCDM objects: resources which have collection relationships and
7
+ # generally resemble +Hyrax::Work+.
8
+ class PcdmObjectForm < Hyrax::Forms::ResourceForm
9
+ include Hyrax::FormFields(:core_metadata)
10
+
11
+ property :on_behalf_of
12
+ property :proxy_depositor
13
+
14
+ # pcdm relationships
15
+ property :admin_set_id, prepopulator: ->(_opts) { self.admin_set_id = Hyrax::AdminSetCreateService.find_or_create_default_admin_set.id.to_s }
16
+ property :member_ids, default: [], type: Valkyrie::Types::Array
17
+ property :member_of_collection_ids, default: [], type: Valkyrie::Types::Array
18
+ property :member_of_collections_attributes, virtual: true, populator: :in_collections_populator
19
+ validates_with CollectionMembershipValidator
20
+
21
+ property :representative_id, type: Valkyrie::Types::String
22
+ property :thumbnail_id, type: Valkyrie::Types::String
23
+ property :rendering_ids, default: [], type: Valkyrie::Types::Array
24
+
25
+ # backs the child work search element;
26
+ # @todo: look for a way for the view template not to depend on this
27
+ property :find_child_work, default: nil, virtual: true
28
+
29
+ private
30
+
31
+ def in_collections_populator(fragment:, **_options)
32
+ adds = []
33
+ deletes = []
34
+ fragment.each do |_, h|
35
+ if h["_destroy"] == "true"
36
+ deletes << Valkyrie::ID.new(h["id"])
37
+ else
38
+ adds << Valkyrie::ID.new(h["id"])
39
+ end
40
+ end
41
+
42
+ self.member_of_collection_ids = ((member_of_collection_ids + adds) - deletes).uniq
43
+ end
44
+ end
45
+ end
46
+ end
@@ -11,12 +11,16 @@ module Hyrax
11
11
  # # other WorkForm-like configuration here
12
12
  # end
13
13
  #
14
+ # @note The returned class will extend +Hyrax::Forms::PcdmObjectForm+, not
15
+ # only +Hyrax::Forms::ResourceForm+. This is for backwards‐compatibility
16
+ # with existing Hyrax instances and satisfies the expected general use
17
+ # case (building forms for various PCDM object classes), but is *not*
18
+ # necessarily suitable for other kinds of Hyrax resource, like
19
+ # +Hyrax::FileSet+s.
14
20
  def self.ResourceForm(work_class)
15
- Class.new(Hyrax::Forms::ResourceForm) do
21
+ Class.new(Hyrax::Forms::PcdmObjectForm) do
16
22
  self.model_class = work_class
17
23
 
18
- include Hyrax::FormFields(:core_metadata)
19
-
20
24
  ##
21
25
  # @return [String]
22
26
  def self.inspect
@@ -29,7 +33,7 @@ module Hyrax
29
33
  ##
30
34
  # @api public
31
35
  #
32
- # This form wraps `Hyrax::ChangeSet` in the `HydraEditor::Form` interface.
36
+ # This form wraps +Hyrax::ChangeSet+ in the +HydraEditor::Form+ interface.
33
37
  class ResourceForm < Hyrax::ChangeSet # rubocop:disable Metrics/ClassLength
34
38
  ##
35
39
  # @api private
@@ -69,10 +73,8 @@ module Hyrax
69
73
  property :human_readable_type, writable: false
70
74
 
71
75
  property :depositor
72
- property :on_behalf_of
73
- property :proxy_depositor
74
76
 
75
- property :visibility, default: VisibilityIntention::PRIVATE
77
+ property :visibility, default: VisibilityIntention::PRIVATE, populator: :visibility_populator
76
78
 
77
79
  property :date_modified, readable: false
78
80
  property :date_uploaded, readable: false
@@ -85,6 +87,9 @@ module Hyrax
85
87
  populator: :permission_populator,
86
88
  prepopulator: ->(_opts) { self.permissions = Hyrax::AccessControl.for(resource: model).permissions })
87
89
 
90
+ property :embargo, form: Hyrax::Forms::Embargo, populator: :embargo_populator
91
+ property :lease, form: Hyrax::Forms::Lease, populator: :lease_populator
92
+
88
93
  # virtual properties for embargo/lease;
89
94
  property :embargo_release_date, virtual: true, prepopulator: ->(_opts) { self.embargo_release_date = model.embargo&.embargo_release_date }
90
95
  property :visibility_after_embargo, virtual: true, prepopulator: ->(_opts) { self.visibility_after_embargo = model.embargo&.visibility_after_embargo }
@@ -94,17 +99,7 @@ module Hyrax
94
99
  property :visibility_after_lease, virtual: true, prepopulator: ->(_opts) { self.visibility_after_lease = model.lease&.visibility_after_lease }
95
100
  property :visibility_during_lease, virtual: true, prepopulator: ->(_opts) { self.visibility_during_lease = model.lease&.visibility_during_lease }
96
101
 
97
- # pcdm relationships
98
- property :admin_set_id, prepopulator: ->(_opts) { self.admin_set_id = Hyrax::AdminSetCreateService.find_or_create_default_admin_set.id.to_s }
99
102
  property :in_works_ids, virtual: true, prepopulator: InWorksPrepopulator
100
- property :member_ids, default: [], type: Valkyrie::Types::Array
101
- property :member_of_collection_ids, default: [], type: Valkyrie::Types::Array
102
- property :member_of_collections_attributes, virtual: true, populator: :in_collections_populator
103
- validates_with CollectionMembershipValidator
104
-
105
- property :representative_id, type: Valkyrie::Types::String
106
- property :thumbnail_id, type: Valkyrie::Types::String
107
- property :rendering_ids, default: [], type: Valkyrie::Types::Array
108
103
 
109
104
  # provide a lock token for optimistic locking; we name this `version` for
110
105
  # backwards compatibility
@@ -116,10 +111,6 @@ module Hyrax
116
111
  # @see https://github.com/samvera/valkyrie/wiki/Optimistic-Locking
117
112
  property :version, virtual: true, prepopulator: LockKeyPrepopulator
118
113
 
119
- # backs the child work search element;
120
- # @todo: look for a way for the view template not to depend on this
121
- property :find_child_work, default: nil, virtual: true
122
-
123
114
  class << self
124
115
  ##
125
116
  # @api public
@@ -140,6 +131,7 @@ module Hyrax
140
131
  when Hyrax::PcdmCollection
141
132
  Hyrax::Forms::PcdmCollectionForm.new(resource)
142
133
  else
134
+ # NOTE: This will create a +Hyrax::Forms::PcdmObjectForm+.
143
135
  Hyrax::Forms::ResourceForm(resource.class).new(resource)
144
136
  end
145
137
  end
@@ -208,18 +200,12 @@ module Hyrax
208
200
 
209
201
  private
210
202
 
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
203
+ def embargo_populator(**)
204
+ self.embargo = Hyrax::EmbargoManager.embargo_for(resource: model)
205
+ end
221
206
 
222
- self.member_of_collection_ids = ((member_of_collection_ids + adds) - deletes).uniq
207
+ def lease_populator(**)
208
+ self.lease = Hyrax::LeaseManager.lease_for(resource: model)
223
209
  end
224
210
 
225
211
  # https://trailblazer.to/2.1/docs/reform.html#reform-populators-populator-collections
@@ -227,6 +213,24 @@ module Hyrax
227
213
  Hyrax::Forms::Permission.new(collection[index])
228
214
  end
229
215
 
216
+ def visibility_populator(fragment:, doc:, **)
217
+ case fragment
218
+ when "embargo"
219
+ self.visibility = doc['visibility_during_embargo']
220
+
221
+ doc['embargo'] = doc.slice('visibility_after_embargo',
222
+ 'visibility_during_embargo',
223
+ 'embargo_release_date')
224
+ when "lease"
225
+ self.visibility = doc['visibility_during_lease']
226
+ doc['lease'] = doc.slice('visibility_after_lease',
227
+ 'visibility_during_lease',
228
+ 'lease_expiration_date')
229
+ else
230
+ self.visibility = fragment
231
+ end
232
+ end
233
+
230
234
  def _form_field_definitions
231
235
  self.class.definitions
232
236
  end
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Hyrax
4
+ module Forms
5
+ ##
6
+ # Represents an embargo 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 embargo, ignoring the work's other fields.
9
+ #
10
+ # @note this supports the edit functionality of
11
+ # +EmbargoesControllerBehavior+.
12
+ class WorkEmbargoForm < Hyrax::ChangeSet
13
+ property :embargo, form: Hyrax::Forms::Embargo, populator: :embargo_populator, prepopulator: :embargo_populator
14
+ property :embargo_release_date, virtual: true, prepopulator: ->(_opts) { self.embargo_release_date = model.embargo&.embargo_release_date }
15
+ property :visibility_after_embargo, virtual: true, prepopulator: ->(_opts) { self.visibility_after_embargo = model.embargo&.visibility_after_embargo }
16
+ property :visibility_during_embargo, virtual: true, prepopulator: ->(_opts) { self.visibility_during_embargo = model.embargo&.visibility_during_embargo }
17
+
18
+ def embargo_populator(**)
19
+ self.embargo = Hyrax::EmbargoManager.embargo_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