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
@@ -12,7 +12,11 @@ module Hyrax
12
12
  end
13
13
 
14
14
  def total_viewable_items
15
- ActiveFedora::Base.where("isPartOf_ssim:#{id}").accessible_by(current_ability).count
15
+ field_pairs = { "isPartOf_ssim" => id.to_s }
16
+ SolrQueryService.new
17
+ .with_field_pairs(field_pairs: field_pairs)
18
+ .accessible_by(ability: current_ability)
19
+ .count
16
20
  end
17
21
 
18
22
  # AdminSet cannot be deleted if default set or non-empty
@@ -0,0 +1,116 @@
1
+ # frozen_string_literal: true
2
+ module Hyrax
3
+ ##
4
+ # @api public
5
+ # @since 3.1.0
6
+ #
7
+ # Presents select options for admin sets.
8
+ #
9
+ # Each entry in the {#select_options} return value provides a label for
10
+ # display, an id to serve as the value, and a data hash which is used as HTML5
11
+ # data entries. The data entries can be used as hooks for Javascript
12
+ # to control input validation taking into account the Admin Set and
13
+ # `PermissionTemplate` rules (`visibility_component.es6` does this, for
14
+ # example).
15
+ #
16
+ # @note this supersedes the older +Hyrax::AdminSetOptionsPresenter+, which
17
+ # actied more like a "service" sending database queries to Solr and
18
+ # ActiveRecord. this version seeks only to present the input data and
19
+ # relies on its caller to pass in the right data.
20
+ class AdminSetSelectionPresenter
21
+ ##
22
+ # @param [Array<#id>]
23
+ def initialize(admin_sets:)
24
+ @admin_sets = admin_sets
25
+ end
26
+
27
+ ##
28
+ # @return [Array<Array<String, String, Hash>>] an array suitable for a form
29
+ # input `collection:` parameter. it should contain a label, an id, and a
30
+ # hash of HTML5 data attributes.
31
+ def select_options
32
+ @admin_sets.map do |admin_set|
33
+ case admin_set
34
+ when OptionsEntry
35
+ admin_set.result
36
+ else
37
+ OptionsEntry.new(admin_set: admin_set).result
38
+ end
39
+ end
40
+ end
41
+
42
+ ##
43
+ # @api public
44
+ class OptionsEntry
45
+ ##
46
+ # @!attribute [rw] admin_set
47
+ # @return [AdministrativeSet, SolrDocument]
48
+ # @!attribute [rw] permission_template
49
+ # @return [PermissionTemplate]
50
+ # @!attribute [rw] permit_sharing
51
+ # @return [Boolean]
52
+ attr_accessor :admin_set, :permission_template, :permit_sharing
53
+
54
+ ##
55
+ # @param [AdministrativeSet, SolrDocument] admin_set
56
+ # @param [PermissionTemplate] permission_template
57
+ # @param [Boolean] permit_sharing
58
+ def initialize(admin_set:, permission_template: nil, permit_sharing: false)
59
+ @admin_set = admin_set
60
+ @permission_template = permission_template
61
+ @permit_sharing = permit_sharing
62
+ end
63
+
64
+ ##
65
+ # @return [Array<String, String, Hash>]
66
+ def result
67
+ [label, id, data]
68
+ end
69
+
70
+ ##
71
+ # @return [String]
72
+ def label
73
+ Array(admin_set.title).first || admin_set.to_s
74
+ end
75
+
76
+ ##
77
+ # @return [String]
78
+ def id
79
+ admin_set.id.to_s
80
+ end
81
+
82
+ ##
83
+ # @return [Hash{String => Object}]
84
+ def data
85
+ {}.tap do |data|
86
+ data['data-sharing'] = permit_sharing
87
+
88
+ if permission_template
89
+ data.merge!(data_for(permission_template))
90
+ else
91
+ data['data-release-no-delay'] = true
92
+ end
93
+ end
94
+ end
95
+
96
+ private
97
+
98
+ ##
99
+ # @api private
100
+ def data_for(template)
101
+ {}.tap do |data|
102
+ if template.release_no_delay?
103
+ data['data-release-no-delay'] = true
104
+ elsif template.release_date.present?
105
+ data['data-release-date'] = template.release_date
106
+ end
107
+
108
+ data['data-release-before-date'] = true if
109
+ template.release_before_date?
110
+ data['data-visibility'] = template.visibility if
111
+ template.visibility.present?
112
+ end
113
+ end
114
+ end
115
+ end
116
+ end
@@ -28,6 +28,7 @@ module Hyrax
28
28
  :to_s, to: :solr_document
29
29
 
30
30
  delegate(*Hyrax::CollectionType.settings_attributes, to: :collection_type, prefix: :collection_type_is)
31
+ alias nestable? collection_type_is_nestable?
31
32
 
32
33
  def collection_type
33
34
  @collection_type ||= Hyrax::CollectionType.find_by_gid!(collection_type_gid)
@@ -77,19 +78,36 @@ module Hyrax
77
78
  end
78
79
 
79
80
  def total_items
80
- Hyrax::SolrService.new.count("member_of_collection_ids_ssim:#{id}")
81
+ field_pairs = { "member_of_collection_ids_ssim" => id.to_s }
82
+ SolrQueryService.new
83
+ .with_field_pairs(field_pairs: field_pairs)
84
+ .count
81
85
  end
82
86
 
83
87
  def total_viewable_items
84
- ActiveFedora::Base.where("member_of_collection_ids_ssim:#{id}").accessible_by(current_ability).count
88
+ field_pairs = { "member_of_collection_ids_ssim" => id.to_s }
89
+ SolrQueryService.new
90
+ .with_field_pairs(field_pairs: field_pairs)
91
+ .accessible_by(ability: current_ability)
92
+ .count
85
93
  end
86
94
 
87
95
  def total_viewable_works
88
- ActiveFedora::Base.where("member_of_collection_ids_ssim:#{id} AND generic_type_sim:Work").accessible_by(current_ability).count
96
+ field_pairs = { "member_of_collection_ids_ssim" => id.to_s }
97
+ SolrQueryService.new
98
+ .with_field_pairs(field_pairs: field_pairs)
99
+ .with_generic_type(generic_type: "Work")
100
+ .accessible_by(ability: current_ability)
101
+ .count
89
102
  end
90
103
 
91
104
  def total_viewable_collections
92
- ActiveFedora::Base.where("member_of_collection_ids_ssim:#{id} AND generic_type_sim:Collection").accessible_by(current_ability).count
105
+ field_pairs = { "member_of_collection_ids_ssim" => id.to_s }
106
+ SolrQueryService.new
107
+ .with_field_pairs(field_pairs: field_pairs)
108
+ .with_generic_type(generic_type: "Collection")
109
+ .accessible_by(ability: current_ability)
110
+ .count
93
111
  end
94
112
 
95
113
  def collection_type_badge
@@ -119,25 +137,21 @@ module Hyrax
119
137
  Hyrax::Engine.routes.url_helpers.dashboard_collection_path(id, locale: I18n.locale)
120
138
  end
121
139
 
140
+ ##
141
+ # @return [#to_s, nil] a download path for the banner file
122
142
  def banner_file
123
- # Find Banner filename
124
- ci = CollectionBrandingInfo.where(collection_id: id, role: "banner")
125
- "/" + ci[0].local_path.split("/")[-4..-1].join("/") unless ci.empty?
143
+ banner = CollectionBrandingInfo.find_by(collection_id: id, role: "banner")
144
+ "/" + banner.local_path.split("/")[-4..-1].join("/") if banner
126
145
  end
127
146
 
128
147
  def logo_record
129
- logo_info = []
130
- # Find Logo filename, alttext, linktext
131
- cis = CollectionBrandingInfo.where(collection_id: id, role: "logo")
132
- return if cis.empty?
133
- cis.each do |coll_info|
134
- logo_file = File.split(coll_info.local_path).last
135
- file_location = "/" + coll_info.local_path.split("/")[-4..-1].join("/") unless logo_file.empty?
136
- alttext = coll_info.alt_text
137
- linkurl = coll_info.target_url
138
- logo_info << { file: logo_file, file_location: file_location, alttext: alttext, linkurl: linkurl }
148
+ CollectionBrandingInfo.where(collection_id: id, role: "logo")
149
+ .select(:local_path, :alt_text, :target_url).map do |logo|
150
+ { alttext: logo.alt_text,
151
+ file: File.split(logo.local_path).last,
152
+ file_location: "/#{logo.local_path.split('/')[-4..-1].join('/')}",
153
+ linkurl: logo.target_url }
139
154
  end
140
- logo_info
141
155
  end
142
156
 
143
157
  # A presenter for selecting a work type to create
@@ -158,14 +172,21 @@ module Hyrax
158
172
  create_work_presenter.first_model
159
173
  end
160
174
 
175
+ ##
176
+ # @deprecated this implementation requires an extra db round trip, had a
177
+ # buggy cacheing mechanism, and was largely duplicative of other code.
178
+ # all versions of this code are replaced by
179
+ # {CollectionsHelper#available_parent_collections_data}.
161
180
  def available_parent_collections(scope:)
181
+ Deprecation.warn("#{self.class}#available_parent_collections is " \
182
+ "deprecated. Use available_parent_collections_data " \
183
+ "helper instead.")
162
184
  return @available_parents if @available_parents.present?
163
185
  collection = ::Collection.find(id)
164
186
  colls = Hyrax::Collections::NestedCollectionQueryService.available_parent_collections(child: collection, scope: scope, limit_to_id: nil)
165
187
  @available_parents = colls.map do |col|
166
188
  { "id" => col.id, "title_first" => col.title.first }
167
- end
168
- @available_parents.to_json
189
+ end.to_json
169
190
  end
170
191
 
171
192
  def subcollection_count=(total)
@@ -57,8 +57,13 @@ module Hyrax
57
57
  current_ability.can?(:read, id) ? first_title : 'File'
58
58
  end
59
59
 
60
+ ##
61
+ # @deprecated use `::Ability.can?(:edit, presenter)`. Hyrax views calling
62
+ # presenter {#editor} methods will continue to call them until Hyrax
63
+ # 4.0.0. The deprecation time horizon for the presenter methods themselves
64
+ # is 5.0.0.
60
65
  def editor?
61
- current_ability.can?(:edit, solr_document)
66
+ current_ability.can?(:edit, self)
62
67
  end
63
68
 
64
69
  def tweeter
@@ -1,7 +1,8 @@
1
1
  # frozen_string_literal: true
2
- # Called by the stats controller, it finds cached file pageview data,
3
- # and prepares it for visualization in /app/views/stats/file.html.erb
4
2
  module Hyrax
3
+ ##
4
+ # Called by the stats controller, it finds cached file pageview data,
5
+ # and prepares it for visualization in /app/views/stats/file.html.erb
5
6
  class FileUsage < StatsUsagePresenter
6
7
  def initialize(id)
7
8
  self.model = ::FileSet.find(id)
@@ -0,0 +1,119 @@
1
+ # frozen_string_literal: true
2
+ module Hyrax
3
+ ##
4
+ # constructs presenters for the pcdm:members of an Object, omitting those
5
+ # not readable by a provided +Ability+.
6
+ #
7
+ # this implementation builds the presenters without recourse to the request
8
+ # context and ActiveFedora-specific index structures (i.e. no `list_source`
9
+ # or `proxy_in_ssi`).
10
+ #
11
+ # @see MemberPresenterFactory
12
+ class PcdmMemberPresenterFactory
13
+ class_attribute :file_presenter_class, :work_presenter_class
14
+ self.file_presenter_class = FileSetPresenter
15
+ self.work_presenter_class = WorkShowPresenter
16
+
17
+ attr_reader :ability, :object
18
+
19
+ ##
20
+ # @param [#member_ids] object
21
+ # @param [::Ability] ability
22
+ def initialize(object, ability)
23
+ @object = object
24
+ @ability = ability
25
+ end
26
+
27
+ ##
28
+ # @return [Array<FileSetPresenter, WorkShowPresenter>]
29
+ # @return [Enumerator<FileSetPresenter>]
30
+ def file_set_presenters
31
+ return enum_for(:file_set_presenters) unless block_given?
32
+
33
+ results = query_docs(generic_type: "FileSet")
34
+
35
+ object.member_ids.each do |id|
36
+ id = id.to_s
37
+ indx = results.index { |doc| id == doc['id'] }
38
+ next if indx.nil?
39
+ hash = results.delete_at(indx)
40
+ yield presenter_for(document: ::SolrDocument.new(hash), ability: ability)
41
+ end
42
+ end
43
+
44
+ ##
45
+ # @note defaults to using `object.member_ids`. passing a specific set of
46
+ # ids is supported for compatibility with {MemberPresenterFactory}, but
47
+ # we recommend making sparing use of this feature.
48
+ #
49
+ # @overload member_presenters
50
+ # @return [Enumerator<FileSetPresenter, WorkShowPresenter>]
51
+ # @raise [ArgumentError] if an unindexed id is passed
52
+ # @overload member_presenters
53
+ # @param [Array<#to_s>] ids
54
+ # @return [Enumerator<FileSetPresenter, WorkShowPresenter>]
55
+ # @raise [ArgumentError] if an unindexed id is passed
56
+ def member_presenters(ids = object.member_ids)
57
+ return enum_for(:member_presenters, ids) unless block_given?
58
+
59
+ results = query_docs(ids: ids)
60
+
61
+ ids.each do |id|
62
+ id = id.to_s
63
+ indx = results.index { |doc| id == doc['id'] }
64
+ raise(ArgumentError, "Could not find an indexed document for id: #{id}") if
65
+ indx.nil?
66
+ hash = results.delete_at(indx)
67
+ yield presenter_for(document: ::SolrDocument.new(hash), ability: ability)
68
+ end
69
+ end
70
+
71
+ ##
72
+ # @return [Array<#to_s>]
73
+ def ordered_ids
74
+ object.member_ids
75
+ end
76
+
77
+ ##
78
+ # @return [Array<WorkShowPresenter>]
79
+ def work_presenters
80
+ return enum_for(:work_presenters) unless block_given?
81
+
82
+ results = query_docs(generic_type: "Work")
83
+
84
+ object.member_ids.each do |id|
85
+ id = id.to_s
86
+ indx = results.index { |doc| id == doc['id'] }
87
+ next if indx.nil?
88
+ hash = results.delete_at(indx)
89
+ yield presenter_for(document: ::SolrDocument.new(hash), ability: ability)
90
+ end
91
+ end
92
+
93
+ ##
94
+ # @param [::SolrDocument] document
95
+ # @param [::Ability] ability
96
+ #
97
+ # @return
98
+ def presenter_for(document:, ability:)
99
+ case document['has_model_ssim'].first
100
+ when Hyrax::FileSet.name
101
+ Hyrax::FileSetPresenter.new(document, ability)
102
+ else
103
+ Hyrax::WorkShowPresenter.new(document, ability)
104
+ end
105
+ end
106
+
107
+ private
108
+
109
+ def query_docs(generic_type: nil, ids: object.member_ids)
110
+ query = "{!terms f=id}#{ids.join(',')}"
111
+ query += "{!term f=generic_type_si}#{generic_type}" if generic_type
112
+
113
+ Hyrax::SolrService
114
+ .post(query, rows: 10_000)
115
+ .fetch('response')
116
+ .fetch('docs')
117
+ end
118
+ end
119
+ end
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
  module Hyrax
3
- # Methods used by both WorkUsage and FileUsage
3
+ ##
4
+ # @abstract methods used by both {WorkUsage} and {FileUsage}
4
5
  class StatsUsagePresenter
5
6
  attr_accessor :id, :model
6
7
 
@@ -1,27 +1,56 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module Hyrax
4
+ ##
5
+ # @api public
6
+ #
7
+ # Presents works in context as "trophied" for a given user.
8
+ #
9
+ # @example
10
+ # my_user = User.find(user_id)
11
+ #
12
+ # trophies = Hyrax::TrophyPresenter.find_by_user(my_user)
13
+ # trophies.each do |trophy|
14
+ # puts "Object name/title: #{trophy}"
15
+ # puts "Thumbnail path: #{trophy.thumbnail_path}"
16
+ # end
3
17
  class TrophyPresenter
4
18
  include ModelProxy
19
+
20
+ ##
21
+ # @param solr_document [::SolrDocument]
5
22
  def initialize(solr_document)
6
23
  @solr_document = solr_document
7
24
  end
8
25
 
26
+ ##
27
+ # @!attribute [r] SolrDocument
28
+ # @return [::SolrDocument]
9
29
  attr_reader :solr_document
10
30
 
11
31
  delegate :to_s, :thumbnail_path, to: :solr_document
12
32
 
33
+ ##
13
34
  # @param user [User] the user to find the TrophyPresentes for.
35
+ #
14
36
  # @return [Array<TrophyPresenter>] a list of all the trophy presenters for the user
15
37
  def self.find_by_user(user)
16
- work_ids = user.trophies.pluck(:work_id)
17
- query = Hyrax::SolrQueryBuilderService.construct_query_for_ids(work_ids)
18
- results = Hyrax::WorkRelation.new.search_with_conditions(query)
19
- results.map { |result| TrophyPresenter.new(document_model.new(result)) }
38
+ ids = user.trophies.pluck(:work_id)
39
+ return ids if ids.empty?
40
+
41
+ documents = Hyrax::SolrQueryService.new.with_ids(ids: ids).solr_documents
42
+
43
+ documents.map { |doc| new(doc) }
20
44
  rescue RSolr::Error::ConnectionRefused
21
45
  []
22
46
  end
23
47
 
48
+ ##
49
+ # @api private
50
+ # @deprecated use CatalogController.blacklight_config.document_model instead
24
51
  def self.document_model
52
+ Deprecation
53
+ .warn("Use CatalogController.blacklight_config.document_model instead.")
25
54
  CatalogController.blacklight_config.document_model
26
55
  end
27
56
  private_class_method :document_model