hyrax 2.1.0 → 2.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (153) hide show
  1. checksums.yaml +5 -5
  2. data/.github/ISSUE_TEMPLATE.md +1 -1
  3. data/.github/PULL_REQUEST_TEMPLATE.md +5 -0
  4. data/.rubocop.yml +8 -1
  5. data/README.md +3 -11
  6. data/app/actors/hyrax/actors/file_set_actor.rb +6 -1
  7. data/app/assets/javascripts/hyrax.js +1 -1
  8. data/app/assets/javascripts/hyrax/editor.es6 +8 -0
  9. data/app/assets/javascripts/hyrax/save_work/save_work_control.es6 +20 -1
  10. data/app/assets/javascripts/hyrax/save_work/uploaded_files.es6 +1 -0
  11. data/app/assets/stylesheets/hyrax/_breadcrumbs.scss +25 -0
  12. data/app/assets/stylesheets/hyrax/_collections.scss +6 -0
  13. data/app/assets/stylesheets/hyrax/_file-listing.scss +5 -0
  14. data/app/assets/stylesheets/hyrax/_file_upload.scss +14 -0
  15. data/app/assets/stylesheets/hyrax/_form-progress.scss +6 -0
  16. data/app/assets/stylesheets/hyrax/_hyrax.scss +1 -1
  17. data/app/assets/stylesheets/hyrax/_styles.scss +6 -0
  18. data/app/assets/stylesheets/hyrax/dashboard.scss +4 -5
  19. data/app/builders/hyrax/bootstrap_breadcrumbs_builder.rb +10 -4
  20. data/app/controllers/concerns/hyrax/admin/stats_behavior.rb +25 -1
  21. data/app/controllers/concerns/hyrax/breadcrumbs_for_collections.rb +6 -2
  22. data/app/controllers/concerns/hyrax/controller.rb +1 -1
  23. data/app/controllers/concerns/hyrax/deny_access_override_behavior.rb +1 -1
  24. data/app/controllers/concerns/hyrax/works_controller_behavior.rb +1 -1
  25. data/app/controllers/hyrax/admin/admin_sets_controller.rb +1 -1
  26. data/app/controllers/hyrax/dashboard/collections_controller.rb +2 -2
  27. data/app/controllers/hyrax/downloads_controller.rb +1 -1
  28. data/app/controllers/hyrax/featured_works_controller.rb +1 -5
  29. data/app/controllers/hyrax/homepage_controller.rb +1 -1
  30. data/app/controllers/hyrax/single_use_links_controller.rb +1 -1
  31. data/app/controllers/hyrax/transfers_controller.rb +1 -1
  32. data/app/controllers/hyrax/users_controller.rb +1 -0
  33. data/app/helpers/hyrax/citations_behaviors/publication_behavior.rb +2 -2
  34. data/app/helpers/hyrax/collections_helper.rb +1 -1
  35. data/app/helpers/hyrax/hyrax_helper_behavior.rb +2 -2
  36. data/app/jobs/characterize_job.rb +1 -1
  37. data/app/jobs/fixity_check_job.rb +1 -1
  38. data/app/jobs/import_url_job.rb +12 -1
  39. data/app/models/checksum_audit_log.rb +1 -1
  40. data/app/models/concerns/hyrax/ability.rb +1 -1
  41. data/app/models/hyrax/collection_type.rb +1 -1
  42. data/app/models/hyrax/operation.rb +4 -6
  43. data/app/models/hyrax/permission_template_access.rb +5 -5
  44. data/app/models/sipity/entity.rb +1 -1
  45. data/app/presenters/hyrax/admin_set_presenter.rb +9 -2
  46. data/app/presenters/hyrax/admin_stats_presenter.rb +52 -6
  47. data/app/presenters/hyrax/inspect_work_presenter.rb +1 -1
  48. data/app/presenters/hyrax/workflow_presenter.rb +1 -1
  49. data/app/search_builders/hyrax/dashboard/nested_collections_search_builder.rb +3 -5
  50. data/app/search_builders/hyrax/filter_suppressed_with_roles.rb +5 -1
  51. data/app/search_builders/hyrax/my/works_search_builder.rb +2 -1
  52. data/app/services/hyrax/collection_size_service.rb +12 -0
  53. data/app/services/hyrax/collections/nested_collection_query_service.rb +2 -2
  54. data/app/services/hyrax/graph_exporter.rb +6 -1
  55. data/app/services/hyrax/license_service.rb +1 -9
  56. data/app/services/hyrax/qa_select_service.rb +28 -0
  57. data/app/services/hyrax/rights_statement_service.rb +1 -1
  58. data/app/services/hyrax/tolerant_select_service.rb +23 -0
  59. data/app/services/hyrax/workflow/permission_query.rb +1 -1
  60. data/app/services/hyrax/workflow/sipity_actions_generator.rb +1 -1
  61. data/app/strategies/hyrax/strategies/yaml_strategy.rb +1 -1
  62. data/app/views/_logo.html.erb +1 -1
  63. data/app/views/catalog/_search_form.html.erb +1 -1
  64. data/app/views/hyrax/admin/collection_types/index.html.erb +1 -1
  65. data/app/views/hyrax/admin/workflow_roles/index.html.erb +4 -2
  66. data/app/views/hyrax/admin/workflows/index.html.erb +1 -1
  67. data/app/views/hyrax/base/_form_files.html.erb +7 -7
  68. data/app/views/hyrax/base/_form_progress.html.erb +10 -5
  69. data/app/views/hyrax/base/_share_with.html.erb +3 -11
  70. data/app/views/hyrax/base/_show_actions.html.erb +1 -3
  71. data/app/views/hyrax/batch_edits/_check_all.html.erb +15 -7
  72. data/app/views/hyrax/collections/_list_collections.html.erb +1 -1
  73. data/app/views/hyrax/dashboard/_index_partials/_transfers.html.erb +1 -1
  74. data/app/views/hyrax/dashboard/collections/_default_group.html.erb +7 -2
  75. data/app/views/hyrax/dashboard/collections/_edit_actions.html.erb +1 -2
  76. data/app/views/hyrax/dashboard/collections/_form.html.erb +1 -1
  77. data/app/views/hyrax/dashboard/collections/_form_branding.html.erb +6 -6
  78. data/app/views/hyrax/dashboard/collections/_list_collections.html.erb +1 -1
  79. data/app/views/hyrax/dashboard/collections/_show_actions.html.erb +1 -2
  80. data/app/views/hyrax/dashboard/collections/_show_add_items_actions.html.erb +1 -2
  81. data/app/views/hyrax/dashboard/sidebar/_repository_content.html.erb +1 -2
  82. data/app/views/hyrax/dashboard/works/_default_group.html.erb +1 -1
  83. data/app/views/hyrax/file_sets/_actions.html.erb +1 -1
  84. data/app/views/hyrax/file_sets/_form.html.erb +3 -3
  85. data/app/views/hyrax/file_sets/_permission.html.erb +2 -2
  86. data/app/views/hyrax/file_sets/_permission_form.html.erb +10 -10
  87. data/app/views/hyrax/file_sets/_show_actions.html.erb +1 -4
  88. data/app/views/hyrax/file_sets/_single_use_links.html.erb +5 -0
  89. data/app/views/hyrax/file_sets/_versioning.html.erb +9 -7
  90. data/app/views/hyrax/file_sets/edit.html.erb +6 -6
  91. data/app/views/hyrax/file_sets/media_display/_audio.html.erb +1 -1
  92. data/app/views/hyrax/file_sets/media_display/_image.html.erb +1 -1
  93. data/app/views/hyrax/file_sets/media_display/_office_document.html.erb +0 -1
  94. data/app/views/hyrax/file_sets/media_display/_pdf.html.erb +0 -1
  95. data/app/views/hyrax/file_sets/media_display/_video.html.erb +1 -1
  96. data/app/views/hyrax/my/collections/_default_group.html.erb +8 -3
  97. data/app/views/hyrax/my/collections/_list_collections.html.erb +1 -1
  98. data/app/views/hyrax/my/works/_batch_actions.html.erb +1 -1
  99. data/app/views/hyrax/my/works/_tabs.html.erb +3 -3
  100. data/app/views/hyrax/single_use_links_viewer/show.html.erb +1 -1
  101. data/app/views/hyrax/uploads/_js_templates.html.erb +11 -11
  102. data/app/views/hyrax/uploads/_js_templates_branding.html.erb +2 -2
  103. data/app/views/layouts/_head_tag_content.html.erb +1 -1
  104. data/app/views/layouts/hyrax.html.erb +1 -1
  105. data/app/views/layouts/hyrax/dashboard.html.erb +1 -1
  106. data/app/views/records/edit_fields/_license.html.erb +1 -1
  107. data/app/views/records/edit_fields/_rights_statement.html.erb +2 -1
  108. data/config/features.rb +4 -0
  109. data/config/locales/hyrax.de.yml +1 -0
  110. data/config/locales/hyrax.en.yml +39 -1
  111. data/config/locales/hyrax.es.yml +1 -0
  112. data/config/locales/hyrax.fr.yml +1 -0
  113. data/config/locales/hyrax.it.yml +1 -0
  114. data/config/locales/hyrax.pt-BR.yml +1 -0
  115. data/config/locales/hyrax.zh.yml +1 -0
  116. data/hyrax.gemspec +5 -2
  117. data/lib/generators/hyrax/templates/mediated_deposit_workflow.json.erb +1 -0
  118. data/lib/hyrax.rb +7 -1
  119. data/lib/hyrax/arkivo/create_subscription_job.rb +1 -1
  120. data/lib/hyrax/redis_event_store.rb +1 -1
  121. data/lib/hyrax/resource_sync/change_list_writer.rb +2 -2
  122. data/lib/hyrax/version.rb +1 -1
  123. data/spec/actors/hyrax/actors/file_set_actor_spec.rb +1 -1
  124. data/spec/controllers/hyrax/admin/stats_controller_spec.rb +31 -1
  125. data/spec/controllers/hyrax/collections_controller_spec.rb +2 -2
  126. data/spec/controllers/hyrax/dashboard/collections_controller_spec.rb +2 -2
  127. data/spec/controllers/hyrax/generic_works_controller_spec.rb +19 -3
  128. data/spec/controllers/hyrax/homepage_controller_spec.rb +1 -1
  129. data/spec/controllers/hyrax/users_controller_spec.rb +58 -0
  130. data/spec/features/batch_create_spec.rb +1 -1
  131. data/spec/features/create_work_spec.rb +22 -2
  132. data/spec/features/dashboard/collection_spec.rb +3 -3
  133. data/spec/features/homepage_spec.rb +20 -4
  134. data/spec/javascripts/save_work_spec.js +50 -0
  135. data/spec/jobs/import_url_job_spec.rb +10 -8
  136. data/spec/lib/hyrax_spec.rb +9 -0
  137. data/spec/models/flipflop_spec.rb +8 -0
  138. data/spec/models/solr_document_spec.rb +2 -2
  139. data/spec/presenters/hyrax/admin_stats_presenter_spec.rb +73 -0
  140. data/spec/search_builders/hyrax/my/works_search_builder_spec.rb +0 -2
  141. data/spec/services/hyrax/graph_exporter_spec.rb +18 -0
  142. data/spec/services/hyrax/qa_select_service_spec.rb +40 -17
  143. data/spec/services/hyrax/tolerant_select_service_spec.rb +80 -0
  144. data/spec/support/fakes/fake_authority.rb +13 -0
  145. data/spec/support/logging_formatter.rb +1 -1
  146. data/spec/support/matchers/collection_type_property_matchers.rb +5 -5
  147. data/spec/views/hyrax/base/_form_progress.html.erb_spec.rb +11 -1
  148. data/spec/views/hyrax/file_sets/_show_actions.html.erb_spec.rb +0 -1
  149. data/spec/views/hyrax/file_sets/_single_use_links.html.erb_spec.rb +4 -0
  150. data/spec/views/hyrax/single_use_links_viewer/show.html.erb_spec.rb +0 -4
  151. data/template.rb +1 -1
  152. metadata +24 -11
  153. data/app/views/kaminari/blacklight_compact/_paginator.html.erb +0 -22
@@ -206,7 +206,7 @@ module Hyrax
206
206
 
207
207
  def document_not_found!
208
208
  doc = ::SolrDocument.find(params[:id])
209
- raise WorkflowAuthorizationException if doc.suppressed?
209
+ raise WorkflowAuthorizationException if doc.suppressed? && current_ability.can?(:read, doc)
210
210
  raise CanCan::AccessDenied.new(nil, :show)
211
211
  end
212
212
 
@@ -25,7 +25,7 @@ module Hyrax
25
25
  self.admin_set_create_service = AdminSetCreateService
26
26
 
27
27
  def deny_adminset_access(exception)
28
- if current_user && current_user.persisted?
28
+ if current_user&.persisted?
29
29
  redirect_to root_url, alert: exception.message
30
30
  else
31
31
  session['user_return_to'] = request.url
@@ -42,7 +42,7 @@ module Hyrax
42
42
  def deny_collection_access(exception)
43
43
  if exception.action == :edit
44
44
  redirect_to(url_for(action: 'show'), alert: 'You do not have sufficient privileges to edit this document')
45
- elsif current_user && current_user.persisted?
45
+ elsif current_user&.persisted?
46
46
  redirect_to root_url, alert: exception.message
47
47
  else
48
48
  session['user_return_to'] = request.url
@@ -242,7 +242,7 @@ module Hyrax
242
242
 
243
243
  def remove_banner
244
244
  banner_info = CollectionBrandingInfo.where(collection_id: @collection.id.to_s).where(role: "banner")
245
- banner_info.delete_all unless banner_info.nil?
245
+ banner_info&.delete_all
246
246
  end
247
247
 
248
248
  def update_logo_info(uploaded_file_id, alttext, linkurl)
@@ -76,7 +76,7 @@ module Hyrax
76
76
  DownloadsController.default_content_path
77
77
  end
78
78
  association = dereference_file(default_file_reference)
79
- association.reader if association
79
+ association&.reader
80
80
  end
81
81
 
82
82
  def mime_type_for(file)
@@ -16,11 +16,7 @@ module Hyrax
16
16
  def destroy
17
17
  authorize! :destroy, FeaturedWork
18
18
  @featured_work = FeaturedWork.find_by(work_id: params[:id])
19
- if @featured_work
20
- # Handle the case where a separate request may have already
21
- # destroyed this work
22
- @featured_work.destroy
23
- end
19
+ @featured_work&.destroy
24
20
 
25
21
  respond_to do |format|
26
22
  format.json { head :no_content }
@@ -44,6 +44,6 @@ class Hyrax::HomepageController < ApplicationController
44
44
  end
45
45
 
46
46
  def sort_field
47
- "#{Solrizer.solr_name('system_create', :stored_sortable, type: :date)} desc"
47
+ "#{Solrizer.solr_name('date_uploaded', :stored_sortable, type: :date)} desc"
48
48
  end
49
49
  end
@@ -9,7 +9,7 @@ module Hyrax
9
9
  rescue_from Hydra::AccessDenied, CanCan::AccessDenied, with: :deny_link_access
10
10
 
11
11
  def deny_link_access(exception)
12
- if current_user && current_user.persisted?
12
+ if current_user&.persisted?
13
13
  redirect_to main_app.root_url, alert: "You do not have sufficient privileges to create links to this document"
14
14
  else
15
15
  session["user_return_to"] = request.url
@@ -10,7 +10,7 @@ module Hyrax
10
10
  # Catch permission errors
11
11
  # TODO: Isn't this already handled?
12
12
  rescue_from CanCan::AccessDenied do |exception|
13
- if current_user && current_user.persisted?
13
+ if current_user&.persisted?
14
14
  redirect_to root_url, alert: exception.message
15
15
  else
16
16
  session["user_return_to"] = request.url
@@ -6,6 +6,7 @@ module Hyrax
6
6
  helper Hyrax::TrophyHelper
7
7
 
8
8
  def index
9
+ authenticate_user! if Flipflop.hide_users_list?
9
10
  @users = search(params[:uq])
10
11
  end
11
12
 
@@ -14,11 +14,11 @@ module Hyrax
14
14
 
15
15
  # @param [Hyrax::WorkShowPresenter] work_presenter
16
16
  def setup_pub_place(work_presenter)
17
- work_presenter.based_near_label.first if work_presenter.based_near_label
17
+ work_presenter.based_near_label&.first
18
18
  end
19
19
 
20
20
  def setup_pub_publisher(work)
21
- work.publisher.first if work.publisher
21
+ work.publisher&.first
22
22
  end
23
23
 
24
24
  def setup_pub_info(work, include_date = false)
@@ -11,7 +11,7 @@ module Hyrax
11
11
  def render_collection_links(solr_doc)
12
12
  collection_list = Hyrax::CollectionMemberService.run(solr_doc, controller.current_ability)
13
13
  return if collection_list.empty?
14
- links = collection_list.map { |collection| link_to collection.title_or_label, collection_path(collection.id) }
14
+ links = collection_list.map { |collection| link_to collection.title_or_label, hyrax.collection_path(collection.id) }
15
15
  collection_links = []
16
16
  links.each_with_index do |link, n|
17
17
  collection_links << link
@@ -201,7 +201,7 @@ module Hyrax
201
201
  # @param [Hash] options from blacklight helper_method invocation. Maps license URIs to links with labels.
202
202
  # @return [ActiveSupport::SafeBuffer] license links, html_safe
203
203
  def license_links(options)
204
- service = Hyrax::LicenseService.new
204
+ service = Hyrax.config.license_service_class.new
205
205
  to_sentence(options[:value].map { |right| link_to service.label(right), right })
206
206
  end
207
207
 
@@ -209,7 +209,7 @@ module Hyrax
209
209
  # @param [Hash] options from blacklight helper_method invocation. Maps rights statement URIs to links with labels.
210
210
  # @return [ActiveSupport::SafeBuffer] rights statement links, html_safe
211
211
  def rights_statement_links(options)
212
- service = Hyrax::RightsStatementService.new
212
+ service = Hyrax.config.rights_statement_service_class.new
213
213
  to_sentence(options[:value].map { |right| link_to service.label(right), right })
214
214
  end
215
215
 
@@ -13,7 +13,7 @@ class CharacterizeJob < Hyrax::ApplicationJob
13
13
  Rails.logger.debug "Ran characterization on #{file_set.characterization_proxy.id} (#{file_set.characterization_proxy.mime_type})"
14
14
  file_set.characterization_proxy.save!
15
15
  file_set.update_index
16
- file_set.parent.in_collections.each(&:update_index) if file_set.parent
16
+ file_set.parent&.in_collections&.each(&:update_index)
17
17
  CreateDerivativesJob.perform_later(file_set, file_id, filepath)
18
18
  end
19
19
  end
@@ -58,6 +58,6 @@ class FixityCheckJob < Hyrax::ApplicationJob
58
58
  end
59
59
 
60
60
  def logger
61
- ActiveFedora::Base.logger
61
+ Hyrax.logger
62
62
  end
63
63
  end
@@ -24,7 +24,7 @@ class ImportUrlJob < Hyrax::ApplicationJob
24
24
  @file_set = file_set
25
25
  @operation = operation
26
26
 
27
- unless HTTParty.head(file_set.import_url).success?
27
+ unless can_retrieve?(uri)
28
28
  send_error('Expired URL')
29
29
  return false
30
30
  end
@@ -44,6 +44,17 @@ class ImportUrlJob < Hyrax::ApplicationJob
44
44
 
45
45
  private
46
46
 
47
+ # The previous strategy of using only a HEAD request to check the validity of a
48
+ # remote URL fails for Amazon S3 pre-signed URLs. S3 URLs are generated for a single
49
+ # verb only (in this case, GET), and will return a 403 Forbidden response if any
50
+ # other verb is used. The workaround is to issue a GET request instead, with a
51
+ # Range: header requesting only the first byte. The successful response status
52
+ # code is 206 instead of 200, but that is enough to satisfy the #success? method.
53
+ # @param uri [URI] the uri of the file to be downloaded
54
+ def can_retrieve?(uri)
55
+ HTTParty.get(uri, headers: { Range: 'bytes=0-0' }).success?
56
+ end
57
+
47
58
  # Download file from uri, yields a block with a file in a temporary directory.
48
59
  # It is important that the file on disk has the same file name as the URL,
49
60
  # because when the file in added into Fedora the file name will get persisted in the
@@ -51,7 +51,7 @@ class ChecksumAuditLog < ActiveRecord::Base
51
51
 
52
52
  0.upto(all_logs.length - 2).each do |i|
53
53
  next if all_logs[i].failed?
54
- next if i > 0 && all_logs[i - 1].failed?
54
+ next if i.positive? && all_logs[i - 1].failed?
55
55
  next if all_logs[i + 1].failed?
56
56
 
57
57
  all_logs[i].destroy!
@@ -75,7 +75,7 @@ module Hyrax
75
75
  .joins(:permission_template)
76
76
  .pluck('DISTINCT source_id')
77
77
  query = "_query_:\"{!raw f=has_model_ssim}AdminSet\" AND {!terms f=id}#{ids.join(',')}"
78
- ActiveFedora::SolrService.count(query) > 0
78
+ ActiveFedora::SolrService.count(query).positive?
79
79
  end
80
80
 
81
81
  # This overrides hydra-head, (and restores the method from blacklight-access-controls)
@@ -66,7 +66,7 @@ module Hyrax
66
66
 
67
67
  # @return [Boolean] True if there is at least one collection of this type
68
68
  def collections?
69
- collections.count > 0
69
+ collections.count.positive?
70
70
  end
71
71
 
72
72
  # @return [Boolean] True if this is the Admin Set type
@@ -45,10 +45,8 @@ module Hyrax
45
45
  def rollup_messages
46
46
  [].tap do |messages|
47
47
  messages << message if message.present?
48
- if children
49
- children.pluck(:message).uniq.each do |child_message|
50
- messages << child_message if child_message.present?
51
- end
48
+ children&.pluck(:message)&.uniq&.each do |child_message|
49
+ messages << child_message if child_message.present?
52
50
  end
53
51
  end
54
52
  end
@@ -63,7 +61,7 @@ module Hyrax
63
61
  def success!
64
62
  run_callbacks :success do
65
63
  update(status: SUCCESS)
66
- parent.rollup_status if parent
64
+ parent&.rollup_status
67
65
  end
68
66
  end
69
67
 
@@ -78,7 +76,7 @@ module Hyrax
78
76
  def fail!(message = nil)
79
77
  run_callbacks :failure do
80
78
  update(status: FAILURE, message: message)
81
- parent.rollup_status if parent
79
+ parent&.rollup_status
82
80
  end
83
81
  end
84
82
 
@@ -11,12 +11,12 @@ module Hyrax
11
11
  scope: [:agent_id, :agent_type, :permission_template_id]
12
12
  }
13
13
 
14
- VIEW = 'view'.freeze
15
- DEPOSIT = 'deposit'.freeze
16
- MANAGE = 'manage'.freeze
14
+ VIEW = 'view'
15
+ DEPOSIT = 'deposit'
16
+ MANAGE = 'manage'
17
17
 
18
- GROUP = 'group'.freeze
19
- USER = 'user'.freeze
18
+ GROUP = 'group'
19
+ USER = 'user'
20
20
 
21
21
  enum(
22
22
  access: {
@@ -28,7 +28,7 @@ module Sipity
28
28
  class_name: 'Sipity::Comment'
29
29
 
30
30
  def workflow_state_name
31
- workflow_state.name if workflow_state
31
+ workflow_state&.name
32
32
  end
33
33
 
34
34
  # Defines the method #workflow_name
@@ -1,5 +1,11 @@
1
1
  module Hyrax
2
2
  class AdminSetPresenter < CollectionPresenter
3
+ ##
4
+ # @return [Boolean] true if there are items
5
+ def any_items?
6
+ total_items.positive?
7
+ end
8
+
3
9
  def total_items
4
10
  ActiveFedora::SolrService.count("{!field f=isPartOf_ssim}#{id}")
5
11
  end
@@ -10,13 +16,14 @@ module Hyrax
10
16
 
11
17
  # AdminSet cannot be deleted if default set or non-empty
12
18
  def disable_delete?
13
- AdminSet.default_set?(id) || total_items > 0
19
+ AdminSet.default_set?(id) || any_items?
14
20
  end
15
21
 
16
22
  # Message to display if deletion is disabled
17
23
  def disabled_message
18
24
  return I18n.t('hyrax.admin.admin_sets.delete.error_default_set') if AdminSet.default_set?(id)
19
- return I18n.t('hyrax.admin.admin_sets.delete.error_not_empty') if total_items > 0
25
+
26
+ I18n.t('hyrax.admin.admin_sets.delete.error_not_empty') if any_items?
20
27
  end
21
28
 
22
29
  def collection_type
@@ -2,10 +2,49 @@ module Hyrax
2
2
  class AdminStatsPresenter
3
3
  attr_reader :limit, :stats_filters
4
4
 
5
- def initialize(stats_filters, limit)
5
+ ##
6
+ # @!attribute [rw] by_depositor
7
+ # @return [#query]
8
+ # @!attribute [rw] by_format
9
+ # @return [#query]
10
+ # @!attribute [rw] depositor_summary
11
+ # @return [#depositors]
12
+ # @!attribute [rw] system_stats
13
+ # @return [#recent_users]
14
+ # @!attribute [rw] works_counter
15
+ # @return [#by_permission]
16
+ attr_accessor :by_depositor, :by_format, :depositor_summary, :system_stats,
17
+ :works_counter
18
+
19
+ # Long parameter lists (especially optional) are preferred to hard-coded
20
+ # dependencies. Further refactors may be desirable.
21
+ #
22
+ # rubocop:disable Metrics/ParameterLists
23
+
24
+ ##
25
+ # @param stats_filters [Hash<Symbol, Object>]
26
+ # @param limit [FixNum]
27
+ # @param by_depositor [#query]
28
+ # @param by_format [#query]
29
+ # @param depositor_summary [#depositors]
30
+ # @param system_stats [#recent_users]
31
+ # @param works_counter [#by_permission]
32
+ def initialize(stats_filters, limit,
33
+ by_depositor: Hyrax::Statistics::Works::ByDepositor,
34
+ by_format: Hyrax::Statistics::FileSets::ByFormat,
35
+ depositor_summary: Hyrax::Statistics::Depositors::Summary,
36
+ system_stats: Hyrax::Statistics::SystemStats,
37
+ works_counter: Hyrax::Statistics::Works::Count)
6
38
  @stats_filters = stats_filters
7
39
  @limit = limit
40
+
41
+ self.by_depositor = by_depositor
42
+ self.by_format = by_format
43
+ self.depositor_summary = depositor_summary
44
+ self.system_stats = system_stats
45
+ self.works_counter = works_counter
8
46
  end
47
+ # rubocop:enable Metrics/ParameterLists
9
48
 
10
49
  def start_date
11
50
  @start_date ||= extract_date_from_stats_filters(key: :start_date, as_of: :beginning_of_day)
@@ -26,29 +65,36 @@ module Hyrax
26
65
 
27
66
  # @see Hyrax::Statistics::Depositors::Summary
28
67
  def depositors
29
- @depositors ||= Hyrax::Statistics::Depositors::Summary.depositors(start_date: start_date, end_date: end_date)
68
+ @depositors ||=
69
+ depositor_summary.depositors(start_date: start_date, end_date: end_date)
30
70
  end
31
71
 
32
72
  # @see Hyrax::Statistics::SystemStats.recent_users
33
73
  def recent_users
34
- @recent_users ||= Hyrax::Statistics::SystemStats.recent_users(limit: limit, start_date: start_date, end_date: end_date)
74
+ @recent_users ||=
75
+ system_stats.recent_users(limit: limit,
76
+ start_date: start_date,
77
+ end_date: end_date)
35
78
  end
36
79
 
37
80
  # @see Hyrax::Statistics::Works::ByDepositor
38
81
  def active_users
39
- @active_users ||= Hyrax::Statistics::Works::ByDepositor.query(limit: limit)
82
+ @active_users ||= by_depositor.query(limit: limit)
40
83
  end
41
84
 
42
85
  # @see Hyrax::Statistics::FileSets::ByFormat
43
86
  def top_formats
44
- @top_formats ||= Hyrax::Statistics::FileSets::ByFormat.query(limit: limit)
87
+ @top_formats ||= by_format.query(limit: limit)
45
88
  end
46
89
 
47
90
  # @see Hyrax::Statistics::Works::Count
48
91
  def works_count
49
- @works_count ||= Hyrax::Statistics::Works::Count.by_permission(start_date: start_date, end_date: end_date)
92
+ @works_count ||=
93
+ works_counter.by_permission(start_date: start_date, end_date: end_date)
50
94
  end
51
95
 
96
+ ##
97
+ # @return [String]
52
98
  def date_filter_string
53
99
  if start_date.blank?
54
100
  "unfiltered"
@@ -43,7 +43,7 @@ module Hyrax
43
43
  end
44
44
 
45
45
  def workflow_comments
46
- return [] unless sipity_entity && sipity_entity.comments.count > 0
46
+ return [] unless sipity_entity&.comments&.any?
47
47
  sipity_entity.comments.map do |comment|
48
48
  { comment: comment.comment, created_at: comment.created_at }
49
49
  end
@@ -10,7 +10,7 @@ module Hyrax
10
10
  attr_reader :solr_document, :current_ability
11
11
 
12
12
  def state
13
- sipity_entity.workflow_state_name if sipity_entity
13
+ sipity_entity&.workflow_state_name
14
14
  end
15
15
 
16
16
  def state_label
@@ -100,11 +100,9 @@ module Hyrax
100
100
  array_to_exclude += @nesting_attributes.ancestors unless @nesting_attributes.ancestors.nil?
101
101
  # build a unique string containing all of Collection F's pathnames and ancestors
102
102
  exclude_list = ""
103
- unless array_to_exclude.nil?
104
- array_to_exclude.uniq.each do |element|
105
- exclude_list += ' ' unless exclude_list.empty?
106
- exclude_list += element.to_s
107
- end
103
+ array_to_exclude&.uniq&.each do |element|
104
+ exclude_list += ' ' unless exclude_list.empty?
105
+ exclude_list += element.to_s
108
106
  end
109
107
  # Using a !lucene query allows us to get items which match any individual element
110
108
  # from the list. Building the query via the AF builder created a !field query which
@@ -31,7 +31,11 @@ module Hyrax
31
31
  end
32
32
 
33
33
  def depositor?
34
- current_work[DepositSearchBuilder.depositor_field].first == current_ability.current_user.user_key
34
+ depositors = current_work[DepositSearchBuilder.depositor_field]
35
+
36
+ return false if depositors.nil?
37
+
38
+ depositors.first == current_ability.current_user.user_key
35
39
  end
36
40
  end
37
41
  end