hyrax 3.0.0.pre.rc4 → 3.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (271) hide show
  1. checksums.yaml +4 -4
  2. data/.circleci/config.yml +41 -8
  3. data/.dassie/Gemfile +10 -5
  4. data/.dassie/config/cable.yml +1 -1
  5. data/.dassie/config/environments/development.rb +2 -0
  6. data/.dassie/config/environments/production.rb +1 -1
  7. data/.dassie/config/initializers/hyrax.rb +5 -0
  8. data/.dassie/config/initializers/riiif.rb +22 -20
  9. data/.dassie/config/redis.yml +1 -0
  10. data/.dassie/config/role_map.yml +2 -0
  11. data/.dassie/db/seeds.rb +9 -1
  12. data/.dassie/package.json +3 -5
  13. data/.dockerignore +4 -0
  14. data/.env +1 -2
  15. data/.rubocop.yml +4 -0
  16. data/CONTAINERS.md +21 -1
  17. data/Dockerfile +46 -17
  18. data/Gemfile +21 -27
  19. data/app/actors/hyrax/actors/base_actor.rb +1 -1
  20. data/app/actors/hyrax/actors/create_with_remote_files_actor.rb +89 -41
  21. data/app/actors/hyrax/actors/create_with_remote_files_ordered_members_actor.rb +7 -42
  22. data/app/actors/hyrax/actors/file_actor.rb +4 -2
  23. data/app/actors/hyrax/actors/file_set_actor.rb +18 -11
  24. data/app/controllers/concerns/hyrax/collections_controller_behavior.rb +20 -8
  25. data/app/controllers/concerns/hyrax/embargoes_controller_behavior.rb +21 -9
  26. data/app/controllers/concerns/hyrax/leases_controller_behavior.rb +14 -5
  27. data/app/controllers/concerns/hyrax/works_controller_behavior.rb +38 -8
  28. data/app/controllers/hyrax/admin/permission_template_accesses_controller.rb +0 -4
  29. data/app/controllers/hyrax/admin/workflows_controller.rb +8 -2
  30. data/app/controllers/hyrax/dashboard/collection_members_controller.rb +13 -9
  31. data/app/controllers/hyrax/dashboard/collections_controller.rb +14 -14
  32. data/app/controllers/hyrax/file_sets_controller.rb +49 -13
  33. data/app/controllers/hyrax/permissions_controller.rb +3 -4
  34. data/app/controllers/hyrax/workflow_actions_controller.rb +3 -1
  35. data/app/forms/hyrax/forms/collection_form.rb +12 -6
  36. data/app/forms/hyrax/forms/dashboard/nest_collection_form.rb +24 -2
  37. data/app/forms/hyrax/forms/file_set_form.rb +46 -0
  38. data/app/forms/hyrax/forms/permission.rb +23 -0
  39. data/app/forms/hyrax/forms/permission_template_form.rb +8 -2
  40. data/app/forms/hyrax/forms/resource_form.rb +31 -13
  41. data/app/forms/hyrax/forms/work_form.rb +5 -2
  42. data/app/helpers/hyrax/batch_edits_helper.rb +3 -1
  43. data/app/helpers/hyrax/collections_helper.rb +88 -2
  44. data/app/helpers/hyrax/dashboard_helper_behavior.rb +16 -5
  45. data/app/helpers/hyrax/embargo_helper.rb +4 -0
  46. data/app/helpers/hyrax/file_set_helper.rb +25 -6
  47. data/app/helpers/hyrax/hyrax_helper_behavior.rb +8 -0
  48. data/app/helpers/hyrax/lease_helper.rb +4 -0
  49. data/app/helpers/hyrax/url_helper.rb +4 -1
  50. data/app/helpers/hyrax/work_form_helper.rb +53 -0
  51. data/app/indexers/hyrax/administrative_set_indexer.rb +18 -0
  52. data/app/indexers/hyrax/valkyrie_file_set_indexer.rb +118 -0
  53. data/app/indexers/hyrax/valkyrie_indexer.rb +10 -4
  54. data/app/indexers/hyrax/valkyrie_work_indexer.rb +3 -1
  55. data/app/inputs/controlled_vocabulary_input.rb +2 -5
  56. data/app/jobs/attach_files_to_work_job.rb +19 -10
  57. data/app/jobs/attach_files_to_work_with_ordered_members_job.rb +6 -5
  58. data/app/jobs/embargo_expiry_job.rb +7 -5
  59. data/app/jobs/file_set_attached_event_job.rb +6 -1
  60. data/app/jobs/ingest_local_file_job.rb +18 -2
  61. data/app/jobs/inherit_permissions_job.rb +9 -5
  62. data/app/jobs/lease_expiry_job.rb +6 -4
  63. data/app/models/admin_set.rb +6 -25
  64. data/app/models/collection_branding_info.rb +25 -9
  65. data/app/models/concerns/hyrax/ability.rb +14 -1
  66. data/app/models/concerns/hyrax/collection_behavior.rb +17 -44
  67. data/app/models/concerns/hyrax/embargoable.rb +24 -0
  68. data/app/models/concerns/hyrax/file_set/characterization.rb +18 -12
  69. data/app/models/concerns/hyrax/solr_document_behavior.rb +9 -46
  70. data/app/models/concerns/hyrax/suppressible.rb +5 -0
  71. data/app/models/concerns/hyrax/user.rb +9 -3
  72. data/app/models/concerns/hyrax/work_behavior.rb +1 -1
  73. data/app/models/hyrax/file_set.rb +7 -0
  74. data/app/models/hyrax/pcdm_collection.rb +1 -0
  75. data/app/models/hyrax/permission_template.rb +98 -12
  76. data/app/models/hyrax/virus_scanner.rb +27 -18
  77. data/app/models/hyrax/work.rb +2 -0
  78. data/app/models/job_io_wrapper.rb +1 -1
  79. data/app/models/sipity/agent.rb +1 -0
  80. data/app/models/sipity/entity.rb +30 -8
  81. data/app/models/sipity/workflow.rb +1 -0
  82. data/app/models/sipity.rb +42 -0
  83. data/app/presenters/hyrax/admin_set_options_presenter.rb +12 -8
  84. data/app/presenters/hyrax/admin_set_presenter.rb +5 -1
  85. data/app/presenters/hyrax/admin_set_selection_presenter.rb +116 -0
  86. data/app/presenters/hyrax/collection_presenter.rb +41 -20
  87. data/app/presenters/hyrax/file_set_presenter.rb +6 -1
  88. data/app/presenters/hyrax/file_usage.rb +3 -2
  89. data/app/presenters/hyrax/pcdm_member_presenter_factory.rb +119 -0
  90. data/app/presenters/hyrax/stats_usage_presenter.rb +2 -1
  91. data/app/presenters/hyrax/trophy_presenter.rb +33 -4
  92. data/app/presenters/hyrax/user_profile_presenter.rb +11 -1
  93. data/app/presenters/hyrax/version_list_presenter.rb +19 -0
  94. data/app/presenters/hyrax/version_presenter.rb +3 -2
  95. data/app/presenters/hyrax/work_show_presenter.rb +30 -5
  96. data/app/presenters/hyrax/work_usage.rb +5 -3
  97. data/app/renderers/hyrax/renderers/attribute_renderer.rb +10 -2
  98. data/app/search_builders/hyrax/admin_set_search_builder.rb +1 -1
  99. data/app/search_builders/hyrax/collection_member_search_builder.rb +6 -1
  100. data/app/search_builders/hyrax/my/collections_search_builder.rb +2 -2
  101. data/app/search_builders/hyrax/nested_collections_parent_search_builder.rb +1 -1
  102. data/app/search_builders/hyrax/single_collection_search_builder.rb +1 -1
  103. data/app/services/hyrax/access_control_list.rb +1 -1
  104. data/app/services/hyrax/adapters/nesting_index_adapter.rb +1 -1
  105. data/app/services/hyrax/admin_set_create_service.rb +3 -1
  106. data/app/services/hyrax/collections/collection_member_search_service.rb +72 -0
  107. data/app/services/hyrax/collections/collection_member_service.rb +112 -27
  108. data/app/services/hyrax/collections/migration_service.rb +4 -2
  109. data/app/services/hyrax/collections/nested_collection_persistence_service.rb +12 -13
  110. data/app/services/hyrax/collections/nested_collection_query_service.rb +2 -0
  111. data/app/services/hyrax/collections/permissions_create_service.rb +6 -4
  112. data/app/services/hyrax/contextual_path.rb +24 -1
  113. data/app/services/hyrax/custom_queries/find_file_metadata.rb +7 -5
  114. data/app/services/hyrax/custom_queries/navigators/parent_collections_navigator.rb +46 -0
  115. data/app/services/hyrax/edit_permissions_service.rb +74 -41
  116. data/app/services/hyrax/embargo_manager.rb +1 -1
  117. data/app/services/hyrax/find_objects_via_solr_service.rb +31 -0
  118. data/app/services/hyrax/graph_exporter.rb +1 -1
  119. data/app/services/hyrax/listeners/member_cleanup_listener.rb +26 -0
  120. data/app/services/hyrax/listeners/metadata_index_listener.rb +18 -1
  121. data/app/services/hyrax/listeners/object_lifecycle_listener.rb +1 -1
  122. data/app/services/hyrax/listeners/trophy_cleanup_listener.rb +17 -0
  123. data/app/services/hyrax/listeners.rb +2 -0
  124. data/app/services/hyrax/multiple_membership_checker.rb +53 -29
  125. data/app/services/hyrax/persist_derivatives.rb +3 -1
  126. data/app/services/hyrax/resource_status.rb +7 -0
  127. data/app/services/hyrax/search_service.rb +4 -2
  128. data/app/services/hyrax/solr_query_builder_service.rb +45 -8
  129. data/app/services/hyrax/solr_query_service.rb +224 -0
  130. data/app/services/hyrax/solr_service.rb +8 -1
  131. data/app/services/hyrax/statistics/depositors/summary.rb +2 -1
  132. data/app/services/hyrax/thumbnail_path_service.rb +1 -1
  133. data/app/services/hyrax/versioning_service.rb +1 -1
  134. data/app/services/hyrax/visibility_intention.rb +20 -2
  135. data/app/services/hyrax/visibility_propagator.rb +30 -1
  136. data/app/services/hyrax/work_uploads_handler.rb +22 -4
  137. data/app/services/hyrax/workflow/actionable_objects.rb +70 -0
  138. data/app/services/hyrax/workflow/object_in_workflow_decorator.rb +31 -0
  139. data/app/services/hyrax/workflow/status_list_service.rb +43 -13
  140. data/app/views/hyrax/admin/admin_sets/_show_document_list_row.html.erb +1 -1
  141. data/app/views/hyrax/base/_form_child_work_relationships.html.erb +1 -1
  142. data/app/views/hyrax/base/_form_relationships.html.erb +1 -2
  143. data/app/views/hyrax/base/_form_rendering.html.erb +1 -1
  144. data/app/views/hyrax/base/_form_representative.html.erb +1 -1
  145. data/app/views/hyrax/base/_form_share.html.erb +1 -5
  146. data/app/views/hyrax/base/_form_thumbnail.html.erb +1 -1
  147. data/app/views/hyrax/base/_form_visibility_error.html.erb +2 -0
  148. data/app/views/hyrax/base/_guts4form.html.erb +3 -3
  149. data/app/views/hyrax/base/_representative_media.html.erb +1 -1
  150. data/app/views/hyrax/base/_show_actions.html.erb +2 -2
  151. data/app/views/hyrax/base/_work_button_row.html.erb +1 -1
  152. data/app/views/hyrax/base/_workflow_actions.html.erb +1 -1
  153. data/app/views/hyrax/batch_edits/edit.html.erb +2 -2
  154. data/app/views/hyrax/batch_uploads/_form.html.erb +1 -1
  155. data/app/views/hyrax/collections/_list_collections.html.erb +1 -1
  156. data/app/views/hyrax/collections/_search_form.html.erb +1 -1
  157. data/app/views/hyrax/collections/show.html.erb +1 -1
  158. data/app/views/hyrax/dashboard/collections/_form.html.erb +3 -3
  159. data/app/views/hyrax/dashboard/collections/_form_branding.html.erb +1 -1
  160. data/app/views/hyrax/dashboard/collections/_list_collections.html.erb +1 -1
  161. data/app/views/hyrax/dashboard/collections/edit.html.erb +4 -2
  162. data/app/views/hyrax/dashboard/collections/new.html.erb +4 -2
  163. data/app/views/hyrax/dashboard/collections/show.html.erb +1 -1
  164. data/app/views/hyrax/file_sets/_actions.html.erb +10 -0
  165. data/app/views/hyrax/file_sets/edit.html.erb +1 -1
  166. data/app/views/hyrax/file_sets/media_display/_audio.html.erb +1 -1
  167. data/app/views/hyrax/file_sets/media_display/_default.html.erb +1 -1
  168. data/app/views/hyrax/file_sets/media_display/_image.html.erb +1 -1
  169. data/app/views/hyrax/file_sets/media_display/_office_document.html.erb +1 -1
  170. data/app/views/hyrax/file_sets/media_display/_pdf.html.erb +1 -1
  171. data/app/views/hyrax/file_sets/media_display/_video.html.erb +1 -1
  172. data/app/views/hyrax/file_sets/show.html.erb +1 -1
  173. data/app/views/hyrax/my/_admin_set_action_menu.html.erb +0 -11
  174. data/app/views/hyrax/my/_collection_action_menu.html.erb +1 -2
  175. data/app/views/hyrax/my/collections/_list_collections.html.erb +1 -1
  176. data/app/views/hyrax/my/collections/_modal_add_subcollection.html.erb +3 -5
  177. data/app/views/hyrax/stats/file.html.erb +1 -1
  178. data/app/views/hyrax/stats/work.html.erb +1 -1
  179. data/app/views/hyrax/uploads/_js_templates.html.erb +4 -4
  180. data/app/views/hyrax/uploads/_js_templates_versioning.html.erb +4 -4
  181. data/app/views/hyrax/users/_contributions.html.erb +1 -1
  182. data/app/views/hyrax/users/_profile_tabs.html.erb +2 -2
  183. data/app/views/hyrax/users/_search_form.html.erb +1 -1
  184. data/app/views/hyrax/users/_user.html.erb +1 -1
  185. data/app/views/hyrax/users/_user_info.html.erb +9 -9
  186. data/bin/db-migrate-seed.sh +6 -2
  187. data/bin/hyrax-entrypoint.sh +0 -14
  188. data/bin/solrcloud-assign-configset.sh +35 -0
  189. data/bin/solrcloud-upload-configset.sh +42 -0
  190. data/chart/hyrax/Chart.yaml +12 -8
  191. data/chart/hyrax/README.md +94 -11
  192. data/chart/hyrax/templates/NOTES.txt +1 -1
  193. data/chart/hyrax/templates/_helpers.tpl +98 -0
  194. data/chart/hyrax/templates/branding-pvc.yaml +14 -0
  195. data/chart/hyrax/templates/configmap-env.yaml +21 -11
  196. data/chart/hyrax/templates/cron-embargo.yaml +24 -0
  197. data/chart/hyrax/templates/cron-lease.yaml +24 -0
  198. data/chart/hyrax/templates/deployment-worker.yaml +129 -0
  199. data/chart/hyrax/templates/deployment.yaml +125 -4
  200. data/chart/hyrax/templates/derivatives-pvc.yaml +14 -0
  201. data/chart/hyrax/templates/ingress.yaml +13 -4
  202. data/chart/hyrax/templates/secrets.yaml +12 -2
  203. data/chart/hyrax/templates/uploads-pvc.yaml +14 -0
  204. data/chart/hyrax/values.yaml +186 -2
  205. data/config/brakeman.ignore +2 -2
  206. data/config/features.rb +47 -43
  207. data/config/initializers/listeners.rb +4 -0
  208. data/config/initializers/valkryrie_storage.rb +7 -0
  209. data/config/locales/hyrax.de.yml +1 -1
  210. data/config/locales/hyrax.en.yml +1 -1
  211. data/config/locales/hyrax.es.yml +1 -1
  212. data/config/locales/hyrax.fr.yml +1 -1
  213. data/config/locales/hyrax.it.yml +1 -1
  214. data/config/locales/hyrax.pt-BR.yml +1 -1
  215. data/config/locales/hyrax.zh.yml +1 -1
  216. data/docker-compose.yml +39 -8
  217. data/documentation/developing-your-hyrax-based-app.md +4 -4
  218. data/documentation/legacyREADME.md +3 -3
  219. data/lib/generators/hyrax/templates/config/initializers/hyrax.rb +5 -0
  220. data/lib/generators/hyrax/templates/config/initializers/riiif.rb +22 -20
  221. data/lib/hyrax/active_fedora_dummy_model.rb +62 -0
  222. data/lib/hyrax/configuration.rb +28 -0
  223. data/lib/hyrax/engine.rb +3 -1
  224. data/lib/hyrax/errors.rb +2 -0
  225. data/lib/hyrax/resource_name.rb +1 -0
  226. data/lib/hyrax/specs/capybara.rb +5 -3
  227. data/lib/hyrax/specs/shared_specs/valkyrie_storage_versions.rb +9 -0
  228. data/lib/hyrax/transactions/container.rb +32 -1
  229. data/lib/hyrax/transactions/file_set_destroy.rb +21 -0
  230. data/lib/hyrax/transactions/steps/add_file_sets.rb +3 -2
  231. data/lib/hyrax/transactions/steps/add_to_parent.rb +36 -0
  232. data/lib/hyrax/transactions/steps/delete_resource.rb +38 -0
  233. data/lib/hyrax/transactions/steps/destroy_work.rb +1 -0
  234. data/lib/hyrax/transactions/steps/remove_file_set_from_work.rb +47 -0
  235. data/lib/hyrax/transactions/work_create.rb +2 -1
  236. data/lib/hyrax/transactions/work_destroy.rb +20 -0
  237. data/lib/hyrax/valkyrie_can_can_adapter.rb +3 -0
  238. data/lib/hyrax/valkyrie_simple_path_generator.rb +20 -0
  239. data/lib/hyrax/version.rb +1 -1
  240. data/lib/hyrax.rb +9 -0
  241. data/lib/tasks/collection_type_global_id.rake +1 -1
  242. data/lib/tasks/embargo_lease.rake +27 -0
  243. data/lib/tasks/regenerate_derivatives.rake +12 -0
  244. data/lib/wings/active_fedora_converter/default_work.rb +19 -0
  245. data/lib/wings/attribute_transformer.rb +29 -19
  246. data/lib/wings/converter_value_mapper.rb +2 -2
  247. data/lib/wings/model_transformer.rb +21 -20
  248. data/lib/wings/orm_converter.rb +42 -23
  249. data/lib/wings/setup.rb +2 -0
  250. data/lib/wings/valkyrie/persister.rb +8 -5
  251. data/lib/wings/valkyrie/query_service.rb +96 -41
  252. data/lib/wings/valkyrie/storage.rb +56 -1
  253. data/lib/wings.rb +0 -21
  254. data/template.rb +1 -1
  255. metadata +41 -21
  256. data/chart/fcrepo/.gitignore +0 -2
  257. data/chart/fcrepo/.helmignore +0 -23
  258. data/chart/fcrepo/Chart.yaml +0 -11
  259. data/chart/fcrepo/README.md +0 -50
  260. data/chart/fcrepo/templates/NOTES.txt +0 -21
  261. data/chart/fcrepo/templates/_helpers.tpl +0 -68
  262. data/chart/fcrepo/templates/configmap-env.yaml +0 -19
  263. data/chart/fcrepo/templates/deployment.yaml +0 -109
  264. data/chart/fcrepo/templates/ingress.yaml +0 -41
  265. data/chart/fcrepo/templates/pvc.yaml +0 -20
  266. data/chart/fcrepo/templates/secret.yaml +0 -12
  267. data/chart/fcrepo/templates/service.yaml +0 -15
  268. data/chart/fcrepo/templates/serviceaccount.yaml +0 -12
  269. data/chart/fcrepo/templates/tests/test-connection.yaml +0 -15
  270. data/chart/fcrepo/values.yaml +0 -79
  271. data/chart/hyrax/templates/fcrepo-secret.yaml +0 -13
@@ -1,16 +1,25 @@
1
1
  # frozen_string_literal: true
2
2
  module Hyrax
3
3
  class UserProfilePresenter
4
+ ##
5
+ # @param user [::User]
6
+ # @param ability [::Ability]
4
7
  def initialize(user, ability)
5
8
  @user = user
6
9
  @ability = ability
7
10
  end
8
11
 
12
+ ##
13
+ # @!attribute [r] ability
14
+ # @return [::Ability]
15
+ # @!attribute [r] user
16
+ # @return [::User]
9
17
  attr_reader :user, :ability
10
18
 
11
19
  delegate :name, to: :user
12
20
 
13
- # @return true if the presenter is for the logged in user
21
+ ##
22
+ # @return [Boolean] true if the presenter is for the logged in user
14
23
  def current_user?
15
24
  user == ability.current_user
16
25
  end
@@ -23,6 +32,7 @@ module Hyrax
23
32
  end
24
33
  end
25
34
 
35
+ ##
26
36
  # @return [Array<TrophyPresenter>] list of TrophyPresenters for this profile.
27
37
  def trophies
28
38
  @trophies ||= Hyrax::TrophyPresenter.find_by_user(user)
@@ -1,10 +1,29 @@
1
1
  # frozen_string_literal: true
2
2
  module Hyrax
3
+ ##
4
+ # @api public
3
5
  class VersionListPresenter
6
+ include Enumerable
7
+
8
+ ##
9
+ # @param version_list [Array<#created>]
4
10
  def initialize(version_list)
5
11
  @raw_list = version_list
6
12
  end
7
13
 
14
+ ##
15
+ # @param [Object] an object representing the File Set
16
+ #
17
+ # @return [Enumerable<Hyrax::VersionPresenter>] an enumerable of presenters
18
+ # for the relevant file versions.
19
+ #
20
+ # @raise [ArgumentError] if we can't build an enu
21
+ def self.for(file_set:)
22
+ new(file_set.original_file&.versions&.all.to_a)
23
+ rescue NoMethodError
24
+ raise ArgumentError
25
+ end
26
+
8
27
  delegate :each, to: :wrapped_list
9
28
 
10
29
  private
@@ -20,8 +20,9 @@ module Hyrax
20
20
  end
21
21
 
22
22
  def committer
23
- vc = Hyrax::VersionCommitter.where(version_id: @version.uri)
24
- vc.empty? ? nil : vc.first.committer_login
23
+ Hyrax::VersionCommitter
24
+ .find_by(version_id: @version.uri)
25
+ &.committer_login
25
26
  end
26
27
  end
27
28
  end
@@ -94,7 +94,7 @@ module Hyrax
94
94
  return nil if representative_id.blank?
95
95
  @representative_presenter ||=
96
96
  begin
97
- result = member_presenters_for([representative_id]).first
97
+ result = member_presenters([representative_id]).first
98
98
  return nil if result.try(:id) == id
99
99
  result.try(:representative_presenter) || result
100
100
  end
@@ -132,8 +132,13 @@ module Hyrax
132
132
  graph.dump(:ttl)
133
133
  end
134
134
 
135
+ ##
136
+ # @deprecated use `::Ability.can?(:edit, presenter)`. Hyrax views calling
137
+ # presenter {#editor} methods will continue to call them until Hyrax
138
+ # 4.0.0. The deprecation time horizon for the presenter methods themselves
139
+ # is 5.0.0.
135
140
  def editor?
136
- current_ability.can?(:edit, solr_document)
141
+ current_ability.can?(:edit, self)
137
142
  end
138
143
 
139
144
  def tweeter
@@ -181,9 +186,13 @@ module Hyrax
181
186
  paginated_item_list(page_array: authorized_item_ids)
182
187
  end
183
188
 
189
+ ##
190
+ # @deprecated use `#member_presenters(ids)` instead
191
+ #
184
192
  # @param [Array<String>] ids a list of ids to build presenters for
185
193
  # @return [Array<presenter_class>] presenters for the array of ids (not filtered by class)
186
194
  def member_presenters_for(an_array_of_ids)
195
+ Deprecation.warn("Use `#member_presenters` instead.")
187
196
  member_presenters(an_array_of_ids)
188
197
  end
189
198
 
@@ -219,9 +228,25 @@ module Hyrax
219
228
  end
220
229
  end
221
230
 
222
- # determine if the user can add this work to a collection
223
- # @param collections [Array<::Collection>] list of collections to which this user can deposit
224
- # @return true if the user can deposit to at least one collection OR if the user can create a collection; otherwise, false
231
+ ##
232
+ # @return [Integer]
233
+ def member_count
234
+ @member_count ||= member_presenters.count
235
+ end
236
+
237
+ ##
238
+ # Given a set of collections, which the caller asserts the current ability
239
+ # can deposit to, decide whether to display actions to add this work to a
240
+ # collection.
241
+ #
242
+ # By default, this returns `true` if any collections are passed in OR the
243
+ # current ability can create a collection.
244
+ #
245
+ # @param collections [Enumerable<::Collection>, nil] list of collections to
246
+ # which the current ability can deposit
247
+ #
248
+ # @return [Boolean] a flag indicating whether to display collection deposit
249
+ # options.
225
250
  def show_deposit_for?(collections:)
226
251
  collections.present? || current_ability.can?(:create_any, ::Collection)
227
252
  end
@@ -1,8 +1,10 @@
1
1
  # frozen_string_literal: true
2
- # class WorkUsage follows the model established by FileUsage
3
- # Called by the stats controller, it finds cached work pageview data,
4
- # and prepares it for visualization in /app/views/stats/work.html.erb
2
+
5
3
  module Hyrax
4
+ # Follows the model established by {FileUsage}.
5
+ #
6
+ # Called by the stats controller, it finds cached work pageview data,
7
+ # and prepares it for visualization in /app/views/stats/work.html.erb
6
8
  class WorkUsage < StatsUsagePresenter
7
9
  def initialize(id)
8
10
  self.model = Hyrax::WorkRelation.new.find(id)
@@ -11,12 +11,14 @@ module Hyrax
11
11
 
12
12
  attr_reader :field, :values, :options
13
13
 
14
+ ##
14
15
  # @param [Symbol] field
15
16
  # @param [Array] values
16
17
  # @param [Hash] options
17
18
  # @option options [String] :label The field label to render
18
19
  # @option options [String] :include_empty Do we render if if the values are empty?
19
20
  # @option options [String] :work_type Used for some I18n logic
21
+ # @option options [Boolean] :sort sort the values with +Array#sort+ if truthy
20
22
  def initialize(field, values, options = {})
21
23
  @field = field
22
24
  @values = values
@@ -31,7 +33,10 @@ module Hyrax
31
33
 
32
34
  attributes = microdata_object_attributes(field).merge(class: "attribute attribute-#{field}")
33
35
 
34
- markup += Array(values).map do |value|
36
+ values_array = Array(values)
37
+ values_array = values_array.sort if options[:sort]
38
+
39
+ markup += values_array.map do |value|
35
40
  "<li#{html_attributes(attributes)}>#{attribute_value_to_html(value.to_s)}</li>"
36
41
  end.join
37
42
 
@@ -48,7 +53,10 @@ module Hyrax
48
53
 
49
54
  attributes = microdata_object_attributes(field).merge(class: "attribute attribute-#{field}")
50
55
 
51
- markup += Array(values).map do |value|
56
+ values_array = Array(values)
57
+ values_array.sort! if options[:sort]
58
+
59
+ markup += values_array.map do |value|
52
60
  "<li#{html_attributes(attributes)}>#{attribute_value_to_html(value.to_s)}</li>"
53
61
  end.join
54
62
  markup += %(</ul></dd>)
@@ -14,7 +14,7 @@ module Hyrax
14
14
 
15
15
  # This overrides the models in FilterByType
16
16
  def models
17
- [::AdminSet]
17
+ [::AdminSet, Hyrax::AdministrativeSet]
18
18
  end
19
19
 
20
20
  # Overrides Hydra::AccessControlsEnforcement
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
  module Hyrax
3
3
  # This search builder requires that a accessor named "collection" exists in the scope
4
- class CollectionMemberSearchBuilder < ::SearchBuilder
4
+ class CollectionMemberSearchBuilder < ::Hyrax::CollectionSearchBuilder
5
5
  include Hyrax::FilterByType
6
6
  attr_writer :collection, :search_includes_models
7
7
 
@@ -41,6 +41,11 @@ module Hyrax
41
41
  solr_parameters[:fq] << "#{collection_membership_field}:#{collection.id}"
42
42
  end
43
43
 
44
+ # This overrides the models in FilterByType
45
+ def models
46
+ work_classes + collection_classes
47
+ end
48
+
44
49
  private
45
50
 
46
51
  def only_works?
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
  # Added to allow for the My controller to show only things I have edit access to
3
- class Hyrax::My::CollectionsSearchBuilder < ::SearchBuilder
3
+ class Hyrax::My::CollectionsSearchBuilder < ::Hyrax::CollectionSearchBuilder
4
4
  include Hyrax::My::SearchBuilderBehavior
5
5
  include Hyrax::FilterByType
6
6
 
@@ -21,6 +21,6 @@ class Hyrax::My::CollectionsSearchBuilder < ::SearchBuilder
21
21
  # This overrides the models in FilterByType
22
22
  # @return [Array<Class>] a list of classes to include
23
23
  def models
24
- [::AdminSet, ::Collection]
24
+ [::AdminSet, ::Collection, Hyrax::AdministrativeSet]
25
25
  end
26
26
  end
@@ -2,7 +2,7 @@
2
2
  module Hyrax
3
3
  ##
4
4
  # Searches for all collections that are parents of a given collection.
5
- class NestedCollectionsParentSearchBuilder < ::SearchBuilder
5
+ class NestedCollectionsParentSearchBuilder < ::Hyrax::CollectionSearchBuilder
6
6
  include Hyrax::FilterByType
7
7
  attr_reader :child, :page, :limit
8
8
 
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
  module Hyrax
3
- class SingleCollectionSearchBuilder < ::SearchBuilder
3
+ class SingleCollectionSearchBuilder < ::Hyrax::CollectionSearchBuilder
4
4
  include SingleResult
5
5
  end
6
6
  end
@@ -14,7 +14,7 @@ module Hyrax
14
14
  when AccessControlList
15
15
  obj
16
16
  else
17
- AccessControlList.new(resource: obj)
17
+ obj.try(:permission_manager)&.acl || AccessControlList.new(resource: obj)
18
18
  end
19
19
  end
20
20
 
@@ -56,7 +56,7 @@ module Hyrax
56
56
  # @see Samvera::NestingIndexer.reindex_all!(extent: FULL_REINDEX)
57
57
  def self.each_perservation_document_id_and_parent_ids(&block) # rubocop:disable Lint/UnusedMethodArgument
58
58
  ActiveFedora::Base.descendant_uris(ActiveFedora.fedora.base_uri, exclude_uri: true).each do |uri|
59
- id = Hyrax::Base.uri_to_id(uri)
59
+ id = Hyrax.config.translate_uri_to_id.call(uri)
60
60
  object = ActiveFedora::Base.find(id)
61
61
  parent_ids = object.try(:member_of_collection_ids) || []
62
62
 
@@ -81,9 +81,11 @@ module Hyrax
81
81
  ::Ability.admin_group_name
82
82
  end
83
83
 
84
+ ##
85
+ # @return [PermissionTemplate]
84
86
  def create_permission_template
85
87
  permission_template = PermissionTemplate.create!(source_id: admin_set.id, access_grants_attributes: access_grants_attributes)
86
- admin_set.reset_access_controls!
88
+ permission_template.reset_access_controls_for(collection: admin_set)
87
89
  permission_template
88
90
  end
89
91
 
@@ -0,0 +1,72 @@
1
+ # frozen_string_literal: true
2
+ module Hyrax
3
+ module Collections
4
+ ##
5
+ # Retrieves collection members
6
+ class CollectionMemberSearchService < Hyrax::SearchService
7
+ ##
8
+ # @param scope [#repository] Typically a controller object which responds to :repository
9
+ # @param [::Collection] collection
10
+ # @param [ActionController::Parameters] params the query params
11
+ # @param [ActionController::Parameters] user_params
12
+ # @param [::Ability] current_ability
13
+ # @param [Class] search_builder_class a {::SearchBuilder}
14
+ def initialize(scope:, collection:, params:, user_params: nil, current_ability: nil, search_builder_class: Hyrax::CollectionMemberSearchBuilder) # rubocop:disable Metrics/ParameterLists
15
+ super(
16
+ config: scope.blacklight_config,
17
+ user_params: user_params || params,
18
+ collection: collection,
19
+ scope: scope,
20
+ current_ability: current_ability || scope.current_ability,
21
+ search_builder_class: search_builder_class
22
+ )
23
+ end
24
+
25
+ ##
26
+ # @api public
27
+ #
28
+ # Collections which are members of the given collection
29
+ #
30
+ # @return [Blacklight::Solr::Response] (up to 50 solr documents)
31
+ def available_member_subcollections
32
+ response, _docs = search_results do |builder|
33
+ # To differentiate current page for works vs subcollections, we have to use a sub_collection_page
34
+ # param. Map this to the page param before querying for subcollections, if it's present
35
+ builder.page(user_params[:sub_collection_page])
36
+ builder.search_includes_models = :collections
37
+ builder
38
+ end
39
+ response
40
+ end
41
+
42
+ ##
43
+ # @api public
44
+ #
45
+ # Works which are members of the given collection
46
+ #
47
+ # @return [Blacklight::Solr::Response]
48
+ def available_member_works
49
+ response, _docs = search_results do |builder|
50
+ builder.search_includes_models = :works
51
+ builder
52
+ end
53
+ response
54
+ end
55
+
56
+ ##
57
+ # @api public
58
+ #
59
+ # Work ids of the works which are members of the given collection
60
+ #
61
+ # @return [Blacklight::Solr::Response]
62
+ def available_member_work_ids
63
+ response, _docs = search_results do |builder|
64
+ builder.search_includes_models = :works
65
+ builder.merge(fl: 'id')
66
+ builder
67
+ end
68
+ response
69
+ end
70
+ end
71
+ end
72
+ end
@@ -3,7 +3,7 @@ module Hyrax
3
3
  module Collections
4
4
  ##
5
5
  # Retrieves collection members
6
- class CollectionMemberService < Hyrax::SearchService
6
+ class CollectionMemberService
7
7
  ##
8
8
  # @param scope [#repository] Typically a controller object which responds to :repository
9
9
  # @param [::Collection] collection
@@ -12,14 +12,14 @@ module Hyrax
12
12
  # @param [::Ability] current_ability
13
13
  # @param [Class] search_builder_class a {::SearchBuilder}
14
14
  def initialize(scope:, collection:, params:, user_params: nil, current_ability: nil, search_builder_class: Hyrax::CollectionMemberSearchBuilder) # rubocop:disable Metrics/ParameterLists
15
- super(
16
- config: scope.blacklight_config,
17
- user_params: user_params || params,
18
- collection: collection,
19
- scope: scope,
20
- current_ability: current_ability || scope.current_ability,
21
- search_builder_class: search_builder_class
22
- )
15
+ Deprecation.warn("'##{__method__}' will be removed in Hyrax 4.0. " \
16
+ "Instead, use the same method in 'Hyrax::Collections::CollectionMemberSearchService'.")
17
+ @member_search_service = Hyrax::Collections::CollectionMemberSearchService(scope: scope,
18
+ collection: collection,
19
+ params: params,
20
+ user_params: user_params,
21
+ current_ability: current_ability,
22
+ search_builder_class: search_builder_class)
23
23
  end
24
24
 
25
25
  ##
@@ -29,14 +29,9 @@ module Hyrax
29
29
  #
30
30
  # @return [Blacklight::Solr::Response] (up to 50 solr documents)
31
31
  def available_member_subcollections
32
- response, _docs = search_results do |builder|
33
- # To differentiate current page for works vs subcollections, we have to use a sub_collection_page
34
- # param. Map this to the page param before querying for subcollections, if it's present
35
- builder.page(user_params[:sub_collection_page])
36
- builder.search_includes_models = :collections
37
- builder
38
- end
39
- response
32
+ Deprecation.warn("'##{__method__}' will be removed in Hyrax 4.0. " \
33
+ "Instead, use the same method in 'Hyrax::Collections::CollectionMemberSearchService'.")
34
+ @member_search_service.available_member_subcollections
40
35
  end
41
36
 
42
37
  ##
@@ -46,11 +41,9 @@ module Hyrax
46
41
  #
47
42
  # @return [Blacklight::Solr::Response]
48
43
  def available_member_works
49
- response, _docs = search_results do |builder|
50
- builder.search_includes_models = :works
51
- builder
52
- end
53
- response
44
+ Deprecation.warn("'##{__method__}' will be removed in Hyrax 4.0. " \
45
+ "Instead, use the same method in 'Hyrax::Collections::CollectionMemberSearchService'.")
46
+ @member_search_service.available_member_works
54
47
  end
55
48
 
56
49
  ##
@@ -60,12 +53,104 @@ module Hyrax
60
53
  #
61
54
  # @return [Blacklight::Solr::Response]
62
55
  def available_member_work_ids
63
- response, _docs = search_results do |builder|
64
- builder.search_includes_models = :works
65
- builder.merge(fl: 'id')
66
- builder
56
+ Deprecation.warn("'##{__method__}' will be removed in Hyrax 4.0. " \
57
+ "Instead, use the same method in 'Hyrax::Collections::CollectionMemberSearchService'.")
58
+ @member_search_service.available_member_work_ids
59
+ end
60
+
61
+ class << self
62
+ # Check if a work or collection is already a member of a collection
63
+ # @param collection_id [Valkyrie::ID] the id of the parent collection
64
+ # @param member [Hyrax::Resource] the child collection and/or child work to check
65
+ # @return [Boolean] true if already in the member set; otherwise, false
66
+ def member?(collection_id:, member:)
67
+ member.member_of_collection_ids.include? collection_id
68
+ end
69
+
70
+ # Add works and/or collections as members of a collection
71
+ # @param collection_id [Valkyrie::ID] the id of the parent collection
72
+ # @param new_member_ids [Enumerable<Valkyrie::ID>] the ids of the new child collections and/or child works
73
+ # @return [Enumerable<Hyrax::Resource>] updated member resources
74
+ def add_members_by_ids(collection_id:, new_member_ids:, user:)
75
+ new_members = Hyrax.query_service.find_many_by_ids(ids: new_member_ids)
76
+ add_members(collection_id: collection_id, new_members: new_members, user: user)
77
+ end
78
+
79
+ # Add works and/or collections as members of a collection
80
+ # @param collection_id [Valkyrie::ID] the id of the parent collection
81
+ # @param new_members [Enumerable<Hyrax::Resource>] the new child collections and/or child works
82
+ # @return [Enumerable<Hyrax::Resource>] updated member resources
83
+ def add_members(collection_id:, new_members:, user:)
84
+ messages = []
85
+ new_members.map do |new_member|
86
+ begin
87
+ add_member(collection_id: collection_id, new_member: new_member, user: user)
88
+ rescue Hyrax::SingleMembershipError => err
89
+ messages += [err.message]
90
+ end
91
+ end
92
+ raise Hyrax::SingleMembershipError, messages if messages.present?
93
+ end
94
+
95
+ # Add a work or collection as a member of a collection
96
+ # @param collection_id [Valkyrie::ID] the id of the parent collection
97
+ # @param new_member_id [Valkyrie::ID] the id of the new child collection or child work
98
+ # @return [Hyrax::Resource] updated member resource
99
+ def add_member_by_id(collection_id:, new_member_id:, user:)
100
+ new_member = Hyrax.query_service.find_by(id: new_member_id)
101
+ add_member(collection_id: collection_id, new_member: new_member, user: user)
102
+ end
103
+
104
+ # Add a work or collection as a member of a collection
105
+ # @param collection_id [Valkyrie::ID] the id of the parent collection
106
+ # @param new_member [Hyrax::Resource] the new child collection or child work
107
+ # @return [Hyrax::Resource] updated member resource
108
+ def add_member(collection_id:, new_member:, user:)
109
+ message = Hyrax::MultipleMembershipChecker.new(item: new_member).check(collection_ids: [collection_id], include_current_members: true)
110
+ raise Hyrax::SingleMembershipError, message if message.present?
111
+ new_member.member_of_collection_ids << collection_id # only populate this direction
112
+ new_member = Hyrax.persister.save(resource: new_member)
113
+ Hyrax.publisher.publish('object.metadata.updated', object: new_member, user: user)
114
+ new_member
115
+ end
116
+
117
+ # Remove collections and/or works from the members set of a collection
118
+ # @param collection_id [Valkyrie::ID] the id of the parent collection
119
+ # @param member_ids [Enumerable<Valkyrie::ID>] the ids of the child collections and/or child works to be removed
120
+ # @return [Enumerable<Hyrax::Resource>] updated member resources
121
+ def remove_members_by_ids(collection_id:, member_ids:, user:)
122
+ members = Hyrax.query_service.find_many_by_ids(ids: member_ids)
123
+ remove_members(collection_id: collection_id, members: members, user: user)
124
+ end
125
+
126
+ # Remove collections and/or works from the members set of a collection
127
+ # @param collection_id [Valkyrie::ID] the id of the parent collection
128
+ # @param members [Enumerable<Valkyrie::Resource>] the child collections and/or child works to be removed
129
+ # @return [Enumerable<Hyrax::Resource>] updated member resources
130
+ def remove_members(collection_id:, members:, user:)
131
+ members.map { |member| remove_member(collection_id: collection_id, member: member, user: user) }
132
+ end
133
+
134
+ # Remove collections and/or works from the members set of a collection
135
+ # @param collection_id [Valkyrie::ID] the id of the parent collection
136
+ # @param member_id [Valkyrie::ID] the id of the child collection or child work to be removed
137
+ # @return [Hyrax::Resource] updated member resource
138
+ def remove_member_by_id(collection_id:, member_id:, user:)
139
+ member = Hyrax.query_service.find_by(id: member_id)
140
+ remove_member(collection_id: collection_id, member: member, user: user)
141
+ end
142
+
143
+ # Remove a collection or work from the members set of a collection, also removing the inverse relationship
144
+ # @param collection_id [Valkyrie::ID] the id of the parent collection
145
+ # @param member [Hyrax::Resource] the child collection or child work to be removed
146
+ # @return [Hyrax::Resource] updated member resource
147
+ def remove_member(collection_id:, member:, user:)
148
+ return member unless member?(collection_id: collection_id, member: member)
149
+ member.member_of_collection_ids.delete(collection_id)
150
+ member = Hyrax.persister.save(resource: member)
151
+ Hyrax.publisher.publish('object.metadata.updated', object: member, user: user)
152
+ member
67
153
  end
68
- response
69
154
  end
70
155
  end
71
156
  end