blacklight-spotlight 2.2.1 → 2.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/concerns/spotlight/catalog.rb +1 -0
  3. data/app/controllers/spotlight/browse_controller.rb +1 -0
  4. data/app/controllers/spotlight/contact_forms_controller.rb +1 -0
  5. data/app/controllers/spotlight/pages_controller.rb +1 -0
  6. data/app/helpers/spotlight/languages_helper.rb +1 -0
  7. data/app/models/concerns/spotlight/exhibit_analytics.rb +1 -0
  8. data/app/models/concerns/spotlight/solr_document.rb +1 -0
  9. data/app/models/concerns/spotlight/solr_document/atomic_updates.rb +1 -0
  10. data/app/models/sir_trevor_rails/blocks/textable.rb +1 -0
  11. data/app/models/spotlight/analytics/ga.rb +5 -5
  12. data/app/models/spotlight/blacklight_configuration.rb +2 -0
  13. data/app/models/spotlight/featured_image.rb +3 -0
  14. data/app/models/spotlight/page.rb +3 -0
  15. data/app/models/spotlight/page_configurations.rb +1 -0
  16. data/app/models/spotlight/reindex_progress.rb +3 -0
  17. data/app/models/spotlight/resource.rb +1 -0
  18. data/app/models/spotlight/resources/iiif_harvester.rb +1 -0
  19. data/app/models/spotlight/resources/iiif_manifest.rb +8 -0
  20. data/app/models/spotlight/search.rb +1 -0
  21. data/app/models/spotlight/solr_document_sidecar.rb +1 -1
  22. data/app/serializers/spotlight/exhibit_export_serializer.rb +1 -0
  23. data/app/services/spotlight/carrierwave_file_resolver.rb +1 -0
  24. data/app/services/spotlight/iiif_resource_resolver.rb +13 -10
  25. data/app/services/spotlight/solr_document_builder.rb +2 -0
  26. data/db/migrate/20180822233601_change_type_of_taggings_taggable.rb +8 -0
  27. data/lib/generators/spotlight/install_generator.rb +0 -4
  28. data/lib/migration/iiif.rb +6 -0
  29. data/lib/spotlight/upload_field_config.rb +4 -2
  30. data/lib/spotlight/version.rb +1 -1
  31. data/spec/examples.txt +1282 -1295
  32. data/spec/features/exhibits/translation_editing_spec.rb +9 -9
  33. data/spec/features/javascript/edit_in_place_spec.rb +1 -0
  34. data/spec/models/solr_document_spec.rb +3 -2
  35. data/spec/models/spotlight/blacklight_configuration_spec.rb +1 -1
  36. data/spec/models/spotlight/exhibit_spec.rb +1 -1
  37. data/spec/models/spotlight/page_spec.rb +1 -1
  38. data/spec/models/spotlight/resources/upload_spec.rb +4 -3
  39. data/spec/models/spotlight/solr_document_sidecar_spec.rb +13 -0
  40. data/spec/support/features/capybara_default_max_wait_metadata_helper.rb +2 -0
  41. data/spec/views/spotlight/exhibits/edit.html.erb_spec.rb +2 -2
  42. metadata +11 -12
  43. data/lib/generators/spotlight/increase_paper_trail_column_size_generator.rb +0 -17
  44. data/lib/generators/spotlight/templates/migrations/20180814221815_change_paper_trail_versions_object_column_to_medium_text.rb +0 -11
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4f0cb09d7197f79846b9c0c0f387315bd2ddd31c
4
- data.tar.gz: 4fee08aa4567e890f4564910abe3698ea0d49c63
3
+ metadata.gz: 4652ccafaff959547b28737b36d4b072a0b743e8
4
+ data.tar.gz: 40a4c98ab046b271b2d353b03aeebacbc3c3f651
5
5
  SHA512:
6
- metadata.gz: 1e425de62fb43001490219e0491af698e7ed2b8859f428cab318cc3ea9d80d7d688aac7bdd1d63ec741972c7c6060508e908bb39623c342284fe89837db737cb
7
- data.tar.gz: e22ae4e68081e94b126abd715990a15ae06735dd86ef627af971cdc7454efa2903d22776bbc4547d9609ddc2578b309d8b268f8013129aa36351f99ad630590e
6
+ metadata.gz: de8c2d7f707973d768ad438b0c8388c6c51816efbc321602973a305fb9db0dc02c2d743fcf115c847cfe7faba331edcd770ac7cc1a5e8c9e2dd4f192d0997e4a
7
+ data.tar.gz: '029ba01acc829eba450a6960869bae7da2ad0c56f098bd9db41bc50864652cb1756cec34a65a7288811d0f73e61995979978aa6c8eb9cbdb3e7cb16437510fdf'
@@ -14,6 +14,7 @@ module Spotlight
14
14
  # if the user is a curator
15
15
  def add_facet_visibility_field
16
16
  return unless current_exhibit && can?(:curate, current_exhibit)
17
+
17
18
  blacklight_config.add_facet_field 'exhibit_visibility',
18
19
  label: I18n.t(:'spotlight.catalog.facets.exhibit_visibility.label'),
19
20
  query: {
@@ -86,6 +86,7 @@ module Spotlight
86
86
 
87
87
  def document_index_view_type
88
88
  return super if params[:view].present?
89
+
89
90
  if @search && @search.default_index_view_type.present?
90
91
  blacklight_config.view[@search.default_index_view_type].key
91
92
  else
@@ -30,6 +30,7 @@ module Spotlight
30
30
 
31
31
  def contact_form_params
32
32
  return {} if params[:action] == 'new'
33
+
33
34
  params.require(:contact_form).permit(:name, :email, Spotlight::Engine.config.spambot_honeypot_email_field, :message, :current_url)
34
35
  end
35
36
  end
@@ -111,6 +111,7 @@ module Spotlight
111
111
 
112
112
  def undo_link
113
113
  return unless can? :manage, @page
114
+
114
115
  view_context.link_to(t(:'spotlight.versions.undo'), revert_version_path(@page.versions.last), method: :post)
115
116
  end
116
117
 
@@ -27,6 +27,7 @@ module Spotlight
27
27
  # @return [Boolean]
28
28
  def default_language?
29
29
  return true unless params[:locale]
30
+
30
31
  params[:locale].to_s == I18n.default_locale.to_s
31
32
  end
32
33
  end
@@ -4,6 +4,7 @@ module Spotlight
4
4
  module ExhibitAnalytics
5
5
  def analytics(start_date = 1.month, path = nil)
6
6
  return OpenStruct.new unless analytics_provider && analytics_provider.enabled?
7
+
7
8
  @analytics ||= {}
8
9
  @analytics[start_date] ||= begin
9
10
  analytics_provider.exhibit_data(path || self, start_date: start_date.ago)
@@ -68,6 +68,7 @@ module Spotlight
68
68
 
69
69
  def update_exhibit_resource(resource_attributes)
70
70
  return unless resource_attributes && resource_attributes['url']
71
+
71
72
  uploaded_resource.upload.update image: resource_attributes['url']
72
73
  end
73
74
 
@@ -5,6 +5,7 @@ module Spotlight
5
5
  module AtomicUpdates
6
6
  def reindex
7
7
  return unless write?
8
+
8
9
  data = hash_for_solr_update(to_solr)
9
10
 
10
11
  blacklight_solr.update params: { commitWithin: 500 }, data: data.to_json, headers: { 'Content-Type' => 'application/json' } unless data.empty?
@@ -13,6 +13,7 @@ module SirTrevorRails
13
13
 
14
14
  def content_align
15
15
  return unless text?
16
+
16
17
  text_align == 'left' ? 'right' : 'left'
17
18
  end
18
19
 
@@ -24,11 +24,11 @@ module Spotlight
24
24
 
25
25
  def self.user(scope = 'https://www.googleapis.com/auth/analytics.readonly')
26
26
  @user ||= begin
27
- Legato::User.new(oauth_token(scope))
28
- rescue => e
29
- Rails.logger.info(e)
30
- nil
31
- end
27
+ Legato::User.new(oauth_token(scope))
28
+ rescue => e
29
+ Rails.logger.info(e)
30
+ nil
31
+ end
32
32
  end
33
33
 
34
34
  def self.site
@@ -331,12 +331,14 @@ module Spotlight
331
331
  # Check to see whether config.view.foobar.title_only_by_default is available
332
332
  def title_only_by_default?(view)
333
333
  return false if [:show, :enabled].include?(view)
334
+
334
335
  title_only = default_blacklight_config.view.send(:[], view).try(:title_only_by_default)
335
336
  title_only.nil? ? false : title_only
336
337
  end
337
338
 
338
339
  def set_show_field_defaults(field)
339
340
  return unless index_fields.blank?
341
+
340
342
  views = default_blacklight_config.view.keys
341
343
  field.merge! Hash[views.map { |v| [v, false] }]
342
344
  field.enabled = true
@@ -15,6 +15,7 @@ module Spotlight
15
15
 
16
16
  def iiif_url
17
17
  return unless iiif_service_base.present?
18
+
18
19
  [iiif_service_base, iiif_region || 'full', image_size.join(','), '0', 'default.jpg'].join('/')
19
20
  end
20
21
 
@@ -49,6 +50,7 @@ module Spotlight
49
50
 
50
51
  def set_tilesource_from_uploaded_resource
51
52
  return if iiif_tilesource
53
+
52
54
  riiif = Riiif::Engine.routes.url_helpers
53
55
  self.iiif_tilesource = riiif.info_path(id)
54
56
  save
@@ -60,6 +62,7 @@ module Spotlight
60
62
 
61
63
  def iiif_service_base
62
64
  return unless iiif_tilesource
65
+
63
66
  iiif_tilesource.sub('/info.json', '')
64
67
  end
65
68
  end
@@ -70,6 +70,7 @@ module Spotlight
70
70
 
71
71
  def thumbnail_image_url
72
72
  return unless thumbnail && thumbnail.iiif_url
73
+
73
74
  thumbnail.iiif_url
74
75
  end
75
76
 
@@ -113,6 +114,7 @@ module Spotlight
113
114
 
114
115
  def updated_after?(other_page)
115
116
  return false unless other_page
117
+
116
118
  updated_at > other_page.updated_at
117
119
  end
118
120
 
@@ -139,6 +141,7 @@ module Spotlight
139
141
  def update_translated_pages_weights_and_parent_page
140
142
  return unless locale.to_sym == I18n.default_locale
141
143
  return unless saved_change_to_weight? || saved_change_to_parent_page_id?
144
+
142
145
  update_params = {}
143
146
  update_params[:weight] = weight if saved_change_to_weight?
144
147
  update_params[:parent_page_id] = parent_page_id if saved_change_to_parent_page_id?
@@ -73,6 +73,7 @@ module Spotlight
73
73
 
74
74
  def page_preview_url
75
75
  return unless page.persisted?
76
+
76
77
  spotlight.exhibit_preview_block_path(current_exhibit, page)
77
78
  end
78
79
 
@@ -57,16 +57,19 @@ module Spotlight
57
57
 
58
58
  def localized_start_time
59
59
  return unless started_at
60
+
60
61
  I18n.l(started_at, format: :short)
61
62
  end
62
63
 
63
64
  def localized_finish_time
64
65
  return unless finished_at
66
+
65
67
  I18n.l(finished_at, format: :short)
66
68
  end
67
69
 
68
70
  def localized_updated_time
69
71
  return unless updated_at
72
+
70
73
  I18n.l(updated_at, format: :short)
71
74
  end
72
75
  end
@@ -90,6 +90,7 @@ module Spotlight
90
90
 
91
91
  def commit
92
92
  return unless write?
93
+
93
94
  blacklight_solr.commit
94
95
  rescue => e
95
96
  Rails.logger.warn "Unable to commit to solr: #{e}"
@@ -25,6 +25,7 @@ module Spotlight
25
25
  req = Faraday.head(url)
26
26
  req = Faraday.get(url) if req.status == 405
27
27
  return unless req.success?
28
+
28
29
  valid_content_types.any? do |valid_type|
29
30
  req.headers['content-type'].include?(valid_type)
30
31
  end
@@ -54,11 +54,13 @@ module Spotlight
54
54
 
55
55
  def add_thumbnail_url
56
56
  return unless thumbnail_field && manifest['thumbnail'].present?
57
+
57
58
  solr_hash[thumbnail_field] = manifest['thumbnail']['@id']
58
59
  end
59
60
 
60
61
  def add_full_image_urls
61
62
  return unless full_image_field && full_image_url
63
+
62
64
  solr_hash[full_image_field] = full_image_url
63
65
  end
64
66
 
@@ -82,10 +84,12 @@ module Spotlight
82
84
  def manifest_metadata
83
85
  metadata = metadata_class.new(manifest).to_solr
84
86
  return {} unless metadata.present?
87
+
85
88
  create_sidecars_for(*metadata.keys)
86
89
 
87
90
  metadata.each_with_object({}) do |(key, value), hash|
88
91
  next unless (field = exhibit_custom_fields[key])
92
+
89
93
  hash[field.field] = value
90
94
  end
91
95
  end
@@ -93,6 +97,7 @@ module Spotlight
93
97
  def json_ld_value(value)
94
98
  return value['@value'] if value.is_a?(Hash)
95
99
  return value.find { |v| v['@language'] == default_json_ld_language }.try(:[], '@value') if value.is_a?(Array)
100
+
96
101
  value
97
102
  end
98
103
 
@@ -119,6 +124,7 @@ module Spotlight
119
124
  def image_urls
120
125
  @image_urls ||= resources.map do |resource|
121
126
  next unless resource && !resource.service.empty?
127
+
122
128
  image_url = resource.service['@id']
123
129
  image_url << '/info.json' unless image_url.downcase.ends_with?('/info.json')
124
130
  image_url
@@ -201,6 +207,7 @@ module Spotlight
201
207
 
202
208
  metadata.each_with_object({}) do |md, hash|
203
209
  next unless md['label'] && md['value']
210
+
204
211
  hash[md['label']] ||= []
205
212
  hash[md['label']] += Array(md['value'])
206
213
  end
@@ -210,6 +217,7 @@ module Spotlight
210
217
  manifest_fields.each_with_object({}) do |field, hash|
211
218
  next unless manifest.respond_to?(field) &&
212
219
  manifest.send(field).present?
220
+
213
221
  hash[field.capitalize] ||= []
214
222
  hash[field.capitalize] += Array(manifest.send(field))
215
223
  end
@@ -24,6 +24,7 @@ module Spotlight
24
24
 
25
25
  def thumbnail_image_url
26
26
  return unless thumbnail && thumbnail.iiif_url
27
+
27
28
  thumbnail.iiif_url
28
29
  end
29
30
 
@@ -72,7 +72,7 @@ module Spotlight
72
72
  field_name = field.field_name.to_s
73
73
  next unless configured_fields && configured_fields[field_name].present?
74
74
 
75
- solr_fields = Array(field.solr_field || field.field_name)
75
+ solr_fields = field.solr_fields || Array(field.solr_field || field.field_name)
76
76
 
77
77
  solr_fields.each do |solr_field|
78
78
  solr_hash[solr_field] = configured_fields[field_name]
@@ -150,6 +150,7 @@ module Spotlight
150
150
 
151
151
  def upload=(json)
152
152
  return unless represented.is_a? Spotlight::Resources::Upload
153
+
153
154
  FeaturedImageRepresenter.new(represented.build_upload).from_json(json)
154
155
  end
155
156
  end
@@ -9,6 +9,7 @@ module Spotlight
9
9
  def pattern(id)
10
10
  uploaded_file = Spotlight::FeaturedImage.find(id).image.file
11
11
  raise Riiif::ImageNotFoundError, "unable to find file for #{id}" if uploaded_file.nil?
12
+
12
13
  uploaded_file.file
13
14
  end
14
15
  end
@@ -12,6 +12,7 @@ module Spotlight
12
12
  def resolve!
13
13
  resource.iiif_tilesource = updated_tilesource
14
14
  return resource.save if resource.changed?
15
+
15
16
  Rails.logger.info("#{self.class.name} resolved #{iiif_manifest_url}, but nothing changed.")
16
17
  end
17
18
 
@@ -29,6 +30,7 @@ module Spotlight
29
30
  end
30
31
 
31
32
  raise(ManifestError, "No image with @id #{iiif_image_id} found in #{iiif_manifest_url}") unless new_image
33
+
32
34
  new_image
33
35
  end
34
36
 
@@ -38,6 +40,7 @@ module Spotlight
38
40
  end
39
41
 
40
42
  raise(ManifestError, "No canvas with @id #{iiif_canvas_id} found in #{iiif_manifest_url}") unless new_canvas
43
+
41
44
  new_canvas
42
45
  end
43
46
 
@@ -52,20 +55,20 @@ module Spotlight
52
55
 
53
56
  def response
54
57
  @response ||= begin
55
- Faraday.get(iiif_manifest_url).body
56
- rescue Faraday::Error => e
57
- Rails.logger.warn("#{self.class.name} failed to fetch #{iiif_manifest_url} with: #{e}")
58
- '{}'
59
- end
58
+ Faraday.get(iiif_manifest_url).body
59
+ rescue Faraday::Error => e
60
+ Rails.logger.warn("#{self.class.name} failed to fetch #{iiif_manifest_url} with: #{e}")
61
+ '{}'
62
+ end
60
63
  end
61
64
 
62
65
  def manifest
63
66
  @manifest ||= begin
64
- JSON.parse(response)
65
- rescue JSON::ParserError => e
66
- Rails.logger.warn("#{self.class.name} failed to parse #{iiif_manifest_url} with: #{e}")
67
- {}
68
- end
67
+ JSON.parse(response)
68
+ rescue JSON::ParserError => e
69
+ Rails.logger.warn("#{self.class.name} failed to parse #{iiif_manifest_url} with: #{e}")
70
+ {}
71
+ end
69
72
  end
70
73
 
71
74
  class ManifestError < RuntimeError; end
@@ -13,6 +13,7 @@ module Spotlight
13
13
  def documents_to_index
14
14
  data = to_solr
15
15
  return [] if data.blank?
16
+
16
17
  data &&= [data] if data.is_a? Hash
17
18
 
18
19
  return to_enum(:documents_to_index) { data.size } unless block_given?
@@ -51,6 +52,7 @@ module Spotlight
51
52
  # @returns [#to_solr] something that responds to `to_solr'
52
53
  def exhibit_solr_doc(id)
53
54
  return NilSolrDocument unless document_model || id.present?
55
+
54
56
  document_model.build_for_exhibit(id, exhibit, resource: resource)
55
57
  end
56
58
 
@@ -0,0 +1,8 @@
1
+ class ChangeTypeOfTaggingsTaggable < ActiveRecord::Migration[5.1]
2
+ def change
3
+ change_column :taggings,
4
+ :taggable_id,
5
+ :integer,
6
+ using: 'taggable_id::integer'
7
+ end
8
+ end
@@ -141,9 +141,5 @@ module Spotlight
141
141
  def add_translations
142
142
  copy_file 'config/initializers/translation.rb'
143
143
  end
144
-
145
- def generate_paper_trail_column_size_migration
146
- generate 'spotlight:increase_paper_trail_column_size'
147
- end
148
144
  end
149
145
  end
@@ -49,11 +49,13 @@ module Migration
49
49
  # as copy the file over to the correct directory given the new class name
50
50
  def copy_exhibit_thumbnail_from_featured_image(image)
51
51
  return unless Spotlight::Exhibit.where(thumbnail_id: image.id).any?
52
+
52
53
  filename = image.read_attribute_before_type_cast('image')
53
54
  filepath = "public/#{image.image.store_dir}/#{filename}"
54
55
  image.becomes!(Spotlight::ExhibitThumbnail)
55
56
  image.save
56
57
  return unless filename.present? && File.exist?(filepath)
58
+
57
59
  old_file = File.new(filepath)
58
60
  # AR + STI seems to require that we re-query for this
59
61
  # otherwise we get an association miss-match
@@ -66,6 +68,7 @@ module Migration
66
68
  filename = contact.read_attribute_before_type_cast('avatar')
67
69
  filepath = "public/uploads/spotlight/contact/avatar/#{contact.id}/#{filename}"
68
70
  return unless filename.present? && File.exist?(filepath)
71
+
69
72
  old_file = File.new(filepath)
70
73
  image = contact.create_avatar { |i| i.image.store!(old_file) }
71
74
  iiif_tilesource = riiif.info_path(image.id)
@@ -75,9 +78,11 @@ module Migration
75
78
 
76
79
  def copy_upload_to_featured_image(upload)
77
80
  return unless upload.exhibit # We need exhibit context to re-index, and you can't find an item not in an exhibit
81
+
78
82
  filename = upload.read_attribute_before_type_cast('url')
79
83
  filepath = "public/uploads/spotlight/resources/upload/url/#{upload.id}/#{filename}"
80
84
  return unless filename.present? && File.exist?(filepath)
85
+
81
86
  old_file = File.new(filepath)
82
87
  image = upload.create_upload { |i| i.image.store!(old_file) }
83
88
  iiif_tilesource = riiif.info_path(image.id)
@@ -95,6 +100,7 @@ module Migration
95
100
 
96
101
  def coordinates(image)
97
102
  return unless image.image_crop_x.present?
103
+
98
104
  [image.image_crop_x, image.image_crop_y, image.image_crop_w, image.image_crop_h].join(',')
99
105
  end
100
106