hyrax 5.0.0.rc2 → 5.0.0.rc3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (307) hide show
  1. checksums.yaml +4 -4
  2. data/.circleci/config.yml +14 -0
  3. data/.dassie/app/listeners/hyrax_listener.rb +81 -0
  4. data/.dassie/config/environments/test.rb +0 -5
  5. data/.dassie/config/initializers/hyrax.rb +5 -0
  6. data/.dassie/config/initializers/publisher.rb +3 -0
  7. data/.dassie/config/initializers/riiif.rb +77 -0
  8. data/.gitignore +4 -0
  9. data/.koppie/.env +2 -2
  10. data/.koppie/app/forms/collection_resource_form.rb +1 -0
  11. data/.koppie/app/indexers/collection_resource_indexer.rb +1 -0
  12. data/.koppie/app/listeners/hyrax_listener.rb +81 -0
  13. data/.koppie/app/models/collection.rb +1 -1
  14. data/.koppie/app/models/collection_resource.rb +1 -0
  15. data/.koppie/config/analytics.yml +5 -5
  16. data/.koppie/config/initializers/publisher.rb +3 -0
  17. data/.koppie/config/initializers/riiif.rb +78 -0
  18. data/.koppie/config/metadata/collection_resource.yaml +8 -166
  19. data/.koppie/config/metadata/sample_metadata.yaml +4 -0
  20. data/CONTAINERS.md +39 -2
  21. data/Dockerfile +14 -11
  22. data/Gemfile +8 -7
  23. data/README.md +2 -0
  24. data/app/actors/hyrax/actors/base_actor.rb +6 -3
  25. data/app/actors/hyrax/actors/file_actor.rb +1 -1
  26. data/app/actors/hyrax/actors/lease_actor.rb +3 -6
  27. data/app/assets/javascripts/hyrax/save_work/uploaded_files.es6 +10 -2
  28. data/app/assets/stylesheets/hyrax/sidebar.scss +6 -1
  29. data/app/controllers/concerns/hyrax/collections_controller_behavior.rb +1 -1
  30. data/app/controllers/concerns/hyrax/local_file_downloads_controller_behavior.rb +12 -19
  31. data/app/controllers/concerns/hyrax/stream_file_downloads_controller_behavior.rb +54 -0
  32. data/app/controllers/concerns/hyrax/valkyrie_downloads_controller_behavior.rb +38 -9
  33. data/app/controllers/concerns/hyrax/works_controller_behavior.rb +19 -14
  34. data/app/controllers/hyrax/admin/admin_sets_controller.rb +2 -2
  35. data/app/controllers/hyrax/admin/analytics/work_reports_controller.rb +5 -5
  36. data/app/controllers/hyrax/dashboard/collections_controller.rb +2 -2
  37. data/app/controllers/hyrax/downloads_controller.rb +1 -0
  38. data/app/controllers/hyrax/file_sets_controller.rb +3 -2
  39. data/app/controllers/hyrax/my/collections_controller.rb +1 -1
  40. data/app/forms/concerns/hyrax/basic_metadata_form_fields_behavior.rb +1 -0
  41. data/app/forms/concerns/hyrax/contained_in_works_behavior.rb +24 -0
  42. data/app/forms/concerns/hyrax/deposit_agreement_behavior.rb +12 -0
  43. data/app/forms/concerns/hyrax/leaseability_behavior.rb +49 -0
  44. data/app/forms/concerns/hyrax/permission_behavior.rb +20 -0
  45. data/app/forms/hyrax/forms/administrative_set_form.rb +1 -5
  46. data/app/forms/hyrax/forms/collection_form.rb +19 -0
  47. data/app/forms/hyrax/forms/file_set_form.rb +5 -0
  48. data/app/forms/hyrax/forms/pcdm_collection_form.rb +1 -5
  49. data/app/forms/hyrax/forms/pcdm_object_form.rb +13 -22
  50. data/app/forms/hyrax/forms/resource_batch_edit_form.rb +7 -2
  51. data/app/forms/hyrax/forms/resource_form.rb +30 -100
  52. data/app/forms/hyrax/forms.rb +52 -0
  53. data/app/helpers/hyrax/hyrax_helper_behavior.rb +2 -0
  54. data/app/indexers/{hyrax → concerns/hyrax}/location_indexer.rb +1 -5
  55. data/app/indexers/{hyrax → concerns/hyrax}/permission_indexer.rb +2 -2
  56. data/app/indexers/{hyrax → concerns/hyrax}/visibility_indexer.rb +1 -1
  57. data/app/indexers/hyrax/administrative_set_indexer.rb +5 -17
  58. data/app/indexers/hyrax/indexers/administrative_set_indexer.rb +25 -0
  59. data/app/indexers/hyrax/indexers/file_set_indexer.rb +144 -0
  60. data/app/indexers/hyrax/indexers/pcdm_collection_indexer.rb +27 -0
  61. data/app/indexers/hyrax/indexers/pcdm_object_indexer.rb +72 -0
  62. data/app/indexers/hyrax/indexers/resource_indexer.rb +86 -0
  63. data/app/indexers/hyrax/indexers.rb +54 -0
  64. data/app/indexers/hyrax/pcdm_collection_indexer.rb +5 -18
  65. data/app/indexers/hyrax/valkyrie_collection_indexer.rb +6 -4
  66. data/app/indexers/hyrax/valkyrie_file_set_indexer.rb +5 -136
  67. data/app/indexers/hyrax/valkyrie_indexer.rb +8 -112
  68. data/app/indexers/hyrax/valkyrie_work_indexer.rb +5 -64
  69. data/app/indexers/hyrax/work_indexer.rb +1 -0
  70. data/app/jobs/create_work_job.rb +1 -0
  71. data/app/models/admin_set.rb +20 -1
  72. data/app/models/collection.rb +5 -0
  73. data/app/models/concerns/hyrax/ability/admin_set_ability.rb +13 -28
  74. data/app/models/concerns/hyrax/ability/collection_ability.rb +26 -28
  75. data/app/models/concerns/hyrax/ability/resource_ability.rb +19 -0
  76. data/app/models/concerns/hyrax/ability.rb +11 -9
  77. data/app/models/concerns/hyrax/collection_behavior.rb +8 -0
  78. data/app/models/concerns/hyrax/solr_document_behavior.rb +15 -5
  79. data/app/models/concerns/hyrax/work_behavior.rb +4 -0
  80. data/app/models/featured_work.rb +12 -4
  81. data/app/models/file_set.rb +5 -0
  82. data/app/models/hyrax/administrative_set.rb +1 -1
  83. data/app/models/hyrax/change_set.rb +2 -2
  84. data/app/models/hyrax/file_metadata.rb +34 -7
  85. data/app/models/hyrax/file_set.rb +2 -2
  86. data/app/models/hyrax/group.rb +9 -38
  87. data/app/models/hyrax/group_behavior.rb +58 -0
  88. data/app/models/hyrax/model_registry.rb +111 -0
  89. data/app/models/hyrax/pcdm_collection.rb +1 -7
  90. data/app/models/hyrax/resource.rb +66 -8
  91. data/app/models/hyrax/statistic.rb +1 -1
  92. data/app/models/hyrax/work.rb +1 -7
  93. data/app/presenters/hyrax/collapsable_section_presenter.rb +7 -3
  94. data/app/presenters/hyrax/file_set_presenter.rb +8 -6
  95. data/app/presenters/hyrax/lease_presenter.rb +4 -0
  96. data/app/presenters/hyrax/menu_presenter.rb +14 -2
  97. data/app/presenters/hyrax/pcdm_member_presenter_factory.rb +1 -1
  98. data/app/presenters/hyrax/version_list_presenter.rb +6 -4
  99. data/app/search_builders/hyrax/admin_set_search_builder.rb +1 -1
  100. data/app/search_builders/hyrax/catalog_search_builder.rb +2 -2
  101. data/app/search_builders/hyrax/dashboard/collections_search_builder.rb +5 -3
  102. data/app/search_builders/hyrax/exposed_models_relation.rb +1 -1
  103. data/app/search_builders/hyrax/file_set_search_builder.rb +1 -1
  104. data/app/search_builders/hyrax/filter_by_type.rb +3 -2
  105. data/app/search_builders/hyrax/member_with_files_search_builder.rb +1 -1
  106. data/app/search_builders/hyrax/my/collections_search_builder.rb +2 -2
  107. data/app/search_builders/hyrax/my/find_works_search_builder.rb +8 -3
  108. data/app/services/hyrax/access_control_list.rb +21 -4
  109. data/app/services/hyrax/action/create_valkyrie_work.rb +80 -0
  110. data/app/services/hyrax/admin_set_create_service.rb +7 -3
  111. data/app/services/hyrax/admin_set_service.rb +2 -2
  112. data/app/services/hyrax/collections/collection_member_search_service.rb +2 -0
  113. data/app/services/hyrax/collections/permissions_service.rb +27 -9
  114. data/app/services/hyrax/custom_queries/find_collections_by_type.rb +1 -1
  115. data/app/services/hyrax/custom_queries/find_file_metadata.rb +1 -1
  116. data/app/services/hyrax/custom_queries/navigators/find_files.rb +1 -1
  117. data/app/services/hyrax/custom_queries/navigators/parent_work_navigator.rb +1 -1
  118. data/app/services/hyrax/edit_permissions_service.rb +1 -1
  119. data/app/services/hyrax/embargo_manager.rb +1 -1
  120. data/app/services/hyrax/file_set_file_service.rb +21 -10
  121. data/app/services/hyrax/form_factory.rb +1 -1
  122. data/app/services/hyrax/lease_manager.rb +39 -16
  123. data/app/services/hyrax/lease_service.rb +12 -6
  124. data/app/services/hyrax/listeners/acl_index_listener.rb +1 -1
  125. data/app/services/hyrax/listeners/active_fedora_acl_index_listener.rb +1 -1
  126. data/app/services/hyrax/listeners/member_cleanup_listener.rb +15 -1
  127. data/app/services/hyrax/listeners/object_lifecycle_listener.rb +5 -1
  128. data/app/services/hyrax/listeners/trophy_cleanup_listener.rb +2 -1
  129. data/app/services/hyrax/listeners/workflow_listener.rb +13 -0
  130. data/app/services/hyrax/listeners.rb +2 -1
  131. data/app/services/hyrax/location_service.rb +3 -0
  132. data/app/services/hyrax/multiple_membership_checker.rb +1 -1
  133. data/app/services/hyrax/simple_schema_loader.rb +1 -1
  134. data/app/services/hyrax/solr_service.rb +19 -5
  135. data/app/services/hyrax/statistics/collections/over_time.rb +1 -1
  136. data/app/services/hyrax/statistics/query_service.rb +6 -0
  137. data/app/services/hyrax/valkyrie_persist_derivatives.rb +11 -4
  138. data/app/services/hyrax/valkyrie_upload.rb +1 -1
  139. data/app/services/hyrax/work_uploads_handler.rb +5 -4
  140. data/app/views/_user_util_links.html.erb +1 -1
  141. data/app/views/collections/edit_fields/_based_near.html.erb +11 -7
  142. data/app/views/hyrax/admin/admin_sets/_form_participants.html.erb +67 -67
  143. data/app/views/hyrax/admin/admin_sets/edit.html.erb +1 -1
  144. data/app/views/hyrax/admin/collection_types/_form_participants.html.erb +3 -1
  145. data/app/views/hyrax/base/_attribute_rows.html.erb +1 -0
  146. data/app/views/hyrax/base/_base_form_files_prepend.html.erb +4 -0
  147. data/app/views/hyrax/base/_form_files.html.erb +65 -64
  148. data/app/views/hyrax/base/show.html.erb +2 -3
  149. data/app/views/hyrax/collections/show.html.erb +7 -9
  150. data/app/views/hyrax/dashboard/_sidebar.html.erb +4 -3
  151. data/app/views/hyrax/dashboard/collections/_form_share_table.html.erb +2 -2
  152. data/app/views/hyrax/file_sets/media_display/_audio.html.erb +1 -1
  153. data/app/views/hyrax/file_sets/media_display/_video.html.erb +1 -1
  154. data/app/views/hyrax/my/facet.html.erb +1 -1
  155. data/app/views/layouts/_head_tag_content.html.erb +1 -0
  156. data/app/views/shared/_footer.html.erb +1 -1
  157. data/chart/hyrax/Chart.yaml +3 -3
  158. data/chart/hyrax/values.yaml +9 -1
  159. data/config/initializers/listeners.rb +1 -1
  160. data/config/locales/hyrax.de.yml +5 -0
  161. data/config/locales/hyrax.en.yml +10 -0
  162. data/config/locales/hyrax.es.yml +5 -0
  163. data/config/locales/hyrax.fr.yml +5 -0
  164. data/config/locales/hyrax.it.yml +5 -0
  165. data/config/locales/hyrax.pt-BR.yml +5 -0
  166. data/config/locales/hyrax.zh.yml +5 -0
  167. data/config/metadata/basic_metadata.yaml +1 -0
  168. data/config/metadata/core_metadata.yaml +2 -0
  169. data/config/metadata/file_set_metadata.yaml +2 -0
  170. data/docker-compose-koppie.yml +3 -3
  171. data/docker-compose-sirenia.yml +3 -3
  172. data/documentation/developing-your-hyrax-based-app.md +77 -60
  173. data/hyrax.gemspec +9 -2
  174. data/lib/generators/hyrax/collection_resource/templates/collection_indexer.rb.erb +1 -1
  175. data/lib/generators/hyrax/config_generator.rb +12 -0
  176. data/lib/generators/hyrax/install_generator.rb +37 -7
  177. data/lib/generators/hyrax/listeners_generator.rb +18 -0
  178. data/lib/generators/hyrax/models_generator.rb +1 -10
  179. data/lib/generators/hyrax/riiif_generator.rb +6 -4
  180. data/lib/generators/hyrax/templates/.env +9 -0
  181. data/lib/generators/hyrax/templates/.lando.yml +50 -0
  182. data/lib/generators/hyrax/templates/app/listeners/hyrax_listener.rb +81 -0
  183. data/lib/generators/hyrax/templates/app/models/file_set.rb +1 -2
  184. data/lib/generators/hyrax/templates/config/initializers/1_valkyrie.rb +102 -0
  185. data/lib/generators/hyrax/templates/config/initializers/file_services.rb +6 -0
  186. data/lib/generators/hyrax/templates/config/initializers/hyrax.rb +41 -5
  187. data/lib/generators/hyrax/templates/config/initializers/publisher.rb +3 -0
  188. data/lib/generators/hyrax/templates/config/initializers/riiif.rb +77 -0
  189. data/lib/generators/hyrax/templates/config/locales/hyrax.de.yml +1 -1
  190. data/lib/generators/hyrax/templates/config/locales/hyrax.en.yml +1 -1
  191. data/lib/generators/hyrax/templates/config/locales/hyrax.es.yml +1 -1
  192. data/lib/generators/hyrax/templates/config/locales/hyrax.fr.yml +1 -1
  193. data/lib/generators/hyrax/templates/config/locales/hyrax.it.yml +1 -1
  194. data/lib/generators/hyrax/templates/config/locales/hyrax.pt-BR.yml +1 -1
  195. data/lib/generators/hyrax/templates/config/locales/hyrax.zh.yml +1 -1
  196. data/lib/generators/hyrax/templates/config/redis.yml +3 -6
  197. data/lib/generators/hyrax/templates/config/valkyrie_index.yml +4 -9
  198. data/lib/generators/hyrax/work_resource/templates/indexer.rb.erb +1 -1
  199. data/lib/hyrax/configuration.rb +95 -7
  200. data/lib/hyrax/indexer.rb +1 -1
  201. data/lib/hyrax/publisher.rb +5 -2
  202. data/lib/hyrax/resource_sync/change_list_writer.rb +1 -1
  203. data/lib/hyrax/resource_sync/resource_list_writer.rb +1 -1
  204. data/lib/hyrax/specs/capybara.rb +1 -0
  205. data/lib/hyrax/specs/shared_specs/hydra_works.rb +78 -20
  206. data/lib/hyrax/specs/shared_specs/indexers.rb +1 -1
  207. data/lib/hyrax/transactions/admin_set_destroy.rb +2 -1
  208. data/lib/hyrax/transactions/container.rb +5 -0
  209. data/lib/hyrax/transactions/steps/add_to_parent.rb +1 -0
  210. data/lib/hyrax/transactions/steps/check_for_default_admin_set.rb +32 -0
  211. data/lib/hyrax/transactions/steps/check_for_empty_admin_set.rb +1 -1
  212. data/lib/hyrax/transactions/steps/save.rb +2 -1
  213. data/lib/hyrax/transactions/steps/set_user_as_creator.rb +1 -1
  214. data/lib/hyrax/transactions/steps/update_work_members.rb +2 -0
  215. data/lib/hyrax/version.rb +1 -1
  216. data/lib/hyrax.rb +1 -0
  217. data/lib/tasks/embargo_lease.rake +1 -0
  218. data/lib/valkyrie/indexing/solr/indexing_adapter.rb +21 -7
  219. data/lib/wings/active_fedora_converter/default_work.rb +4 -5
  220. data/lib/wings/active_fedora_converter/file_metadata_node.rb +1 -1
  221. data/lib/wings/model_registry.rb +8 -0
  222. data/lib/wings/model_transformer.rb +19 -2
  223. data/lib/wings/orm_converter.rb +4 -0
  224. data/lib/wings/services/custom_queries/find_ids_by_model.rb +2 -2
  225. data/lib/wings/valkyrie/query_service.rb +5 -2
  226. data/lib/wings.rb +3 -0
  227. data/spec/factories/access_control.rb +12 -0
  228. data/spec/factories/admin_sets.rb +32 -0
  229. data/spec/factories/admin_sets_lw.rb +222 -0
  230. data/spec/factories/administrative_sets.rb +79 -0
  231. data/spec/factories/api_items.rb +92 -0
  232. data/spec/factories/collection_branding_infos.rb +12 -0
  233. data/spec/factories/collection_type_participants.rb +9 -0
  234. data/spec/factories/collection_types.rb +139 -0
  235. data/spec/factories/collections.rb +282 -0
  236. data/spec/factories/collections_factory.rb +107 -0
  237. data/spec/factories/content_blocks.rb +5 -0
  238. data/spec/factories/counter_metrics.rb +12 -0
  239. data/spec/factories/featured_works.rb +5 -0
  240. data/spec/factories/file_sets.rb +45 -0
  241. data/spec/factories/generic_works.rb +200 -0
  242. data/spec/factories/hyrax_collection.rb +92 -0
  243. data/spec/factories/hyrax_default_admin_set.rb +7 -0
  244. data/spec/factories/hyrax_embargo.rb +18 -0
  245. data/spec/factories/hyrax_file_metadata.rb +92 -0
  246. data/spec/factories/hyrax_file_set.rb +129 -0
  247. data/spec/factories/hyrax_lease.rb +18 -0
  248. data/spec/factories/hyrax_resource.rb +15 -0
  249. data/spec/factories/hyrax_work.rb +221 -0
  250. data/spec/factories/object_id.rb +7 -0
  251. data/spec/factories/operations.rb +22 -0
  252. data/spec/factories/permission.rb +7 -0
  253. data/spec/factories/permission_template_accesses.rb +17 -0
  254. data/spec/factories/permission_templates.rb +111 -0
  255. data/spec/factories/proxy_deposit_requests.rb +7 -0
  256. data/spec/factories/single_use_links.rb +14 -0
  257. data/spec/factories/sipity_entities.rb +17 -0
  258. data/spec/factories/uploaded_files.rb +11 -0
  259. data/spec/factories/users.rb +52 -0
  260. data/spec/factories/workflow_actions.rb +7 -0
  261. data/spec/factories/workflow_states.rb +7 -0
  262. data/spec/factories/workflows.rb +7 -0
  263. data/spec/support/book_resource.rb +36 -0
  264. data/spec/support/can_can_overrides.rb +43 -0
  265. data/spec/support/clean_solr.rb +7 -0
  266. data/spec/support/controller_level_helpers.rb +27 -0
  267. data/spec/support/factory_helpers.rb +94 -0
  268. data/spec/support/fakes/fake_actor.rb +22 -0
  269. data/spec/support/fakes/fake_authority.rb +14 -0
  270. data/spec/support/fakes/fake_search_builder_scope.rb +44 -0
  271. data/spec/support/fakes/indexing_adapter.rb +17 -0
  272. data/spec/support/fakes/test_hydra_group_service.rb +55 -0
  273. data/spec/support/features/batch_edit_actions.rb +37 -0
  274. data/spec/support/features/session_helpers.rb +15 -0
  275. data/spec/support/features/workflow.rb +10 -0
  276. data/spec/support/features.rb +11 -0
  277. data/spec/support/form_with_validations.rb +15 -0
  278. data/spec/support/input_support.rb +12 -0
  279. data/spec/support/logging_formatter.rb +67 -0
  280. data/spec/support/matchers/api_responses.rb +27 -0
  281. data/spec/support/matchers/collection_type_property_matchers.rb +30 -0
  282. data/spec/support/matchers/embargo.rb +9 -0
  283. data/spec/support/matchers/lease.rb +9 -0
  284. data/spec/support/matchers/match_valkyrie_ids_with_af_ids.rb +12 -0
  285. data/spec/support/matchers/pcdm_matchers.rb +34 -0
  286. data/spec/support/matchers/permission.rb +31 -0
  287. data/spec/support/matchers/response_matchers.rb +8 -0
  288. data/spec/support/optional_example.rb +17 -0
  289. data/spec/support/rake.rb +42 -0
  290. data/spec/support/selectors.rb +112 -0
  291. data/spec/support/shared_examples_for_collection_presenter.rb +44 -0
  292. data/spec/support/simple_work.rb +28 -0
  293. data/spec/support/spec_statistic.rb +24 -0
  294. data/spec/support/speedup.rb +7 -0
  295. data/spec/support/statistic_helper.rb +10 -0
  296. data/spec/support/valkyrie_indexing.rb +2 -0
  297. data/spec/support/wings_models.rb +9 -0
  298. data/template.rb +1 -3
  299. metadata +112 -30
  300. data/app/indexers/hyrax/resource_indexer.rb +0 -15
  301. data/app/models/concerns/hyrax/riiif_file.rb +0 -30
  302. data/app/services/hyrax/characterization/model_wrapper.rb +0 -0
  303. data/app/services/hyrax/custom_queries/find_by_collection_type.rb +0 -0
  304. data/app/services/hyrax/query_service.rb +0 -0
  305. data/app/services/hyrax/riiif_file_resolver.rb +0 -50
  306. data/lib/hyrax/specs/disable_animations_in_test_environment.rb +0 -53
  307. /data/app/indexers/{hyrax → concerns/hyrax}/thumbnail_indexer.rb +0 -0
@@ -0,0 +1,139 @@
1
+ # frozen_string_literal: true
2
+ FactoryBot.define do
3
+ factory :collection_type, class: Hyrax::CollectionType do
4
+ sequence(:title) { |n| "Collection Type #{n}" }
5
+ sequence(:machine_id) { |n| "title_#{n}" }
6
+
7
+ description { 'Collection type with all options' }
8
+ nestable { true }
9
+ discoverable { true }
10
+ sharable { true }
11
+ brandable { true }
12
+ share_applies_to_new_works { true }
13
+ allow_multiple_membership { true }
14
+ require_membership { false }
15
+ assigns_workflow { false }
16
+ assigns_visibility { false }
17
+
18
+ transient do
19
+ creator_user { nil }
20
+ creator_group { nil }
21
+ manager_user { nil }
22
+ manager_group { nil }
23
+ end
24
+
25
+ after(:create) do |collection_type, evaluator|
26
+ CollectionTypeFactoryHelper.process_access(collection_type, evaluator)
27
+ end
28
+
29
+ trait :nestable do
30
+ nestable { true }
31
+ end
32
+
33
+ trait :not_nestable do
34
+ nestable { false }
35
+ end
36
+
37
+ trait :discoverable do
38
+ discoverable { true }
39
+ end
40
+
41
+ trait :not_discoverable do
42
+ discoverable { false }
43
+ end
44
+
45
+ trait :brandable do
46
+ brandable { true }
47
+ end
48
+
49
+ trait :not_brandable do
50
+ brandable { false }
51
+ end
52
+
53
+ trait :sharable do
54
+ sharable { true }
55
+ share_applies_to_new_works { true }
56
+ end
57
+
58
+ trait :sharable_no_work_permissions do
59
+ sharable { true }
60
+ share_applies_to_new_works { false }
61
+ end
62
+
63
+ trait :not_sharable do
64
+ sharable { false }
65
+ share_applies_to_new_works { false }
66
+ end
67
+
68
+ trait :allow_multiple_membership do
69
+ allow_multiple_membership { true }
70
+ end
71
+
72
+ trait :not_allow_multiple_membership do
73
+ allow_multiple_membership { false }
74
+ end
75
+ end
76
+
77
+ factory :user_collection_type, class: Hyrax::CollectionType do
78
+ initialize_with { Hyrax::CollectionType.find_or_create_default_collection_type }
79
+ end
80
+
81
+ factory :admin_set_collection_type, class: Hyrax::CollectionType do
82
+ initialize_with { Hyrax::CollectionType.find_or_create_admin_set_type }
83
+
84
+ transient do
85
+ creator_user { nil }
86
+ creator_group { nil }
87
+ manager_user { nil }
88
+ manager_group { nil }
89
+ end
90
+
91
+ after(:create) do |collection_type, evaluator|
92
+ CollectionTypeFactoryHelper.process_access(collection_type, evaluator)
93
+ end
94
+ end
95
+
96
+ class CollectionTypeFactoryHelper
97
+ def self.process_access(collection_type, evaluator) # rubocop:disable Metrics/MethodLength
98
+ if evaluator.creator_user
99
+ Array(evaluator.creator_user).each do |user|
100
+ attributes = { hyrax_collection_type_id: collection_type.id,
101
+ access: Hyrax::CollectionTypeParticipant::CREATE_ACCESS,
102
+ agent_id: user,
103
+ agent_type: Hyrax::CollectionTypeParticipant::USER_TYPE }
104
+ FactoryBot.create(:collection_type_participant, attributes)
105
+ end
106
+ end
107
+
108
+ if evaluator.creator_group
109
+ Array(evaluator.creator_group).each do |group|
110
+ attributes = { hyrax_collection_type_id: collection_type.id,
111
+ access: Hyrax::CollectionTypeParticipant::CREATE_ACCESS,
112
+ agent_id: group,
113
+ agent_type: Hyrax::CollectionTypeParticipant::GROUP_TYPE }
114
+ FactoryBot.create(:collection_type_participant, attributes)
115
+ end
116
+ end
117
+
118
+ if evaluator.manager_user
119
+ Array(evaluator.manager_user).each do |user|
120
+ attributes = { hyrax_collection_type_id: collection_type.id,
121
+ access: Hyrax::CollectionTypeParticipant::MANAGE_ACCESS,
122
+ agent_id: user,
123
+ agent_type: Hyrax::CollectionTypeParticipant::USER_TYPE }
124
+ FactoryBot.create(:collection_type_participant, attributes)
125
+ end
126
+ end
127
+
128
+ return unless evaluator.manager_group
129
+
130
+ Array(evaluator.manager_group).each do |group|
131
+ attributes = { hyrax_collection_type_id: collection_type.id,
132
+ access: Hyrax::CollectionTypeParticipant::MANAGE_ACCESS,
133
+ agent_id: group,
134
+ agent_type: Hyrax::CollectionTypeParticipant::GROUP_TYPE }
135
+ FactoryBot.create(:collection_type_participant, attributes)
136
+ end
137
+ end
138
+ end
139
+ end
@@ -0,0 +1,282 @@
1
+ # frozen_string_literal: true
2
+ FactoryBot.define do
3
+ # Tests that create a Fedora Object are very slow. This factory lets you control which parts of the object ecosystem
4
+ # get built.
5
+ #
6
+ # PREFERRED: Use build whenever possible. You can control the creation of the permission template, collection type, and
7
+ # solr document by passing parameters to the build(:collection_lw) method. That way you can build only the parts
8
+ # needed for a specific test.
9
+ #
10
+ # AVOID: Do not use create unless absolutely necessary. It will create everything including the Fedora object.
11
+ #
12
+ # @example Simple build of a collection with no additional parts created. Lightest weight.
13
+ # NOTE: A user is automatically created as the owner of the collection.
14
+ # let(:collection) { build(:collection_lw) }
15
+ #
16
+ # @example Simple build of a collection with no additional parts created. User is the owner of the collection. Lightest weight.
17
+ # let(:collection) { build(:collection_lw, user:) }
18
+ #
19
+ # @example Simple build of a collection with only solr-document. Owner is given edit-access in solr-document. Light weight.
20
+ # let(:collection) { build(:collection_lw, with_solr_document: true) }
21
+ #
22
+ # @example Simple build of a collection with only a permission template created. Owner is set as a manager. Light weight.
23
+ # let(:collection) { build(:collection_lw, with_permission_template: true) }
24
+ #
25
+ # @example Build a collection with only a permission template created. Permissions are set based on
26
+ # attributes set for `with_permission_template`. Middle weight.
27
+ # # permissions passed thru `with_permission_template` can be any of the following in any combination
28
+ # let(:permissions) { { manage_users: [user.user_key], # multiple users can be listed
29
+ # deposit_users: [user.user_key],
30
+ # view_users: [user.user_key],
31
+ # manage_groups: [group_name], # multiple groups can be listed
32
+ # deposit_groups: [group_name],
33
+ # view_groups: [group_name], } }
34
+ # let(:collection) { build(:collection_lw, user: , with_permission_template: permissions) }
35
+ #
36
+ # @example Build a collection with permission template and solr-document created. Permissions are set based on
37
+ # attributes set for `with_permission_template`. Solr-document includes read/edit access defined based
38
+ # on attributes passed thru `with_permission_template`. Middle weight.
39
+ # # permissions passed thru `with_permission_template` can be any of the following in any combination
40
+ # let(:permissions) { { manage_users: [user.user_key], # multiple users can be listed
41
+ # deposit_users: [user.user_key],
42
+ # view_users: [user.user_key],
43
+ # manage_groups: [group_name], # multiple groups can be listed
44
+ # deposit_groups: [group_name],
45
+ # view_groups: [group_name], } }
46
+ # let(:collection) { build(:collection_lw, user: , with_permission_template: permissions, with_solr_document: true) }
47
+ #
48
+ # @example Build a collection generating its collection type with specific settings. Light Weight.
49
+ # NOTE: Do not use this approach if you need access to the collection type in the test.
50
+ # DEFAULT: If `collection_type_settings` and `collection_type` are not specified, then the default
51
+ # User Collection type will be used.
52
+ # # Any not specified default to ON. At least one setting should be specified.
53
+ # let(:settings) { [
54
+ # :nestable, # OR :not_nestable,
55
+ # :discoverable, # OR :not_discoverable
56
+ # :brandable, # OR :not_brandable
57
+ # :sharable, # OR :not_sharable OR :sharable_no_work_permissions
58
+ # :allow_multiple_membership, # OR :not_allow_multiple_membership
59
+ # ] }
60
+ # let(:collection) { build(:collection_lw, collection_type_settings: settings) }
61
+ #
62
+ # @example Build a collection using the passed in collection type. Light Weight.
63
+ # NOTE: Use this approach if you need access to the collection type in the test.
64
+ # # Any not specified default to ON. At least one setting should be specified.
65
+ # let(:settings) { [
66
+ # :nestable, # OR :not_nestable,
67
+ # :discoverable, # OR :not_discoverable
68
+ # :brandable, # OR :not_brandable
69
+ # :sharable, # OR :not_sharable OR :sharable_no_work_permissions
70
+ # :allow_multiple_membership, # OR :not_allow_multiple_membership
71
+ # ] }
72
+ # let(:collection_type) { create(:collection_lw_type, settings) }
73
+ # let(:collection) { build(:collection_lw, collection_type: collection_type) }
74
+
75
+ factory :collection_lw, class: Collection do
76
+ transient do
77
+ user { FactoryBot.create(:user) }
78
+
79
+ collection_type { nil }
80
+ collection_type_settings { nil }
81
+ with_permission_template { false }
82
+ with_solr_document { false }
83
+ end
84
+ sequence(:title) { |n| ["Collection Title #{n}"] }
85
+
86
+ after(:build) do |collection, evaluator|
87
+ collection.collection_type_gid = evaluator.collection_type.to_global_id if evaluator.collection_type&.id.present?
88
+ collection.apply_depositor_metadata(evaluator.user.user_key)
89
+
90
+ CollectionLwFactoryHelper.process_collection_type_settings(collection, evaluator)
91
+ CollectionLwFactoryHelper.process_with_permission_template(collection, evaluator)
92
+ CollectionLwFactoryHelper.process_with_solr_document(collection, evaluator)
93
+ end
94
+
95
+ before(:create) do |collection, evaluator|
96
+ # force create a permission template if it doesn't exist for the newly created collection
97
+ CollectionLwFactoryHelper.process_with_permission_template(collection, evaluator, true) unless evaluator.with_permission_template
98
+ end
99
+
100
+ after(:create) do |collection, _evaluator|
101
+ collection.permission_template.reset_access_controls_for(collection: collection, interpret_visibility: true)
102
+ end
103
+
104
+ factory :public_collection_lw, traits: [:public_lw]
105
+
106
+ factory :private_collection_lw do
107
+ visibility { Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_PRIVATE }
108
+ end
109
+
110
+ factory :institution_collection_lw do
111
+ visibility { Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_AUTHENTICATED }
112
+ end
113
+
114
+ factory :named_collection_lw do
115
+ title { ['collection title'] }
116
+ description { ['collection description'] }
117
+ end
118
+
119
+ trait :public_lw do
120
+ visibility { Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_PUBLIC }
121
+ end
122
+
123
+ trait :private_lw do
124
+ visibility { Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_PRIVATE }
125
+ end
126
+
127
+ trait :institution_lw do
128
+ visibility { Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_AUTHENTICATED }
129
+ end
130
+
131
+ trait :public_lw do
132
+ visibility { Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_PUBLIC }
133
+ end
134
+ end
135
+
136
+ factory :user_collection_lw, class: Collection do
137
+ transient do
138
+ user { FactoryBot.create(:user) }
139
+ collection_type { create(:user_collection_type) }
140
+ end
141
+
142
+ sequence(:title) { |n| ["User Collection Title #{n}"] }
143
+
144
+ after(:build) do |collection, evaluator|
145
+ collection.apply_depositor_metadata(evaluator.user.user_key)
146
+ end
147
+ end
148
+
149
+ factory :typeless_collection_lw, class: Collection do
150
+ # To create a pre-Hyrax 2.1.0 collection without a collection type gid...
151
+ # col = build(:typeless_collection, ...)
152
+ # col.save(validate: false)
153
+ transient do
154
+ user { FactoryBot.create(:user) }
155
+ with_permission_template { false }
156
+ do_save { false }
157
+ end
158
+
159
+ sequence(:title) { |n| ["Typeless Collection Title #{n}"] }
160
+
161
+ after(:build) do |collection, evaluator|
162
+ collection.apply_depositor_metadata(evaluator.user.user_key)
163
+ collection.save(validate: false) if evaluator.do_save || evaluator.with_permission_template
164
+ if evaluator.with_permission_template
165
+ attributes = { source_id: collection.id }
166
+ attributes[:manage_users] = [evaluator.user]
167
+ attributes = evaluator.with_permission_template.merge(attributes) if evaluator.with_permission_template.respond_to?(:merge)
168
+ create(:permission_template, attributes) unless Hyrax::PermissionTemplate.find_by(source_id: collection.id)
169
+ end
170
+ end
171
+ end
172
+
173
+ class CollectionLwFactoryHelper
174
+ # @returns array of user keys
175
+ def self.permission_from_template(permission_template_attributes, permission_key)
176
+ permissions = []
177
+ return permissions if permission_template_attributes.blank?
178
+ return permissions unless permission_template_attributes.is_a? Hash
179
+ return permissions unless permission_template_attributes.key?(permission_key)
180
+ permission_template_attributes[permission_key]
181
+ end
182
+ private_class_method :permission_from_template
183
+
184
+ # @param [Hash] permission_template_attributes where names identify the role and value are the user keys for that role
185
+ # @parem [String] creator_user is the user who created the new collection
186
+ # @param [Boolean] include_creator, when true, adds the creator_user as a manager
187
+ # @returns array of user keys
188
+ def self.user_managers(permission_template_attributes, creator_user)
189
+ managers = permission_from_template(permission_template_attributes, :manage_users)
190
+ managers << creator_user
191
+ managers
192
+ end
193
+
194
+ # @param [Hash] permission_template_attributes where names identify the role and value are the user keys for that role
195
+ # @returns array of user keys
196
+ def self.group_managers(permission_template_attributes)
197
+ permission_from_template(permission_template_attributes, :manage_groups)
198
+ end
199
+
200
+ # @param [Hash] permission_template_attributes where names identify the role and value are the user keys for that role
201
+ # @returns array of user keys
202
+ def self.user_depositors(permission_template_attributes)
203
+ permission_from_template(permission_template_attributes, :deposit_users)
204
+ end
205
+
206
+ # @param [Hash] permission_template_attributes where names identify the role and value are the user keys for that role
207
+ # @returns array of user keys
208
+ def self.group_depositors(permission_template_attributes)
209
+ permission_from_template(permission_template_attributes, :deposit_groups)
210
+ end
211
+
212
+ # @param [Hash] permission_template_attributes where names identify the role and value are the user keys for that role
213
+ # @returns array of user keys
214
+ def self.user_viewers(permission_template_attributes)
215
+ permission_from_template(permission_template_attributes, :view_users)
216
+ end
217
+
218
+ # @param [Hash] permission_template_attributes where names identify the role and value are the user keys for that role
219
+ # @returns array of user keys
220
+ def self.group_viewers(permission_template_attributes)
221
+ permission_from_template(permission_template_attributes, :view_groups)
222
+ end
223
+
224
+ # Process the collection_type_settings transient property such that...
225
+ # * creates the collection type with specified settings if collection_type_settings has settings (ignores collection_type_gid)
226
+ # * uses passed in collection type if collection_type_gid is specified AND collection_type_settings is nil
227
+ # * uses default User Collection type if neither are specified
228
+ # @param [Collection] collection object being built/created by the factory
229
+ # @param [Class] evaluator holding the transient properties for the current build/creation process
230
+ def self.process_collection_type_settings(collection, evaluator)
231
+ if evaluator.collection_type_settings.present?
232
+ collection.collection_type = FactoryBot.create(:collection_type, *evaluator.collection_type_settings)
233
+ elsif collection.collection_type_gid.blank?
234
+ collection.collection_type = FactoryBot.create(:user_collection_type)
235
+ end
236
+ end
237
+
238
+ # Process the with_permission_template transient property such that...
239
+ # * a permission template is created for the collection
240
+ # * a permission template access is created for the collection creator
241
+ # * additional permission template accesses are created for each user/group identified in the attributes
242
+ # of with_permission_template (created by the permission_template factory)
243
+ # @param [Collection] collection object being built/created by the factory
244
+ # @param [Class] evaluator holding the transient properties for the current build/creation process
245
+ # @param [Boolean] if true, force the permission template to be created
246
+ def self.process_with_permission_template(collection, evaluator, force = false)
247
+ return unless force || evaluator.with_permission_template
248
+ collection.id ||= FactoryBot.generate(:object_id)
249
+ attributes = { source_id: collection.id }
250
+ attributes[:manage_users] = user_managers(evaluator.with_permission_template, evaluator.user)
251
+ attributes = evaluator.with_permission_template.merge(attributes) if evaluator.with_permission_template.respond_to?(:merge)
252
+ FactoryBot.create(:permission_template, attributes) unless Hyrax::PermissionTemplate.find_by(source_id: collection.id)
253
+ end
254
+
255
+ # Process the with_solr_document transient property such that...
256
+ # * a solr document is created for the collection
257
+ # * permissions identified by with_permission_template, if any, are added to the solr fields
258
+ # @param [Collection] collection object being built/created by the factory
259
+ # @param [Class] evaluator holding the transient properties for the current build/creation process
260
+ def self.process_with_solr_document(collection, evaluator)
261
+ return unless evaluator.with_solr_document
262
+ Hyrax::SolrService.add(solr_document_with_permissions(collection, evaluator), commit: true)
263
+ end
264
+
265
+ # Return the collection's solr document with permissions added, such that...
266
+ # * permissions identified by with_permission_template, if any, are added to the solr fields
267
+ # @param [Collection] collection object being built/created by the factory
268
+ # @param [Class] evaluator holding the transient properties for the current build/creation process
269
+ # @returns the collection's solr document with permissions added
270
+ def self.solr_document_with_permissions(collection, evaluator)
271
+ collection.id ||= FactoryBot.generate(:object_id)
272
+ collection.edit_users = user_managers(evaluator.with_permission_template, evaluator.user)
273
+ collection.edit_groups = group_managers(evaluator.with_permission_template)
274
+ collection.read_users = user_viewers(evaluator.with_permission_template) +
275
+ user_depositors(evaluator.with_permission_template)
276
+ collection.read_groups = group_viewers(evaluator.with_permission_template) +
277
+ group_depositors(evaluator.with_permission_template)
278
+ collection.to_solr
279
+ end
280
+ private_class_method :solr_document_with_permissions
281
+ end
282
+ end
@@ -0,0 +1,107 @@
1
+ # frozen_string_literal: true
2
+ FactoryBot.define do
3
+ factory :collection do
4
+ # DEPRECATION: This factory is being replaced by collection_lw defined in collections.rb. New tests should use the
5
+ # light weight collection factory. DO NOT ADD tests using this factory.
6
+ #
7
+ # rubocop:disable Layout/LineLength
8
+ # @example let(:collection) { build(:collection, collection_type_settings: [:not_nestable, :discoverable, :sharable, :allow_multiple_membership]) }
9
+ # rubocop:enable Layout/LineLength
10
+
11
+ transient do
12
+ user { FactoryBot.create(:user) }
13
+ # allow defaulting to default user collection
14
+ collection_type_settings { nil }
15
+ with_permission_template { false }
16
+ create_access { false }
17
+ end
18
+ sequence(:title) { |n| ["Collection Title #{n}"] }
19
+
20
+ after(:build) do |collection, evaluator|
21
+ collection.apply_depositor_metadata(evaluator.user.user_key)
22
+ if evaluator.collection_type_settings.present?
23
+ collection.collection_type = create(:collection_type, *evaluator.collection_type_settings)
24
+ elsif collection.collection_type_gid.nil?
25
+ collection.collection_type = create(:user_collection_type)
26
+ end
27
+ end
28
+
29
+ after(:create) do |collection, evaluator|
30
+ # create the permission template if it was requested
31
+ if evaluator.with_permission_template || evaluator.create_access
32
+ attributes = { source_id: collection.id }
33
+ attributes[:manage_users] = CollectionFactoryHelper.user_managers(evaluator.with_permission_template, evaluator.user, evaluator.create_access)
34
+ attributes = evaluator.with_permission_template.merge(attributes) if evaluator.with_permission_template.respond_to?(:merge)
35
+ create(:permission_template, attributes) unless Hyrax::PermissionTemplate.find_by(source_id: collection.id)
36
+ collection.permission_template.reset_access_controls_for(collection: collection, interpret_visibility: true)
37
+ end
38
+ end
39
+
40
+ factory :public_collection, traits: [:public]
41
+
42
+ trait :public do
43
+ visibility { Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_PUBLIC }
44
+ end
45
+
46
+ factory :private_collection do
47
+ visibility { Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_PRIVATE }
48
+ end
49
+
50
+ factory :institution_collection do
51
+ visibility { Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_AUTHENTICATED }
52
+ end
53
+
54
+ factory :named_collection do
55
+ title { ['collection title'] }
56
+ description { ['collection description'] }
57
+ end
58
+ end
59
+
60
+ factory :user_collection, class: Collection do
61
+ transient do
62
+ user { FactoryBot.create(:user) }
63
+ collection_type { create(:user_collection_type) }
64
+ end
65
+
66
+ sequence(:title) { |n| ["User Collection Title #{n}"] }
67
+
68
+ after(:build) do |collection, evaluator|
69
+ collection.apply_depositor_metadata(evaluator.user.user_key)
70
+ end
71
+ end
72
+
73
+ factory :typeless_collection, class: Collection do
74
+ # To create a pre-Hyrax 2.1.0 collection without a collection type gid...
75
+ # col = build(:typeless_collection, ...)
76
+ # col.save(validate: false)
77
+ transient do
78
+ user { FactoryBot.create(:user) }
79
+ with_permission_template { false }
80
+ create_access { false }
81
+ do_save { false }
82
+ end
83
+
84
+ sequence(:title) { |n| ["Typeless Collection Title #{n}"] }
85
+
86
+ after(:build) do |collection, evaluator|
87
+ collection.apply_depositor_metadata(evaluator.user.user_key)
88
+ collection.save(validate: false) if evaluator.do_save || evaluator.with_permission_template
89
+ if evaluator.with_permission_template
90
+ attributes = { source_id: collection.id }
91
+ attributes[:manage_users] = [evaluator.user] if evaluator.create_access
92
+ attributes = evaluator.with_permission_template.merge(attributes) if evaluator.with_permission_template.respond_to?(:merge)
93
+ create(:permission_template, attributes) unless Hyrax::PermissionTemplate.find_by(source_id: collection.id)
94
+ end
95
+ end
96
+ end
97
+
98
+ class CollectionFactoryHelper
99
+ def self.user_managers(permission_template_attributes, creator_user, include_creator = false)
100
+ managers = []
101
+ managers << creator_user.user_key if include_creator
102
+ return managers unless permission_template_attributes.respond_to?(:merge)
103
+ return managers unless permission_template_attributes.key?(:manage_users)
104
+ managers + permission_template_attributes[:manage_users]
105
+ end
106
+ end
107
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+ FactoryBot.define do
3
+ factory :content_block do |_cb|
4
+ end
5
+ end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ FactoryBot.define do
4
+ factory :counter_metric, class: "Hyrax::CounterMetric" do
5
+ worktype { "Generic Work" }
6
+ resource_type { "Book" }
7
+ work_id { "12345678" }
8
+ date { Date.new(2023, 7, 17) }
9
+ total_item_investigations { 10 }
10
+ total_item_requests { 5 }
11
+ end
12
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+ FactoryBot.define do
3
+ factory :featured_work do |_u|
4
+ end
5
+ end
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+ FactoryBot.define do
3
+ factory :file_set do
4
+ transient do
5
+ user { FactoryBot.create(:user) }
6
+ content { nil }
7
+ end
8
+ after(:build) do |fs, evaluator|
9
+ fs.apply_depositor_metadata evaluator.user.user_key
10
+ end
11
+
12
+ after(:create) do |file, evaluator|
13
+ Hydra::Works::UploadFileToFileSet.call(file, evaluator.content) if evaluator.content
14
+ end
15
+
16
+ trait :public do
17
+ read_groups { ["public"] }
18
+ end
19
+
20
+ trait :registered do
21
+ read_groups { ["registered"] }
22
+ end
23
+
24
+ trait :image do
25
+ content { File.open(Hyrax::Engine.root + 'spec/fixtures/world.png') }
26
+ end
27
+
28
+ trait :with_original_file do
29
+ after(:create) do |file_set, _evaluator|
30
+ Hydra::Works::AddFileToFileSet
31
+ .call(file_set, File.open(Hyrax::Engine.root + 'spec/fixtures/world.png'), :original_file)
32
+ end
33
+ end
34
+
35
+ factory :file_with_work do
36
+ after(:build) do |file, _evaluator|
37
+ file.title = ['testfile']
38
+ end
39
+ after(:create) do |file, evaluator|
40
+ Hydra::Works::UploadFileToFileSet.call(file, evaluator.content) if evaluator.content
41
+ create(:work, user: evaluator.user).members << file
42
+ end
43
+ end
44
+ end
45
+ end