hyrax 4.0.0.rc3 → 5.0.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (168) hide show
  1. checksums.yaml +4 -4
  2. data/.circleci/config.yml +116 -231
  3. data/.dassie/.env +3 -1
  4. data/.dassie/Gemfile +0 -2
  5. data/.dassie/config/analytics.yml +2 -2
  6. data/.dassie/config/environments/test.rb +1 -0
  7. data/.dassie/config/initializers/hyrax.rb +3 -1
  8. data/.dassie/config/initializers/redis_config.rb +0 -1
  9. data/.dassie/config/initializers/riiif.rb +13 -3
  10. data/.dassie/db/schema.rb +2 -2
  11. data/.dockerignore +6 -0
  12. data/.github/ISSUE_TEMPLATE.md +14 -9
  13. data/.github/PULL_REQUEST_TEMPLATE.md +25 -6
  14. data/.github/release.yml +5 -2
  15. data/.koppie/.env +3 -0
  16. data/.koppie/Gemfile +0 -2
  17. data/.koppie/README.md +11 -11
  18. data/.koppie/app/forms/collection_resource_form.rb +1 -0
  19. data/.koppie/app/indexers/collection_resource_indexer.rb +1 -0
  20. data/.koppie/app/models/collection_resource.rb +1 -0
  21. data/.koppie/config/analytics.yml +1 -0
  22. data/.koppie/config/environments/test.rb +1 -0
  23. data/.koppie/config/initializers/hyrax.rb +8 -2
  24. data/.koppie/config/initializers/redis_config.rb +0 -1
  25. data/.koppie/config/initializers/riiif.rb +13 -4
  26. data/.koppie/config/metadata/collection_resource.yaml +1 -128
  27. data/.koppie/yarn.lock +23 -23
  28. data/.regen +1 -1
  29. data/CONTAINERS.md +15 -15
  30. data/Dockerfile +6 -11
  31. data/app/actors/hyrax/actors/base_actor.rb +4 -3
  32. data/app/actors/hyrax/actors/embargo_actor.rb +5 -2
  33. data/app/actors/hyrax/actors/lease_actor.rb +5 -2
  34. data/app/assets/javascripts/hyrax/file_manager/sorting.es6 +3 -2
  35. data/app/controllers/concerns/hyrax/embargoes_controller_behavior.rb +1 -1
  36. data/app/controllers/concerns/hyrax/valkyrie_downloads_controller_behavior.rb +74 -0
  37. data/app/controllers/concerns/hyrax/works_controller_behavior.rb +14 -5
  38. data/app/controllers/hyrax/admin/workflows_controller.rb +48 -3
  39. data/app/controllers/hyrax/batch_edits_controller.rb +33 -4
  40. data/app/controllers/hyrax/downloads_controller.rb +8 -1
  41. data/app/controllers/hyrax/file_sets_controller.rb +1 -0
  42. data/app/forms/hyrax/forms/file_set_edit_form.rb +1 -1
  43. data/app/forms/hyrax/forms/permission_template_form.rb +2 -0
  44. data/app/forms/hyrax/forms/resource_batch_edit_form.rb +90 -0
  45. data/app/forms/hyrax/forms/work_embargo_form.rb +1 -0
  46. data/app/forms/hyrax/forms/work_form.rb +1 -1
  47. data/app/forms/hyrax/forms/work_lease_form.rb +1 -0
  48. data/app/helpers/hyrax/dashboard_helper_behavior.rb +17 -9
  49. data/app/helpers/hyrax/membership_helper.rb +13 -1
  50. data/app/helpers/hyrax/work_form_helper.rb +0 -107
  51. data/app/indexers/hyrax/file_set_indexer.rb +6 -0
  52. data/app/indexers/hyrax/pcdm_collection_indexer.rb +8 -0
  53. data/app/indexers/hyrax/valkyrie_file_set_indexer.rb +41 -5
  54. data/app/indexers/hyrax/valkyrie_work_indexer.rb +8 -2
  55. data/app/jobs/valkyrie_create_derivatives_job.rb +8 -7
  56. data/app/jobs/valkyrie_ingest_job.rb +0 -1
  57. data/app/models/admin_set.rb +1 -31
  58. data/app/models/concerns/hyrax/file_set/derivatives.rb +3 -2
  59. data/app/models/concerns/hyrax/solr_document_behavior.rb +1 -1
  60. data/app/models/hyrax/collection_type.rb +5 -14
  61. data/app/models/hyrax/file_metadata.rb +6 -7
  62. data/app/models/hyrax/file_set.rb +8 -0
  63. data/app/models/hyrax/resource.rb +30 -2
  64. data/app/presenters/hyrax/file_set_presenter.rb +6 -0
  65. data/app/presenters/hyrax/iiif_manifest_presenter.rb +3 -7
  66. data/app/presenters/hyrax/presenter_renderer.rb +0 -7
  67. data/app/presenters/hyrax/work_show_presenter.rb +6 -11
  68. data/app/search_builders/hyrax/file_set_search_builder.rb +1 -1
  69. data/app/search_builders/hyrax/valkyrie_abstract_type_relation.rb +37 -0
  70. data/app/search_builders/hyrax/valkyrie_work_relation.rb +9 -0
  71. data/app/services/hyrax/analytics/google.rb +23 -15
  72. data/app/services/hyrax/analytics/matomo.rb +4 -3
  73. data/app/services/hyrax/characterization/valkyrie_characterization_service.rb +11 -9
  74. data/app/services/hyrax/custom_queries/find_by_date_range.rb +55 -0
  75. data/app/services/hyrax/custom_queries/find_count_by.rb +62 -0
  76. data/app/services/hyrax/custom_queries/find_file_metadata.rb +1 -1
  77. data/app/services/hyrax/custom_queries/find_models_by_access.rb +59 -0
  78. data/app/services/hyrax/derivative_bucketed_storage.rb +25 -0
  79. data/app/services/hyrax/derivative_path.rb +14 -4
  80. data/app/services/hyrax/embargo_manager.rb +76 -10
  81. data/app/services/hyrax/file_set_derivatives_service.rb +3 -2
  82. data/app/services/hyrax/lease_manager.rb +88 -8
  83. data/app/services/hyrax/listeners/file_metadata_listener.rb +2 -2
  84. data/app/services/hyrax/listeners/workflow_listener.rb +8 -11
  85. data/app/services/hyrax/persist_directly_contained_output_file_service.rb +24 -2
  86. data/app/services/hyrax/solr_query_service.rb +7 -6
  87. data/app/services/hyrax/statistics/depositors/summary.rb +1 -1
  88. data/app/services/hyrax/statistics/over_time.rb +1 -1
  89. data/app/services/hyrax/statistics/users/over_time.rb +3 -1
  90. data/app/services/hyrax/statistics/valkyrie_query_service.rb +49 -0
  91. data/app/services/hyrax/statistics/works/count.rb +1 -1
  92. data/app/services/hyrax/thumbnail_path_service.rb +5 -0
  93. data/app/services/hyrax/valkyrie_persist_derivatives.rb +16 -11
  94. data/app/services/hyrax/valkyrie_upload.rb +5 -3
  95. data/app/services/hyrax/versioning_service.rb +1 -0
  96. data/app/services/hyrax/visibility_intention.rb +1 -4
  97. data/app/services/hyrax/visibility_propagator.rb +1 -1
  98. data/app/services/hyrax/workflow/actionable_objects.rb +28 -3
  99. data/app/services/hyrax/workflow/grant_edit_to_depositor.rb +1 -1
  100. data/app/services/hyrax/workflow/grant_read_to_depositor.rb +1 -1
  101. data/app/services/hyrax/workflow/permission_query.rb +23 -2
  102. data/app/views/hyrax/admin/workflows/_tabs.html.erb +9 -0
  103. data/app/views/hyrax/admin/workflows/index.html.erb +53 -76
  104. data/app/views/hyrax/base/_file_manager_members.html.erb +2 -2
  105. data/app/views/hyrax/base/_form.html.erb +0 -10
  106. data/app/views/hyrax/base/_form_files.html.erb +7 -2
  107. data/app/views/hyrax/base/_form_permission_embargo.html.erb +1 -1
  108. data/app/views/hyrax/base/_form_permission_lease.html.erb +1 -1
  109. data/app/views/hyrax/base/_form_visibility_component.html.erb +2 -2
  110. data/app/views/hyrax/base/_items.html.erb +1 -1
  111. data/app/views/hyrax/base/file_manager.html.erb +1 -1
  112. data/app/views/hyrax/base/show.json.jbuilder +2 -2
  113. data/app/views/hyrax/file_sets/_versioning.html.erb +1 -1
  114. data/app/views/hyrax/file_sets/show.html.erb +5 -3
  115. data/app/views/hyrax/homepage/_explore_collections.html.erb +1 -1
  116. data/chart/hyrax/Chart.yaml +18 -14
  117. data/chart/hyrax/README.md +34 -21
  118. data/chart/hyrax/templates/_helpers.tpl +26 -1
  119. data/chart/hyrax/templates/configmap-env.yaml +12 -2
  120. data/chart/hyrax/templates/secrets.yaml +1 -1
  121. data/chart/hyrax/values.yaml +36 -14
  122. data/config/initializers/listeners.rb +4 -10
  123. data/config/initializers/storage_adapter_initializer.rb +1 -1
  124. data/config/locales/hyrax.de.yml +11 -3
  125. data/config/locales/hyrax.en.yml +13 -2
  126. data/config/locales/hyrax.es.yml +4 -1
  127. data/config/locales/hyrax.fr.yml +4 -1
  128. data/config/locales/hyrax.it.yml +5 -2
  129. data/config/locales/hyrax.pt-BR.yml +9 -2
  130. data/config/locales/hyrax.zh.yml +4 -1
  131. data/config/metadata/file_set_metadata.yaml +1 -1
  132. data/docker-compose-koppie.yml +17 -4
  133. data/docker-compose.yml +19 -6
  134. data/documentation/developing-your-hyrax-based-app.md +6 -14
  135. data/documentation/legacyREADME.md +7 -5
  136. data/hyrax.gemspec +2 -2
  137. data/karma.conf.js +8 -9
  138. data/lib/generators/hyrax/templates/config/analytics.yml +1 -0
  139. data/lib/generators/hyrax/templates/config/initializers/hyrax.rb +1 -1
  140. data/lib/generators/hyrax/templates/config/initializers/redis_config.rb +0 -1
  141. data/lib/generators/hyrax/templates/config/initializers/riiif.rb +15 -5
  142. data/lib/hyrax/active_fedora_dummy_model.rb +6 -1
  143. data/lib/hyrax/configuration.rb +6 -0
  144. data/lib/hyrax/engine.rb +2 -0
  145. data/lib/hyrax/publisher.rb +19 -3
  146. data/lib/hyrax/specs/capybara.rb +9 -4
  147. data/lib/hyrax/transactions/container.rb +5 -0
  148. data/lib/hyrax/transactions/steps/add_file_sets.rb +6 -0
  149. data/lib/hyrax/transactions/steps/apply_permission_template.rb +40 -0
  150. data/lib/hyrax/transactions/steps/save.rb +21 -0
  151. data/lib/hyrax/transactions/work_create.rb +1 -0
  152. data/lib/hyrax/version.rb +1 -1
  153. data/lib/hyrax.rb +1 -0
  154. data/lib/wings/active_fedora_converter/default_work.rb +7 -2
  155. data/lib/wings/active_fedora_converter/file_metadata_node.rb +1 -1
  156. data/lib/wings/active_fedora_converter.rb +47 -11
  157. data/lib/wings/model_transformer.rb +23 -4
  158. data/lib/wings/setup.rb +21 -1
  159. data/lib/wings/valkyrie/persister.rb +4 -2
  160. data/package.json +3 -1
  161. data/template.rb +1 -1
  162. metadata +15 -10
  163. data/app/forms/hyrax/forms/file_manager_form.rb +0 -35
  164. data/app/services/hyrax/collections/migration_service.rb +0 -113
  165. data/app/views/hyrax/base/_form_collections_error.html.erb +0 -1
  166. data/app/views/hyrax/base/_form_in_works_error.html.erb +0 -3
  167. data/app/views/hyrax/base/_form_ordered_members_error.html.erb +0 -3
  168. data/app/views/hyrax/base/_form_visibility_error.html.erb +0 -19
@@ -1,20 +1,24 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require 'oauth2'
3
4
  require 'signet/oauth_2/client'
4
5
 
5
- # rubocop:disable Metrics/ModuleLength
6
6
  module Hyrax
7
7
  module Analytics
8
+ # rubocop:disable Metrics/ModuleLength
8
9
  module Google
9
10
  extend ActiveSupport::Concern
10
11
  # rubocop:disable Metrics/BlockLength
11
12
  class_methods do
12
- # Loads configuration options from config/analytics.yml. Expected structure:
13
+ # Loads configuration options from config/analytics.yml. You only need PRIVATE_KEY_PATH or
14
+ # PRIVATE_KEY_VALUE. VALUE takes precedence.
15
+ # Expected structure:
13
16
  # `analytics:`
14
17
  # ` google:`
15
18
  # ` app_name: <%= ENV['GOOGLE_OAUTH_APP_NAME']`
16
19
  # ` app_version: <%= ENV['GOOGLE_OAUTH_APP_VERSION']`
17
20
  # ` privkey_path: <%= ENV['GOOGLE_OAUTH_PRIVATE_KEY_PATH']`
21
+ # ` privkey_value: <%= ENV['GOOGLE_OAUTH_PRIVATE_KEY_VALUE']`
18
22
  # ` privkey_secret: <%= ENV['GOOGLE_OAUTH_PRIVATE_KEY_SECRET']`
19
23
  # ` client_email: <%= ENV['GOOGLE_OAUTH_CLIENT_EMAIL']`
20
24
  # @return [Config]
@@ -41,7 +45,8 @@ module Hyrax
41
45
  new config
42
46
  end
43
47
 
44
- REQUIRED_KEYS = %w[analytics_id app_name app_version privkey_path privkey_secret client_email].freeze
48
+ KEYS = %w[analytics_id app_name app_version privkey_path privkey_value privkey_secret client_email].freeze
49
+ REQUIRED_KEYS = %w[analytics_id app_name app_version privkey_secret client_email].freeze
45
50
 
46
51
  def initialize(config)
47
52
  @config = config
@@ -49,18 +54,16 @@ module Hyrax
49
54
 
50
55
  # @return [Boolean] are all the required values present?
51
56
  def valid?
52
- config_keys = @config.keys
53
- REQUIRED_KEYS.all? { |required| config_keys.include?(required) }
54
- end
57
+ return false unless @config['privkey_value'].present? || @config['privkey_path'].present?
55
58
 
56
- REQUIRED_KEYS.each do |key|
57
- class_eval %{ def #{key}; @config.fetch('#{key}'); end }
59
+ REQUIRED_KEYS.all? { |required| @config[required].present? }
58
60
  end
59
61
 
60
- # This method allows setting the analytics id in the initializer
61
- # @deprecated set the analytics id in either ENV['GOOGLE_ANALYTICS_ID'] or config/analytics.yaml
62
- def analytics_id=(value)
63
- @config['analytics_id'] = value
62
+ KEYS.each do |key|
63
+ # rubocop:disable Style/EvalWithLocation
64
+ class_eval %{ def #{key}; @config.fetch('#{key}'); end }
65
+ class_eval %{ def #{key}=(value); @config['#{key}'] = value; end }
66
+ # rubocop:enable Style/EvalWithLocation
64
67
  end
65
68
  end
66
69
 
@@ -77,8 +80,12 @@ module Hyrax
77
80
  end
78
81
 
79
82
  def auth_client(scope)
80
- raise "Private key file for Google analytics was expected at '#{config.privkey_path}', but no file was found." unless File.exist?(config.privkey_path)
81
- private_key = File.read(config.privkey_path)
83
+ private_key = Base64.decode64(config.privkey_value) if config.privkey_value.present?
84
+ if private_key.blank?
85
+ raise "Private key file for Google analytics was expected at '#{config.privkey_path}', but no file was found." unless File.exist?(config.privkey_path)
86
+
87
+ private_key = File.read(config.privkey_path)
88
+ end
82
89
  Signet::OAuth2::Client.new token_credential_uri: 'https://accounts.google.com/o/oauth2/token',
83
90
  audience: 'https://accounts.google.com/o/oauth2/token',
84
91
  scope: scope,
@@ -123,7 +130,7 @@ module Hyrax
123
130
 
124
131
  [start_date, end_date]
125
132
  end
126
- # rubocop:enabl e Metrics/MethodLength
133
+ # rubocop:enable Metrics/MethodLength
127
134
 
128
135
  def keyword_conversion(date)
129
136
  case date
@@ -199,6 +206,7 @@ module Hyrax
199
206
  end
200
207
  # rubocop:enable Metrics/BlockLength
201
208
  end
209
+ # rubocop:enable Metrics/ModuleLength
202
210
  end
203
211
  end
204
212
  # rubocop:enable Metrics/ModuleLength
@@ -11,15 +11,16 @@ module Hyrax
11
11
  # Loads configuration options from config/analytics.yml. Expected structure:
12
12
  # `analytics:`
13
13
  # ` matomo:`
14
- # ` base_url: <%= ENV['MATOMOT_BASE_URL']`
15
- # ` site_id: <%= ENV['MATOMOT_SITE_ID']`
16
- # ` auth_token: <%= ENV['MATOMOT_AUTH_TOKEN']`
14
+ # ` base_url: <%= ENV['MATOMO_BASE_URL']`
15
+ # ` site_id: <%= ENV['MATOMO_SITE_ID']`
16
+ # ` auth_token: <%= ENV['MATOMO_AUTH_TOKEN']`
17
17
  # @return [Config]
18
18
  def config
19
19
  @config ||= Config.load_from_yaml
20
20
  end
21
21
 
22
22
  class Config
23
+ # TODO: test matomo and see if it needs any of the updates from https://github.com/samvera/hyrax/pull/6063
23
24
  def self.load_from_yaml
24
25
  filename = Rails.root.join('config', 'analytics.yml')
25
26
  yaml = YAML.safe_load(ERB.new(File.read(filename)).result)
@@ -27,25 +27,27 @@ class Hyrax::Characterization::ValkyrieCharacterizationService
27
27
  # @!attribute [rw] source
28
28
  # @return [Valkyrie::StorageAdapter::StreamFile]
29
29
  # @!attribute [rw] tools
30
- # @todo clarify what this is for. it gets passed to {#characterize}
31
- # on the characterizer, but it's not clear how to customize
32
- # effectively.
30
+ # can be :fits, :fits_servlet, :ffprobe or any other service added to HydraFileCharacterization
31
+ # note that ffprope is faster but only works on AV files.
33
32
  # @return [Symbol]
34
33
  attr_accessor :mapping, :metadata, :parser, :source, :tools
35
34
 
36
35
  ##
37
36
  # @api private
38
- def initialize(metadata:, # rubocop:disable Metrics/ParameterLists
39
- file:,
40
- characterizer: Hydra::FileCharacterization,
41
- parser_mapping: Hydra::Works::Characterization.mapper,
42
- parser: Hydra::Works::Characterization::FitsDocument.new)
37
+ def initialize( # rubocop:disable Metrics/ParameterLists
38
+ metadata:,
39
+ file:,
40
+ characterizer: Hydra::FileCharacterization,
41
+ parser_mapping: Hydra::Works::Characterization.mapper,
42
+ parser: Hydra::Works::Characterization::FitsDocument.new,
43
+ ch12n_tool: :fits
44
+ )
43
45
  @characterizer = characterizer
44
46
  @metadata = metadata
45
47
  @source = file
46
48
  @mapping = parser_mapping
47
49
  @parser = parser
48
- @tools = :fits
50
+ @tools = ch12n_tool
49
51
  end
50
52
 
51
53
  ##
@@ -0,0 +1,55 @@
1
+ # frozen_string_literal: true
2
+ module Hyrax
3
+ module CustomQueries
4
+ ##
5
+ # @see https://github.com/samvera/valkyrie/wiki/Queries#custom-queries
6
+ class FindByDateRange
7
+ def self.queries
8
+ [:find_by_date_range]
9
+ end
10
+
11
+ def initialize(query_service:)
12
+ @query_service = query_service
13
+ end
14
+
15
+ attr_reader :query_service
16
+ delegate :resource_factory, to: :query_service
17
+ delegate :orm_class, to: :resource_factory
18
+
19
+ ##
20
+ # @note this is an unoptimized default implementation of this custom
21
+ # query. it's Hyrax's policy to provide such implementations of custom
22
+ # queries in use for cross-compatibility of Valkyrie query services.
23
+ # it's advisable to provide an optimized query for the specific adapter.
24
+ #
25
+ # @param models [Array]
26
+ # @param start_datetime [DateTime]
27
+ # @param end_datetime [DateTime]
28
+ def find_by_date_range(start_datetime:, end_datetime: nil, models: nil)
29
+ end_datetime = 1.second.since(Time.zone.now) if end_datetime.blank?
30
+ if models.present?
31
+ query_service.run_query(find_models_by_date_range_query, start_datetime.to_s, end_datetime.to_s, models)
32
+ else
33
+ query_service.run_query(find_by_date_range_query, start_datetime.to_s, end_datetime.to_s)
34
+ end
35
+ end
36
+
37
+ def find_models_by_date_range_query
38
+ <<-SQL
39
+ SELECT * FROM orm_resources
40
+ WHERE created_at >= ?
41
+ AND created_at <= ?
42
+ AND internal_resource IN (?);
43
+ SQL
44
+ end
45
+
46
+ def find_by_date_range_query
47
+ <<-SQL
48
+ SELECT * FROM orm_resources
49
+ WHERE created_at >= ?
50
+ AND created_at <= ?;
51
+ SQL
52
+ end
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,62 @@
1
+ # frozen_string_literal: true
2
+ module Hyrax
3
+ module CustomQueries
4
+ ##
5
+ # @see https://github.com/samvera/valkyrie/wiki/Queries#custom-queries
6
+ class FindCountBy
7
+ def self.queries
8
+ [:find_count_by]
9
+ end
10
+
11
+ def initialize(query_service:)
12
+ @query_service = query_service
13
+ end
14
+
15
+ attr_reader :query_service
16
+ delegate :resource_factory, to: :query_service
17
+ delegate :orm_class, to: :resource_factory
18
+
19
+ ##
20
+ # @note this is an unoptimized default implementation of this custom
21
+ # query. it's Hyrax's policy to provide such implementations of custom
22
+ # queries in use for cross-compatibility of Valkyrie query services.
23
+ # it's advisable to provide an optimized query for the specific adapter.
24
+ #
25
+ # @param hash [Hash] the hash representation of the query
26
+ def find_count_by(hash = {}, models: nil)
27
+ return nil if models.empty? && hash.blank?
28
+
29
+ internal_array = ["{ #{hash.map { |k, v| "\"#{k}\": #{v}" }.join(', ')} }"] if hash.present?
30
+ if models.empty?
31
+ query_service.orm_class.count_by_sql(([find_count_by_properties_query] + internal_array))
32
+ elsif hash.blank?
33
+ query_service.orm_class.count_by_sql([find_count_by_models_query] + [models])
34
+ else
35
+ query_service.orm_class.count_by_sql(([find_count_by_properties_and_models_query] + internal_array + [models]))
36
+ end
37
+ end
38
+
39
+ def find_count_by_properties_and_models_query
40
+ <<-SQL
41
+ SELECT count(*) FROM orm_resources
42
+ WHERE metadata @> ?
43
+ AND internal_resource IN (?);
44
+ SQL
45
+ end
46
+
47
+ def find_count_by_models_query
48
+ <<-SQL
49
+ SELECT count(*) FROM orm_resources
50
+ WHERE internal_resource IN (?);
51
+ SQL
52
+ end
53
+
54
+ def find_count_by_properties_query
55
+ <<-SQL
56
+ SELECT count(*) FROM orm_resources
57
+ WHERE metadata @> ?;
58
+ SQL
59
+ end
60
+ end
61
+ end
62
+ end
@@ -67,7 +67,7 @@ module Hyrax
67
67
  return [] unless resource.try(:file_ids)
68
68
 
69
69
  results = find_many_file_metadata_by_ids(ids: resource.file_ids)
70
- results.select { |fm| fm.type.include?(use) }
70
+ results.select { |fm| fm.pcdm_use.include?(use) }
71
71
  end
72
72
  end
73
73
  end
@@ -0,0 +1,59 @@
1
+ # frozen_string_literal: true
2
+ module Hyrax
3
+ module CustomQueries
4
+ ##
5
+ # @see https://github.com/samvera/valkyrie/wiki/Queries#custom-queries
6
+ class FindModelsByAccess
7
+ def self.queries
8
+ [:find_models_by_access]
9
+ end
10
+
11
+ def initialize(query_service:)
12
+ @query_service = query_service
13
+ end
14
+
15
+ attr_reader :query_service
16
+ delegate :resource_factory, to: :query_service
17
+ delegate :orm_class, to: :resource_factory
18
+
19
+ ##
20
+ # @note this is an unoptimized default implementation of this custom
21
+ # query. it's Hyrax's policy to provide such implementations of custom
22
+ # queries in use for cross-compatibility of Valkyrie query services.
23
+ # it's advisable to provide an optimized query for the specific adapter.
24
+ #
25
+ # @param model [Class]
26
+ # @param ids [Enumerable<#to_s>, Symbol]
27
+ #
28
+ def find_models_by_access(mode:, models: nil, agent:, group: nil)
29
+ agent = "group/#{agent}" if group.present?
30
+ internal_array = "{\"permissions\": [{\"mode\": \"#{mode}\", \"agent\": \"#{agent}\"}]}"
31
+ if models.present?
32
+ query_service.run_query(find_models_by_access_query, internal_array, models)
33
+ else
34
+ query_service.run_query(find_by_access_query, internal_array)
35
+ end
36
+ end
37
+
38
+ def find_models_by_access_query
39
+ <<-SQL
40
+ SELECT * FROM orm_resources
41
+ WHERE id IN (
42
+ SELECT uuid(metadata::json#>'{access_to,0}'->>'id') FROM orm_resources
43
+ WHERE metadata @> ?
44
+ ) AND internal_resource IN (?);
45
+ SQL
46
+ end
47
+
48
+ def find_by_access_query
49
+ <<-SQL
50
+ SELECT * FROM orm_resources
51
+ WHERE id IN (
52
+ SELECT uuid(metadata::json#>'{access_to,0}'->>'id') FROM orm_resources
53
+ WHERE metadata @> ?
54
+ );
55
+ SQL
56
+ end
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ # this class overrides the Valkyrie::Storage::Disk::BucketStorage class so that file paths match
4
+ module Hyrax
5
+ class DerivativeBucketedStorage
6
+ attr_reader :base_path
7
+
8
+ def initialize(base_path:)
9
+ @base_path = base_path
10
+ end
11
+
12
+ # rubocop:disable Lint/UnusedMethodArgument
13
+ def generate(resource:, file:, original_filename:)
14
+ raise ArgumentError, "original_filename must be provided" unless original_filename
15
+ Pathname.new(base_path).join(*bucketed_path(resource.id)).join(original_filename)
16
+ end
17
+ # rubocop:enable Lint/UnusedMethodArgument
18
+
19
+ def bucketed_path(id)
20
+ # We want to use the same code the derivative process uses so that items end up
21
+ # stored in the place we expect them.
22
+ Hyrax::DerivativePath.new(id.to_s).pair_directory
23
+ end
24
+ end
25
+ end
@@ -35,6 +35,18 @@ module Hyrax
35
35
  end
36
36
  end
37
37
 
38
+ def pairs
39
+ @pairs ||= id.split('').each_slice(2).map(&:join)
40
+ end
41
+
42
+ def pair_directory
43
+ pairs[0..-2]
44
+ end
45
+
46
+ def pair_path
47
+ (pair_directory + pairs[-1..-1]).join('/')
48
+ end
49
+
38
50
  private
39
51
 
40
52
  # @return [String] Returns the root path where derivatives will be generated into.
@@ -47,10 +59,6 @@ module Hyrax
47
59
  Pathname.new(Hyrax.config.derivatives_path).join(pair_path)
48
60
  end
49
61
 
50
- def pair_path
51
- id.split('').each_slice(2).map(&:join).join('/')
52
- end
53
-
54
62
  def file_name
55
63
  return unless destination_name
56
64
  destination_name + extension
@@ -60,6 +68,8 @@ module Hyrax
60
68
  case destination_name
61
69
  when 'thumbnail'
62
70
  ".#{MIME::Types.type_for('jpg').first.extensions.first}"
71
+ when 'extracted_text'
72
+ ".#{MIME::Types.type_for('txt').first.extensions.first}"
63
73
  else
64
74
  ".#{destination_name}"
65
75
  end
@@ -17,6 +17,7 @@ module Hyrax
17
17
  # - "Enforced" means the object's visibility matches the pre-release
18
18
  # visibility of the embargo; i.e. the embargo has been applied,
19
19
  # but not released.
20
+ # - "Deactivate" means that the existing embargo will be removed
20
21
  #
21
22
  # Note that an resource may be `#under_embargo?` even if the embargo is not
22
23
  # be `#enforced?` (in this case, the application should seek to apply the
@@ -74,7 +75,7 @@ module Hyrax
74
75
  # resource.visibility # => 'open'
75
76
  # manager.enforced? => false
76
77
  #
77
- class EmbargoManager
78
+ class EmbargoManager # rubocop:disable Metrics/ClassLength
78
79
  ##
79
80
  # @!attribute [rw] resource
80
81
  # @return [Hyrax::Resource]
@@ -117,6 +118,51 @@ module Hyrax
117
118
  new(resource: resource, query_service: query_service)
118
119
  .release!
119
120
  end
121
+
122
+ # Creates or updates an existing embargo on a member to match the embargo on the parent work
123
+ # @param [Array<Valkyrie::Resource>] members
124
+ # @param [Hyrax::Work] work
125
+ # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
126
+ def create_or_update_embargo_on_members(members, work)
127
+ # TODO: account for all members and levels, not just file sets. ref: #6131
128
+
129
+ members.each do |member|
130
+ member_embargo_needs_updating = work.embargo.updated_at > member.embargo&.updated_at if member.embargo
131
+
132
+ if member.embargo && member_embargo_needs_updating
133
+ member.embargo.embargo_release_date = work.embargo['embargo_release_date']
134
+ member.embargo.visibility_during_embargo = work.embargo['visibility_during_embargo']
135
+ member.embargo.visibility_after_embargo = work.embargo['visibility_after_embargo']
136
+ member.embargo = Hyrax.persister.save(resource: member.embargo)
137
+ else
138
+ work_embargo_manager = Hyrax::EmbargoManager.new(resource: work)
139
+ work_embargo_manager.copy_embargo_to(target: member)
140
+ member = Hyrax.persister.save(resource: member)
141
+ end
142
+
143
+ user ||= ::User.find_by_user_key(member.depositor)
144
+ # the line below works in that it indexes the file set with the necessary lease properties
145
+ # I do not know however if this is the best event_id to pass
146
+ Hyrax.publisher.publish('object.metadata.updated', object: member, user: user)
147
+ end
148
+ end
149
+ # rubocop:enable Metrics/AbcSize, Metrics/MethodLength
150
+ end
151
+
152
+ # Deactivates the embargo and logs a message to the embargo_history property
153
+ def deactivate!
154
+ embargo_state = embargo.active? ? 'active' : 'expired'
155
+ embargo_record = embargo_history_message(
156
+ embargo_state,
157
+ Time.zone.today,
158
+ embargo.embargo_release_date,
159
+ embargo.visibility_during_embargo,
160
+ embargo.visibility_after_embargo
161
+ )
162
+
163
+ release(force: true)
164
+ nullify(force: true)
165
+ embargo.embargo_history += [embargo_record]
120
166
  end
121
167
 
122
168
  ##
@@ -128,7 +174,7 @@ module Hyrax
128
174
  def copy_embargo_to(target:)
129
175
  return false unless under_embargo?
130
176
 
131
- target.embargo = Embargo.new(clone_attributes)
177
+ target.embargo = Hyrax.persister.save(resource: Embargo.new(clone_attributes))
132
178
  self.class.apply_embargo_for(resource: target)
133
179
  end
134
180
 
@@ -152,7 +198,8 @@ module Hyrax
152
198
  ##
153
199
  # @return [Boolean]
154
200
  def enforced?
155
- embargo.visibility_during_embargo.to_s == resource.visibility
201
+ embargo.embargo_release_date.present? &&
202
+ (embargo.visibility_during_embargo.to_s == resource.visibility)
156
203
  end
157
204
 
158
205
  ##
@@ -162,21 +209,28 @@ module Hyrax
162
209
  end
163
210
 
164
211
  ##
165
- # Drop the embargo by setting its release date to `nil`.
212
+ # Drop the embargo by setting its release date and visibility settings to `nil`.
213
+ #
214
+ # @param force [boolean] force the nullify even when the embargo period is current
166
215
  #
167
216
  # @return [void]
168
- def nullify
169
- return unless under_embargo?
217
+ def nullify(force: false)
218
+ return false if !force && under_embargo?
219
+
170
220
  embargo.embargo_release_date = nil
221
+ embargo.visibility_during_embargo = nil
222
+ embargo.visibility_after_embargo = nil
171
223
  end
172
224
 
173
225
  ##
174
- # Sets the visibility of the resource to the embargo's visibility condition.
175
- # no-op if the embargo period is current.
226
+ # Sets the visibility of the resource to the embargo's after embargo visibility.
227
+ # no-op if the embargo period is current and the force flag is false.
228
+ #
229
+ # @param force [boolean] force the release even when the embargo period is current
176
230
  #
177
231
  # @return [Boolean] truthy if the embargo has been applied
178
- def release
179
- return false if under_embargo?
232
+ def release(force: false)
233
+ return false if !force && under_embargo?
180
234
  return true if embargo.visibility_after_embargo.nil?
181
235
 
182
236
  resource.visibility = embargo.visibility_after_embargo
@@ -209,5 +263,17 @@ module Hyrax
209
263
  def core_attribute_keys
210
264
  [:visibility_after_embargo, :visibility_during_embargo, :embargo_release_date]
211
265
  end
266
+
267
+ protected
268
+
269
+ # Create the log message used when deactivating an embargo
270
+ def embargo_history_message(state, deactivate_date, release_date, visibility_during, visibility_after)
271
+ I18n.t 'hydra.embargo.history_message',
272
+ state: state,
273
+ deactivate_date: deactivate_date,
274
+ release_date: release_date,
275
+ visibility_during: visibility_during,
276
+ visibility_after: visibility_after
277
+ end
212
278
  end
213
279
  end
@@ -75,7 +75,7 @@ module Hyrax
75
75
  url: derivative_url('thumbnail'),
76
76
  layer: 0
77
77
  }])
78
- extract_full_text(filename, uri)
78
+ extract_full_text(filename, derivative_url('extracted_text'))
79
79
  end
80
80
 
81
81
  def create_office_document_derivatives(filename)
@@ -86,7 +86,7 @@ module Hyrax
86
86
  url: derivative_url('thumbnail'),
87
87
  layer: 0
88
88
  }])
89
- extract_full_text(filename, uri)
89
+ extract_full_text(filename, derivative_url('extracted_text'))
90
90
  end
91
91
 
92
92
  def create_audio_derivatives(filename)
@@ -122,6 +122,7 @@ module Hyrax
122
122
  # @param [String] uri to the file set (deligated to file_set)
123
123
  def extract_full_text(filename, uri)
124
124
  return unless Hyrax.config.extract_full_text?
125
+
125
126
  Hydra::Derivatives::FullTextExtract.create(filename,
126
127
  outputs: [{ url: uri, container: "extracted_text" }])
127
128
  end