hyrax 3.1.0 → 3.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (114) hide show
  1. checksums.yaml +4 -4
  2. data/.circleci/config.yml +5 -5
  3. data/.dassie/Gemfile +1 -1
  4. data/.dassie/app/controllers/catalog_controller.rb +6 -0
  5. data/Dockerfile +2 -3
  6. data/app/actors/hyrax/actors/base_actor.rb +1 -1
  7. data/app/actors/hyrax/actors/collections_membership_actor.rb +3 -3
  8. data/app/actors/hyrax/actors/file_set_actor.rb +2 -0
  9. data/app/assets/stylesheets/hyrax/_styles.scss +5 -0
  10. data/app/controllers/concerns/hyrax/collections_controller_behavior.rb +13 -5
  11. data/app/controllers/concerns/hyrax/controller.rb +13 -2
  12. data/app/controllers/hyrax/admin/admin_sets_controller.rb +2 -19
  13. data/app/controllers/hyrax/admin/permission_template_accesses_controller.rb +5 -2
  14. data/app/controllers/hyrax/collections_controller.rb +3 -1
  15. data/app/controllers/hyrax/dashboard/collection_members_controller.rb +12 -9
  16. data/app/controllers/hyrax/dashboard/collections_controller.rb +92 -28
  17. data/app/controllers/hyrax/dashboard/nest_collections_controller.rb +75 -39
  18. data/app/controllers/hyrax/my_controller.rb +4 -4
  19. data/app/controllers/hyrax/workflow_actions_controller.rb +8 -5
  20. data/app/forms/hyrax/forms/administrative_set_form.rb +62 -0
  21. data/app/forms/hyrax/forms/collection_form.rb +2 -2
  22. data/app/forms/hyrax/forms/dashboard/nest_collection_form.rb +14 -4
  23. data/app/forms/hyrax/forms/pcdm_collection_form.rb +64 -0
  24. data/app/forms/hyrax/forms/resource_form.rb +15 -10
  25. data/app/forms/hyrax/forms/workflow_action_form.rb +4 -0
  26. data/app/helpers/hyrax/hyrax_helper_behavior.rb +9 -0
  27. data/app/indexers/hyrax/administrative_set_indexer.rb +6 -6
  28. data/app/indexers/hyrax/pcdm_collection_indexer.rb +2 -0
  29. data/app/models/admin_set.rb +16 -5
  30. data/app/models/concerns/hyrax/ability/admin_set_ability.rb +31 -7
  31. data/app/models/concerns/hyrax/ability/collection_ability.rb +35 -20
  32. data/app/models/concerns/hyrax/ability/collection_type_ability.rb +1 -1
  33. data/app/models/concerns/hyrax/ability.rb +2 -2
  34. data/app/models/concerns/hyrax/solr_document_behavior.rb +2 -2
  35. data/app/models/hyrax/administrative_set.rb +7 -1
  36. data/app/models/hyrax/permission.rb +1 -1
  37. data/app/models/hyrax/permission_template.rb +19 -5
  38. data/app/models/hyrax/work.rb +1 -0
  39. data/app/models/hyrax/workflow_action_info.rb +16 -0
  40. data/app/models/sipity/comment.rb +17 -0
  41. data/app/models/sipity.rb +11 -2
  42. data/app/presenters/hyrax/admin_set_presenter.rb +8 -3
  43. data/app/presenters/hyrax/collection_presenter.rb +3 -3
  44. data/app/presenters/hyrax/work_show_presenter.rb +2 -1
  45. data/app/search_builders/hyrax/abstract_type_relation.rb +4 -2
  46. data/app/search_builders/hyrax/dashboard/collections_search_builder.rb +1 -1
  47. data/app/search_builders/hyrax/exposed_models_relation.rb +1 -1
  48. data/app/search_builders/hyrax/filter_by_type.rb +1 -2
  49. data/app/search_builders/hyrax/my/collections_search_builder.rb +1 -1
  50. data/app/services/hyrax/admin_set_create_service.rb +136 -54
  51. data/app/services/hyrax/collection_types/permissions_service.rb +1 -1
  52. data/app/services/hyrax/collections/collection_member_service.rb +12 -2
  53. data/app/services/hyrax/collections/permissions_create_service.rb +81 -79
  54. data/app/services/hyrax/collections/permissions_service.rb +1 -1
  55. data/app/services/hyrax/curation_concern.rb +24 -2
  56. data/app/services/hyrax/default_middleware_stack.rb +11 -0
  57. data/app/services/hyrax/ensure_well_formed_admin_set_service.rb +3 -3
  58. data/app/services/hyrax/listeners/active_fedora_acl_index_listener.rb +1 -0
  59. data/app/services/hyrax/listeners/metadata_index_listener.rb +25 -9
  60. data/app/services/hyrax/permission_manager.rb +4 -4
  61. data/app/services/hyrax/solr_service.rb +1 -1
  62. data/app/services/hyrax/statistics/collections/over_time.rb +2 -1
  63. data/app/services/hyrax/workflow/abstract_notification.rb +2 -2
  64. data/app/services/hyrax/workflow/action_taken_service.rb +16 -4
  65. data/app/services/hyrax/workflow/activate_object.rb +5 -4
  66. data/app/services/hyrax/workflow/changes_required_notification.rb +5 -4
  67. data/app/services/hyrax/workflow/deactivate_object.rb +7 -5
  68. data/app/services/hyrax/workflow/deposited_notification.rb +8 -4
  69. data/app/services/hyrax/workflow/grant_edit_to_depositor.rb +7 -3
  70. data/app/services/hyrax/workflow/grant_read_to_depositor.rb +10 -3
  71. data/app/services/hyrax/workflow/revoke_edit_from_depositor.rb +8 -2
  72. data/app/services/hyrax/workflow/workflow_action_service.rb +4 -1
  73. data/app/views/hyrax/admin/admin_sets/_form.html.erb +1 -1
  74. data/app/views/hyrax/dashboard/collections/_collection_title.html.erb +1 -1
  75. data/app/views/hyrax/dashboard/collections/_form.html.erb +1 -1
  76. data/app/views/hyrax/dashboard/collections/_sort_and_per_page.html.erb +1 -1
  77. data/app/views/hyrax/homepage/index.html.erb +1 -1
  78. data/app/views/hyrax/my/collections/_modal_collection_types_to_create.html.erb +1 -1
  79. data/app/views/layouts/hyrax/dashboard.html.erb +1 -0
  80. data/app/views/layouts/hyrax.html.erb +1 -0
  81. data/app/views/shared/_read_only.html.erb +5 -0
  82. data/chart/hyrax/Chart.yaml +2 -2
  83. data/chart/hyrax/templates/deployment.yaml +6 -0
  84. data/config/features.rb +3 -0
  85. data/config/initializers/1_healthz.rb +1 -0
  86. data/config/initializers/listeners.rb +2 -1
  87. data/config/locales/hyrax.en.yml +1 -0
  88. data/db/seeds.rb +1 -1
  89. data/documentation/developing-your-hyrax-based-app.md +1 -1
  90. data/documentation/legacyREADME.md +1 -1
  91. data/hyrax.gemspec +1 -1
  92. data/lib/generators/hyrax/templates/catalog_controller.rb +3 -1
  93. data/lib/generators/hyrax/templates/config/initializers/hyrax.rb +10 -0
  94. data/lib/generators/hyrax/work/templates/feature_spec.rb.erb +1 -1
  95. data/lib/generators/hyrax/work_resource/templates/indexer_spec.rb.erb +1 -0
  96. data/lib/hyrax/collection_name.rb +6 -2
  97. data/lib/hyrax/configuration.rb +28 -0
  98. data/lib/hyrax/form_fields.rb +1 -0
  99. data/lib/hyrax/publisher.rb +12 -0
  100. data/lib/hyrax/resource_sync/change_list_writer.rb +2 -2
  101. data/lib/hyrax/resource_sync/resource_list_writer.rb +2 -2
  102. data/lib/hyrax/specs/shared_specs/hydra_works.rb +2 -0
  103. data/lib/hyrax/specs/shared_specs/indexers.rb +6 -0
  104. data/lib/hyrax/transactions/collection_create.rb +25 -0
  105. data/lib/hyrax/transactions/collection_update.rb +20 -0
  106. data/lib/hyrax/transactions/container.rb +26 -0
  107. data/lib/hyrax/transactions/steps/add_to_collections.rb +13 -1
  108. data/lib/hyrax/transactions/steps/apply_collection_type_permissions.rb +29 -0
  109. data/lib/hyrax/transactions/steps/save.rb +18 -6
  110. data/lib/hyrax/transactions/steps/set_collection_type_gid.rb +35 -0
  111. data/lib/hyrax/version.rb +1 -1
  112. data/lib/tasks/default_admin_set.rake +12 -11
  113. data/template.rb +1 -1
  114. metadata +16 -9
@@ -159,7 +159,7 @@ module Hyrax
159
159
  # If calling from Abilities, pass the ability. If you try to get the ability from the user, you end up in an infinit loop.
160
160
  def self.access_to_collection_type?(collection_type:, access:, user: nil, ability: nil) # rubocop:disable Metrics/CyclomaticComplexity
161
161
  return false unless user.present? || ability.present?
162
- return false unless user && collection_type
162
+ return false unless collection_type
163
163
  return true if ([user_id(user, ability)] & agent_ids_for(collection_type: collection_type, agent_type: 'user', access: access)).present?
164
164
  return true if (user_groups(user, ability) & agent_ids_for(collection_type: collection_type, agent_type: 'group', access: access)).present?
165
165
  false
@@ -110,7 +110,7 @@ module Hyrax
110
110
  raise Hyrax::SingleMembershipError, message if message.present?
111
111
  new_member.member_of_collection_ids << collection_id # only populate this direction
112
112
  new_member = Hyrax.persister.save(resource: new_member)
113
- Hyrax.publisher.publish('object.metadata.updated', object: new_member, user: user)
113
+ publish_metadata_updated(new_member, user)
114
114
  new_member
115
115
  end
116
116
 
@@ -148,9 +148,19 @@ module Hyrax
148
148
  return member unless member?(collection_id: collection_id, member: member)
149
149
  member.member_of_collection_ids.delete(collection_id)
150
150
  member = Hyrax.persister.save(resource: member)
151
- Hyrax.publisher.publish('object.metadata.updated', object: member, user: user)
151
+ publish_metadata_updated(member, user)
152
152
  member
153
153
  end
154
+
155
+ private
156
+
157
+ def publish_metadata_updated(member, user)
158
+ if member.collection?
159
+ Hyrax.publisher.publish('collection.metadata.updated', collection: member, user: user)
160
+ else
161
+ Hyrax.publisher.publish('object.metadata.updated', object: member, user: user)
162
+ end
163
+ end
154
164
  end
155
165
  end
156
166
  end
@@ -2,94 +2,96 @@
2
2
  module Hyrax
3
3
  module Collections
4
4
  class PermissionsCreateService
5
- # @api public
6
- #
7
- # Set the default permissions for a (newly created) collection
8
- #
9
- # @param collection [::Collection] the collection the new permissions will act on
10
- # @param creating_user [User] the user that created the collection
11
- # @param grants [Array<Hash>] additional grants to apply to the new collection
12
- # @return [Hyrax::PermissionTemplate]
13
- def self.create_default(collection:, creating_user:, grants: [])
14
- collection_type = Hyrax::CollectionType.find_by_gid!(collection.collection_type_gid)
15
- access_grants = access_grants_attributes(collection_type: collection_type, creating_user: creating_user, grants: grants)
16
- template = PermissionTemplate.create!(source_id: collection.id,
17
- access_grants_attributes: access_grants.uniq)
5
+ class << self
6
+ # @api public
7
+ #
8
+ # Set the default permissions for a (newly created) collection
9
+ #
10
+ # @param collection [#collection_type_gid || Hyrax::AdministrativeSet] the collection or admin set the new permissions will act on
11
+ # @param creating_user [User] the user that created the collection
12
+ # @param grants [Array<Hash>] additional grants to apply to the new collection
13
+ # @return [Hyrax::PermissionTemplate]
14
+ def create_default(collection:, creating_user:, grants: [])
15
+ collection_type = Hyrax::CollectionType.find_by_gid!(collection.collection_type_gid)
16
+ access_grants = access_grants_attributes(collection_type: collection_type, creating_user: creating_user, grants: grants)
17
+ template = Hyrax::PermissionTemplate.create!(source_id: collection.id.to_s,
18
+ access_grants_attributes: access_grants.uniq)
18
19
 
19
- template.reset_access_controls_for(collection: collection, interpret_visibility: true)
20
- end
21
-
22
- # @api public
23
- #
24
- # Add access grants to a collection
25
- #
26
- # @param collection_id [String] id of a collection
27
- # @param grants [Array<Hash>] array of grants to add to the collection
28
- # @example grants
29
- # [ { agent_type: Hyrax::PermissionTemplateAccess::GROUP,
30
- # agent_id: 'my_group_name',
31
- # access: Hyrax::PermissionTemplateAccess::DEPOSIT } ]
32
- # @see Hyrax::PermissionTemplateAccess for valid values for agent_type and access
33
- def self.add_access(collection_id:, grants:)
34
- collection = ::Collection.find(collection_id)
35
- template = Hyrax::PermissionTemplate.find_by!(source_id: collection_id)
36
- grants.each do |grant|
37
- Hyrax::PermissionTemplateAccess.find_or_create_by(permission_template_id: template.id,
38
- agent_type: grant[:agent_type],
39
- agent_id: grant[:agent_id],
40
- access: grant[:access])
20
+ template.reset_access_controls_for(collection: collection, interpret_visibility: true)
21
+ template
41
22
  end
42
23
 
43
- template.reset_access_controls_for(collection: collection, interpret_visibility: true)
44
- end
24
+ # @api public
25
+ #
26
+ # Add access grants to a collection
27
+ #
28
+ # @param collection_id [String] id of a collection
29
+ # @param grants [Array<Hash>] array of grants to add to the collection
30
+ # @example grants
31
+ # [ { agent_type: Hyrax::PermissionTemplateAccess::GROUP,
32
+ # agent_id: 'my_group_name',
33
+ # access: Hyrax::PermissionTemplateAccess::DEPOSIT } ]
34
+ # @see Hyrax::PermissionTemplateAccess for valid values for agent_type and access
35
+ def add_access(collection_id:, grants:)
36
+ collection = Hyrax.query_service.find_by(id: collection_id)
37
+ template = Hyrax::PermissionTemplate.find_by!(source_id: collection_id.to_s)
38
+ grants.each do |grant|
39
+ Hyrax::PermissionTemplateAccess.find_or_create_by(permission_template_id: template.id.to_s,
40
+ agent_type: grant[:agent_type],
41
+ agent_id: grant[:agent_id],
42
+ access: grant[:access])
43
+ end
45
44
 
46
- # @api private
47
- #
48
- # Gather the default permissions needed for a new collection
49
- #
50
- # @param collection_type [CollectionType] the collection type of the new collection
51
- # @param creating_user [User] the user that created the collection
52
- # @param grants [Array<Hash>] additional grants to apply to the new collection
53
- # @return [Hash] a hash containing permission attributes
54
- def self.access_grants_attributes(collection_type:, creating_user:, grants:)
55
- [
56
- { agent_type: 'group', agent_id: admin_group_name, access: Hyrax::PermissionTemplateAccess::MANAGE }
57
- ].tap do |attribute_list|
58
- # Grant manage access to the creating_user if it exists
59
- attribute_list << { agent_type: 'user', agent_id: creating_user.user_key, access: Hyrax::PermissionTemplateAccess::MANAGE } if creating_user
60
- end + managers_of_collection_type(collection_type: collection_type) + grants
61
- end
62
- private_class_method :access_grants_attributes
45
+ template.reset_access_controls_for(collection: collection, interpret_visibility: true)
46
+ end
63
47
 
64
- # @api private
65
- #
66
- # Retrieve the users or groups with manage permissions for a collection type
67
- #
68
- # @param collection_type [CollectionType] the collection type of the new collection
69
- # @return [Hash] a hash containing permission attributes
70
- def self.managers_of_collection_type(collection_type:)
71
- attribute_list = []
72
- user_managers = Hyrax::CollectionTypes::PermissionsService.user_edit_grants_for_collection_of_type(collection_type: collection_type)
73
- user_managers.each do |user|
74
- attribute_list << { agent_type: 'user', agent_id: user, access: Hyrax::PermissionTemplateAccess::MANAGE }
48
+ private
49
+
50
+ # @api private
51
+ #
52
+ # Gather the default permissions needed for a new collection
53
+ #
54
+ # @param collection_type [CollectionType] the collection type of the new collection
55
+ # @param creating_user [User] the user that created the collection
56
+ # @param grants [Array<Hash>] additional grants to apply to the new collection
57
+ # @return [Array<Hash>] a hash containing permission attributes
58
+ def access_grants_attributes(collection_type:, creating_user:, grants:)
59
+ [
60
+ { agent_type: 'group', agent_id: admin_group_name, access: Hyrax::PermissionTemplateAccess::MANAGE }
61
+ ].tap do |attribute_list|
62
+ # Grant manage access to the creating_user if it exists
63
+ attribute_list << { agent_type: 'user', agent_id: creating_user.user_key, access: Hyrax::PermissionTemplateAccess::MANAGE } if creating_user
64
+ end + managers_of_collection_type(collection_type: collection_type) + grants
75
65
  end
76
- group_managers = Hyrax::CollectionTypes::PermissionsService.group_edit_grants_for_collection_of_type(collection_type: collection_type)
77
- group_managers.each do |group|
78
- attribute_list << { agent_type: 'group', agent_id: group, access: Hyrax::PermissionTemplateAccess::MANAGE }
66
+
67
+ # @api private
68
+ #
69
+ # Retrieve the users or groups with manage permissions for a collection type
70
+ #
71
+ # @param collection_type [CollectionType] the collection type of the new collection
72
+ # @return [Array<Hash>] a hash containing permission attributes
73
+ def managers_of_collection_type(collection_type:)
74
+ attribute_list = []
75
+ user_managers = Hyrax::CollectionTypes::PermissionsService.user_edit_grants_for_collection_of_type(collection_type: collection_type)
76
+ user_managers.each do |user|
77
+ attribute_list << { agent_type: 'user', agent_id: user, access: Hyrax::PermissionTemplateAccess::MANAGE }
78
+ end
79
+ group_managers = Hyrax::CollectionTypes::PermissionsService.group_edit_grants_for_collection_of_type(collection_type: collection_type)
80
+ group_managers.each do |group|
81
+ attribute_list << { agent_type: 'group', agent_id: group, access: Hyrax::PermissionTemplateAccess::MANAGE }
82
+ end
83
+ attribute_list
79
84
  end
80
- attribute_list
81
- end
82
- private_class_method :managers_of_collection_type
83
85
 
84
- # @api private
85
- #
86
- # The value of the admin group name
87
- #
88
- # @return [String] a string representation of the admin group name
89
- def self.admin_group_name
90
- ::Ability.admin_group_name
86
+ # @api private
87
+ #
88
+ # The value of the admin group name
89
+ #
90
+ # @return [String] a string representation of the admin group name
91
+ def admin_group_name
92
+ ::Ability.admin_group_name
93
+ end
91
94
  end
92
- private_class_method :admin_group_name
93
95
  end
94
96
  end
95
97
  end
@@ -243,7 +243,7 @@ module Hyrax
243
243
  # @note Several checks get the user's groups from the user's ability. The same values can be retrieved directly from a passed in ability.
244
244
  def self.access_to_collection?(collection_id:, access:, ability:, exclude_groups: [])
245
245
  return false unless collection_id
246
- template = Hyrax::PermissionTemplate.find_by!(source_id: collection_id)
246
+ template = Hyrax::PermissionTemplate.find_by!(source_id: collection_id.to_s)
247
247
  return true if ([ability.current_user.user_key] & template.agent_ids_for(agent_type: 'user', access: access)).present?
248
248
  return true if (ability.user_groups & (template.agent_ids_for(agent_type: 'group', access: access) - exclude_groups)).present?
249
249
  false
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
  module Hyrax
3
3
  class CurationConcern
4
+ ##
4
5
  # The actor middleware stack can be customized like so:
5
6
  # # Adding a new middleware
6
7
  # Hyrax::CurationConcern.actor_factory.use MyCustomActor
@@ -16,14 +17,35 @@ module Hyrax
16
17
  #
17
18
  # You can customize the actor stack, so long as you do so before the actor
18
19
  # is used. Once it is used, it becomes immutable.
20
+ #
19
21
  # @return [ActionDispatch::MiddlewareStack]
22
+ # @see Hyrax::DefaultMiddlewareStack
20
23
  def self.actor_factory
21
24
  @actor_factory ||= Hyrax::DefaultMiddlewareStack.build_stack
22
25
  end
23
26
 
24
- # A consumer of this method can inject a different factory
25
- # into this class in order to change the behavior of this method.
27
+ ##
28
+ # Provides the Hyrax "Actor Stack" used during creation of Works when
29
+ # +ActiveFedora+ models are used by the application
30
+ #
31
+ # The "Actor Stack" consists of a series of objects ("Actors"), which
32
+ # implement +#create+, +#update+ and +#destroy+. Each actor's methods
33
+ # promise to call the same methods on the next actor in the series, and may
34
+ # do some work before (on the way down the stack) and/or after (on the
35
+ # way up) calling to the next actor.
36
+ #
37
+ # The normal convention is to call an actor inheriting
38
+ # {Hyrax::Actors::BaseActor} at or near the bottom of the stack, to handle
39
+ # the create, update , or destroy action.
40
+ #
41
+ # @note this stack, and the Actor classes it calls, is not used when
42
+ # +Valkyrie+ models are defined by the application. in that context,
43
+ # this behavior is replaced by `Hyrax::Transactions::Container`.
44
+ #
26
45
  # @return [#create, #update] an actor that can create and update the work
46
+ #
47
+ # @see Hyrax::DefaultMiddlewareStack
48
+ # @see https://samvera.github.io/actor_stack.html
27
49
  def self.actor
28
50
  @work_middleware_stack ||= actor_factory.build(Actors::Terminator.new)
29
51
  end
@@ -1,5 +1,16 @@
1
1
  # frozen_string_literal: true
2
2
  module Hyrax
3
+ ##
4
+ # Defines the Hyrax "Actor Stack", used in creation of works when using
5
+ # +ActiveFedora+.
6
+ #
7
+ # @note this stack, and the Actor classes it calls, is not used when
8
+ # +Valkyrie+ models are defined by the application. in that context,
9
+ # this behavior is replaced by `Hyrax::Transactions::Container`.
10
+ #
11
+ # @see Hyrax::CurationConcern.actor
12
+ # @see Hyrax::WorksControllerBehavior#create
13
+ # @see Hyrax::WorksControllerBehavior#update
3
14
  class DefaultMiddlewareStack
4
15
  # rubocop:disable Metrics/MethodLength
5
16
  def self.build_stack
@@ -14,12 +14,12 @@ module Hyrax
14
14
  #
15
15
  # @param admin_set_id [String, nil]
16
16
  #
17
- # @return [String] an admin_set_id; if you provide a "present"
17
+ # @return [#to_s] an admin_set_id; if you provide a "present"
18
18
  # admin_set_id, this service will return that.
19
19
  #
20
- # @see AdminSet.find_or_create_default_admin_set_id
20
+ # @see Hyrax::AdminSetCreateService.find_or_create_default_admin_set
21
21
  def self.call(admin_set_id: nil)
22
- admin_set_id = admin_set_id.presence || AdminSet.find_or_create_default_admin_set_id
22
+ admin_set_id = admin_set_id.presence&.to_s || Hyrax::AdminSetCreateService.find_or_create_default_admin_set.id.to_s
23
23
  Hyrax::PermissionTemplate.find_or_create_by!(source_id: admin_set_id)
24
24
  admin_set_id
25
25
  end
@@ -13,6 +13,7 @@ module Hyrax
13
13
  #
14
14
  # @param event [Dry::Event]
15
15
  def on_object_acl_updated(event)
16
+ return if Hyrax.config.disable_wings
16
17
  return unless event[:result] == :success # do nothing on failure
17
18
 
18
19
  if Hyrax.metadata_adapter.is_a?(Wings::Valkyrie::MetadataAdapter)
@@ -15,10 +15,17 @@ module Hyrax
15
15
  # Re-index the resource.
16
16
  #
17
17
  # @param event [Dry::Event]
18
- def on_object_metadata_updated(event)
19
- log_non_resource(event) && return unless
20
- event[:object].is_a?(Valkyrie::Resource)
18
+ def on_collection_metadata_updated(event)
19
+ return unless resource? event[:collection]
20
+ Hyrax.index_adapter.save(resource: event[:collection])
21
+ end
21
22
 
23
+ ##
24
+ # Re-index the resource.
25
+ #
26
+ # @param event [Dry::Event]
27
+ def on_object_metadata_updated(event)
28
+ return unless resource? event[:object]
22
29
  Hyrax.index_adapter.save(resource: event[:object])
23
30
  end
24
31
 
@@ -27,17 +34,26 @@ module Hyrax
27
34
  #
28
35
  # @param event [Dry::Event]
29
36
  def on_object_deleted(event)
30
- log_non_resource(event.payload) && return unless
31
- event.payload[:object].is_a?(Valkyrie::Resource)
32
-
37
+ return unless resource?(event.payload[:object])
33
38
  Hyrax.index_adapter.delete(resource: event[:object])
34
39
  end
35
40
 
36
41
  private
37
42
 
38
- def log_non_resource(event)
39
- Hyrax.logger.info('Skipping object reindex because the object ' \
40
- "#{event[:object]} was not a Valkyrie::Resource.")
43
+ def resource?(resource)
44
+ return true if resource.is_a? Valkyrie::Resource
45
+ log_non_resource(resource)
46
+ false
47
+ end
48
+
49
+ def log_non_resource(resource)
50
+ generic_type = resource_generic_type(resource)
51
+ Hyrax.logger.info("Skipping #{generic_type} reindex because the " \
52
+ "#{generic_type} #{resource} was not a Valkyrie::Resource.")
53
+ end
54
+
55
+ def resource_generic_type(resource)
56
+ resource.try(:collection?) ? 'collection' : 'object'
41
57
  end
42
58
  end
43
59
  end
@@ -143,7 +143,7 @@ module Hyrax
143
143
  def groups_for(mode:)
144
144
  Enumerator.new do |yielder|
145
145
  acl.permissions.each do |permission|
146
- next unless permission.mode == mode
146
+ next unless permission.mode.to_sym == mode
147
147
  next unless permission.agent.starts_with?(Hyrax::Group.name_prefix)
148
148
  yielder << permission.agent.gsub(Hyrax::Group.name_prefix, '')
149
149
  end
@@ -154,7 +154,7 @@ module Hyrax
154
154
  groups = groups.map(&:to_s)
155
155
 
156
156
  acl.permissions.each do |permission|
157
- next unless permission.mode == mode
157
+ next unless permission.mode.to_sym == mode
158
158
  next unless permission.agent.starts_with?(Hyrax::Group.name_prefix)
159
159
 
160
160
  group_name = permission.agent.gsub(Hyrax::Group.name_prefix, '')
@@ -175,7 +175,7 @@ module Hyrax
175
175
  end
176
176
 
177
177
  acl.permissions.each do |permission|
178
- next unless permission.mode == mode
178
+ next unless permission.mode.to_sym == mode
179
179
  next if permission.agent.starts_with?(Hyrax::Group.name_prefix)
180
180
  next if users.include? permission.agent
181
181
 
@@ -189,7 +189,7 @@ module Hyrax
189
189
  def users_for(mode:)
190
190
  Enumerator.new do |yielder|
191
191
  acl.permissions.each do |permission|
192
- next unless permission.mode == mode
192
+ next unless permission.mode.to_sym == mode
193
193
  next if permission.agent.starts_with?(Hyrax::Group.name_prefix)
194
194
  yielder << permission.agent
195
195
  end
@@ -140,7 +140,7 @@ module Hyrax
140
140
  # valkyrie indexers used here would, at minimum, need to provide a
141
141
  # functioning `rsolr` connection.
142
142
  def valkyrie_index
143
- Valkyrie::IndexingAdapter.find(:solr_index)
143
+ Hyrax.index_adapter
144
144
  end
145
145
 
146
146
  ##
@@ -6,7 +6,8 @@ module Hyrax
6
6
  private
7
7
 
8
8
  def relation
9
- ::Collection
9
+ AbstractTypeRelation
10
+ .new(allowable_types: [Hyrax.config.collection_class])
10
11
  end
11
12
  end
12
13
  end
@@ -39,9 +39,9 @@ module Hyrax
39
39
  # @option recipients [Array<Hyrax::User>] :to a list of users to which to send the notification
40
40
  # @option recipients [Array<Hyrax::User>] :cc a list of users to which to copy on the notification
41
41
  def initialize(entity, comment, user, recipients)
42
- @work_id = entity.proxy_for_global_id.sub(/.*\//, '')
42
+ @work_id = entity.proxy_for.id
43
43
  @title = entity.proxy_for.title.first
44
- @comment = comment.respond_to?(:comment) ? comment.comment.to_s : ''
44
+ @comment = comment&.comment.to_s
45
45
  # Convert to hash with indifferent access to allow both string and symbol keys
46
46
  @recipients = recipients.with_indifferent_access
47
47
  @user = user
@@ -14,7 +14,14 @@ module Hyrax
14
14
  end
15
15
 
16
16
  def initialize(target:, action:, comment:, user:)
17
- @target = target
17
+ @target =
18
+ case target
19
+ when Valkyrie::Resource
20
+ Hyrax::ChangeSet.for(target)
21
+ else
22
+ target
23
+ end
24
+
18
25
  @action = action
19
26
  @comment = comment
20
27
  @user = user
@@ -70,10 +77,15 @@ module Hyrax
70
77
  # @api private
71
78
  def save_target
72
79
  case target
73
- when ActiveFedora::Base
74
- target.save
80
+ when Valkyrie::ChangeSet
81
+ return target.model unless target.changed?
82
+
83
+ Hyrax::Transactions::Container['change_set.apply']
84
+ .with_step_args('change_set.save' => { user: user })
85
+ .call(target)
86
+ .value!
75
87
  else
76
- Hyrax.persister.save(resource: target)
88
+ target.save
77
89
  end
78
90
  end
79
91
  end
@@ -3,14 +3,15 @@ module Hyrax
3
3
  module Workflow
4
4
  module ActivateObject
5
5
  ##
6
- # This is a built in function for workflow, setting the `#state`
7
- # of the target to the Fedora 'active' status URI
6
+ # This is a built in function for workflow, setting the +#state+
7
+ # of the target to the Fedora +active+ status URI
8
8
  #
9
- # @param target [#state] an instance of a model that includes `Hyrax::Suppressible`
9
+ # @param target [#state] an instance of a model with a +#state+ property;
10
+ # e.g. a {Hyrax::Work}
10
11
  #
11
12
  # @return [RDF::Vocabulary::Term] the Fedora Resource Status 'active' term
12
13
  def self.call(target:, **)
13
- target.state = Vocab::FedoraResourceStatus.active
14
+ target.state = Hyrax::ResourceStatus::ACTIVE
14
15
  end
15
16
  end
16
17
  end
@@ -9,14 +9,15 @@ module Hyrax
9
9
  end
10
10
 
11
11
  def message
12
- I18n.t('hyrax.notifications.workflow.changes_required.message', title: title,
13
- link: (link_to work_id, document_path),
14
- comment: comment)
12
+ I18n.t('hyrax.notifications.workflow.changes_required.message',
13
+ title: title,
14
+ link: (link_to work_id, document_path),
15
+ comment: comment)
15
16
  end
16
17
 
17
18
  def users_to_notify
18
19
  user_key = document.depositor
19
- super << ::User.find_by(email: user_key)
20
+ super << ::User.find_by_user_key(user_key)
20
21
  end
21
22
  end
22
23
  end
@@ -2,15 +2,17 @@
2
2
  module Hyrax
3
3
  module Workflow
4
4
  ##
5
- # This is a built in function for workflow, setting the `#state`
6
- # of the target to the Fedora 'inactive' status URI
5
+ # This is a built in function for workflow, setting the +#state+
6
+ # of the target to the Fedora +inactive+ status URI
7
7
  #
8
- # @param target [#state] an instance of a model that includes `Hyrax::Suppressible`
8
+ # @param target [#state] an instance of a model with a +#state+ property;
9
+ # e.g. a {Hyrax::Work}
9
10
  #
10
- # @return [RDF::Vocabulary::Term] the Fedora Resource Status 'inactive' term
11
+ # @return [RDF::URI] the Fedora Resource Status 'inactive' term
12
+ # @see Hyrax::ResourceStatus
11
13
  module DeactivateObject
12
14
  def self.call(target:, **)
13
- target.state = Vocab::FedoraResourceStatus.inactive
15
+ target.state = Hyrax::ResourceStatus::INACTIVE
14
16
  end
15
17
  end
16
18
  end
@@ -9,13 +9,17 @@ module Hyrax
9
9
  end
10
10
 
11
11
  def message
12
- I18n.t('hyrax.notifications.workflow.deposited.message', title: title, link: (link_to work_id, document_path),
13
- user: user.user_key, comment: comment)
12
+ I18n.t('hyrax.notifications.workflow.deposited.message',
13
+ title: title,
14
+ link: (link_to work_id, document_path),
15
+ user: user.user_key,
16
+ comment: comment)
14
17
  end
15
18
 
16
19
  def users_to_notify
17
- user_key = Hyrax.query_service.find_by_alternate_identifier(alternate_identifier: work_id).depositor
18
- super << ::User.find_by(email: user_key)
20
+ user_key = @entity.proxy_for.depositor
21
+
22
+ super << ::User.find_by_user_key(user_key)
19
23
  end
20
24
  end
21
25
  end
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
  module Hyrax
3
3
  module Workflow
4
+ ##
4
5
  # This is a built in function for workflow, so that a workflow action can be created that
5
6
  # grants the creator the ability to alter it.
6
7
  module GrantEditToDepositor
@@ -8,11 +9,14 @@ module Hyrax
8
9
  # @return void
9
10
  def self.call(target:, **)
10
11
  return true unless target.try(:depositor)
11
- target.edit_users = target.edit_users.to_a + Array.wrap(target.depositor) # += works in Ruby 2.6+
12
- target.try(:permission_manager)&.acl&.save
12
+
13
+ model = target.try(:model) || target # get the model if target is a ChangeSet
14
+ model.edit_users = model.edit_users.to_a + Array.wrap(target.depositor) # += works in Ruby 2.6+
15
+ model.try(:permission_manager)&.acl&.save
16
+
13
17
  # If there are a lot of members, granting access to each could take a
14
18
  # long time. Do this work in the background.
15
- GrantEditToMembersJob.perform_later(target, target.depositor)
19
+ GrantEditToMembersJob.perform_later(model, target.depositor)
16
20
  end
17
21
  end
18
22
  end
@@ -1,16 +1,23 @@
1
1
  # frozen_string_literal: true
2
2
  module Hyrax
3
3
  module Workflow
4
+ ##
4
5
  # This is a built in function for workflow, so that a workflow action can be created that
5
6
  # grants the creator the ability to view their work.
6
7
  module GrantReadToDepositor
7
- # @param [#read_users=, #read_users] target (likely an ActiveRecord::Base) to which we are adding read_users for the depositor
8
+ # @param [#read_users=, #read_users] target to which we are adding read_users
9
+ # for the depositor
8
10
  # @return void
9
11
  def self.call(target:, **)
10
- target.read_users += [target.depositor]
12
+ return true unless target.try(:depositor)
13
+
14
+ model = target.try(:model) || target # get the model if target is a ChangeSet
15
+ model.read_users = model.read_users.to_a + Array.wrap(target.depositor) # += works in Ruby 2.6+
16
+ model.try(:permission_manager)&.acl&.save
17
+
11
18
  # If there are a lot of members, granting access to each could take a
12
19
  # long time. Do this work in the background.
13
- GrantReadToMembersJob.perform_later(target, target.depositor)
20
+ GrantReadToMembersJob.perform_later(model, target.depositor)
14
21
  end
15
22
  end
16
23
  end
@@ -1,14 +1,20 @@
1
1
  # frozen_string_literal: true
2
2
  module Hyrax
3
3
  module Workflow
4
+ ##
4
5
  # This is a built in function for workflow, so that a workflow action can be created that
5
6
  # removes the creators the ability to alter it.
6
7
  module RevokeEditFromDepositor
7
8
  def self.call(target:, **)
8
- target.edit_users -= [target.depositor]
9
+ return true unless target.try(:depositor)
10
+
11
+ model = target.try(:model) || target # get the model if target is a ChangeSet
12
+ model.edit_users = model.edit_users.to_a - Array.wrap(target.depositor)
13
+ model.try(:permission_manager)&.acl&.save
14
+
9
15
  # If there are a lot of members, revoking access from each could take a
10
16
  # long time. Do this work in the background.
11
- RevokeEditFromMembersJob.perform_later(target, target.depositor)
17
+ RevokeEditFromMembersJob.perform_later(model, target.depositor)
12
18
  end
13
19
  end
14
20
  end