blacklight-spotlight 3.0.0.rc4 → 3.0.0.rc5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (169) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/images/blacklight/close.svg +1 -0
  3. data/app/assets/images/blacklight/zoom_in.svg +1 -0
  4. data/app/assets/images/blacklight/zoom_out.svg +1 -0
  5. data/app/assets/javascripts/spotlight/admin/blocks/uploaded_items_block.js +8 -1
  6. data/app/assets/javascripts/spotlight/admin/catalog_edit.js +13 -47
  7. data/app/assets/javascripts/spotlight/admin/exhibit_tag_autocomplete.js +37 -0
  8. data/app/assets/javascripts/spotlight/admin/{reindex_monitor.js → progress_monitor.js} +25 -4
  9. data/app/assets/javascripts/spotlight/admin/sir-trevor/locales.js +1 -1
  10. data/app/assets/javascripts/spotlight/user/zpr_links.js.erb +29 -14
  11. data/app/assets/stylesheets/spotlight/_browse.scss +8 -0
  12. data/app/assets/stylesheets/spotlight/_catalog.scss +30 -4
  13. data/app/assets/stylesheets/spotlight/_exhibit_admin.scss +9 -0
  14. data/app/assets/stylesheets/spotlight/_modals.scss +3 -0
  15. data/app/assets/stylesheets/spotlight/_nestable.scss +8 -0
  16. data/app/assets/stylesheets/spotlight/_spotlight.scss +2 -0
  17. data/app/assets/stylesheets/spotlight/_view_larger.scss +22 -0
  18. data/app/assets/stylesheets/spotlight/typeahead.css +23 -23
  19. data/app/builders/spotlight/bootstrap_breadcrumbs_builder.rb +4 -2
  20. data/app/controllers/concerns/spotlight/catalog.rb +7 -1
  21. data/app/controllers/spotlight/browse_controller.rb +5 -0
  22. data/app/controllers/spotlight/bulk_actions_controller.rb +62 -0
  23. data/app/controllers/spotlight/bulk_updates_controller.rb +67 -0
  24. data/app/controllers/spotlight/catalog_controller.rb +5 -7
  25. data/app/controllers/spotlight/dashboards_controller.rb +2 -1
  26. data/app/controllers/spotlight/featured_images_controller.rb +1 -1
  27. data/app/controllers/spotlight/job_trackers_controller.rb +17 -0
  28. data/app/controllers/spotlight/tags_controller.rb +39 -5
  29. data/app/helpers/spotlight/application_helper.rb +1 -1
  30. data/app/helpers/spotlight/job_trackers_helper.rb +31 -0
  31. data/app/helpers/spotlight/pages_helper.rb +0 -7
  32. data/app/helpers/spotlight/roles_helper.rb +1 -1
  33. data/app/jobs/concerns/spotlight/gather_documents.rb +35 -0
  34. data/app/jobs/concerns/spotlight/job_tracking.rb +40 -23
  35. data/app/jobs/spotlight/add_tags_job.rb +31 -0
  36. data/app/jobs/spotlight/add_uploads_from_csv.rb +2 -4
  37. data/app/jobs/spotlight/change_visibility_job.rb +33 -0
  38. data/app/jobs/spotlight/process_bulk_updates_csv_job.rb +82 -0
  39. data/app/jobs/spotlight/reindex_exhibit_job.rb +5 -2
  40. data/app/jobs/spotlight/reindex_job.rb +35 -23
  41. data/app/jobs/spotlight/remove_tags_job.rb +31 -0
  42. data/app/jobs/spotlight/rename_sidecar_field_job.rb +1 -0
  43. data/app/jobs/spotlight/rename_tags_job.rb +33 -0
  44. data/app/models/concerns/spotlight/exhibit_analytics.rb +2 -6
  45. data/app/models/concerns/spotlight/exhibit_documents.rb +2 -2
  46. data/app/models/concerns/spotlight/resources/web.rb +1 -1
  47. data/app/models/concerns/spotlight/solr_document.rb +1 -1
  48. data/app/models/concerns/spotlight/solr_document/atomic_updates.rb +2 -2
  49. data/app/models/concerns/spotlight/user.rb +5 -1
  50. data/app/models/sir_trevor_rails/blocks/uploaded_items_block.rb +4 -0
  51. data/app/models/spotlight/ability.rb +6 -2
  52. data/app/models/spotlight/attachment.rb +1 -1
  53. data/app/models/spotlight/{reindex_progress.rb → background_job_progress.rb} +8 -7
  54. data/app/models/spotlight/blacklight_configuration.rb +17 -6
  55. data/app/models/spotlight/bulk_update.rb +8 -0
  56. data/app/models/spotlight/exhibit.rb +2 -1
  57. data/app/models/spotlight/feature_page.rb +0 -2
  58. data/app/models/spotlight/featured_image.rb +7 -1
  59. data/app/models/spotlight/field_metadata.rb +4 -8
  60. data/app/models/spotlight/job_tracker.rb +11 -2
  61. data/app/models/spotlight/page.rb +1 -3
  62. data/app/models/spotlight/resource.rb +4 -4
  63. data/app/models/spotlight/resources/iiif_harvester.rb +2 -2
  64. data/app/models/spotlight/resources/iiif_service.rb +8 -1
  65. data/app/models/spotlight/resources/upload.rb +2 -2
  66. data/app/models/spotlight/role.rb +1 -2
  67. data/app/presenters/spotlight/iiif_manifest_presenter.rb +1 -1
  68. data/app/services/spotlight/bulk_updates_csv_template_service.rb +93 -0
  69. data/app/services/spotlight/etl/executor.rb +1 -3
  70. data/app/services/spotlight/iiif_resource_resolver.rb +1 -1
  71. data/app/uploaders/spotlight/bulk_updates_uploader.rb +7 -0
  72. data/app/uploaders/spotlight/featured_image_uploader.rb +1 -1
  73. data/app/views/catalog/_add_tags.html.erb +28 -0
  74. data/app/views/catalog/_bulk_actions.html.erb +12 -0
  75. data/app/views/catalog/_change_visibility.html.erb +35 -0
  76. data/app/views/catalog/_curator_actions.html.erb +3 -0
  77. data/app/views/catalog/_remove_tags.html.erb +37 -0
  78. data/app/views/spotlight/bulk_updates/_download.html.erb +23 -0
  79. data/app/views/spotlight/bulk_updates/_overview.html.erb +1 -0
  80. data/app/views/spotlight/bulk_updates/_progress_panel.html.erb +19 -0
  81. data/app/views/spotlight/bulk_updates/_upload.html.erb +12 -0
  82. data/app/views/spotlight/bulk_updates/edit.html.erb +37 -0
  83. data/app/views/spotlight/catalog/_admin_header.html.erb +1 -1
  84. data/app/views/spotlight/catalog/_edit_default.html.erb +2 -2
  85. data/app/views/spotlight/catalog/_reindex_progress_panel.html.erb +1 -1
  86. data/app/views/spotlight/custom_fields/_form.html.erb +1 -1
  87. data/app/views/spotlight/custom_search_fields/_form.html.erb +1 -1
  88. data/app/views/spotlight/dashboards/_reindexing_activity.html.erb +1 -1
  89. data/app/views/spotlight/exhibits/_exhibit_card.html.erb +1 -1
  90. data/app/views/spotlight/job_trackers/show.html.erb +79 -0
  91. data/app/views/spotlight/pages/_form.html.erb +2 -2
  92. data/app/views/spotlight/resources/_form.html.erb +1 -1
  93. data/app/views/spotlight/resources/csv_upload/_form.html.erb +1 -1
  94. data/app/views/spotlight/resources/iiif/_form.html.erb +1 -1
  95. data/app/views/spotlight/resources/json_upload/_form.html.erb +2 -2
  96. data/app/views/spotlight/resources/upload/_form.html.erb +1 -1
  97. data/app/views/spotlight/shared/_curation_sidebar.html.erb +3 -0
  98. data/app/views/spotlight/sir_trevor/blocks/_browse_group_categories_block.html.erb +3 -3
  99. data/app/views/spotlight/sir_trevor/blocks/_solr_documents_block.html.erb +3 -3
  100. data/app/views/spotlight/sir_trevor/blocks/_solr_documents_carousel_block.html.erb +2 -2
  101. data/app/views/spotlight/sir_trevor/blocks/_solr_documents_features_block.html.erb +2 -2
  102. data/app/views/spotlight/sir_trevor/blocks/_solr_documents_grid_block.html.erb +2 -2
  103. data/app/views/spotlight/sir_trevor/blocks/_uploaded_items_block.html.erb +4 -0
  104. data/app/views/spotlight/tags/_tag.html.erb +24 -0
  105. data/app/views/spotlight/tags/index.html.erb +12 -16
  106. data/app/views/spotlight/translations/show.yaml.yamlbuilder +6 -0
  107. data/config/i18n-tasks.yml +1 -0
  108. data/config/locales/spotlight.en.yml +169 -10
  109. data/config/routes.rb +28 -1
  110. data/db/migrate/20210126123041_create_events.rb +1 -1
  111. data/db/migrate/20210305070001_remove_class_from_sirtrevor_image_blocks.rb +20 -0
  112. data/db/migrate/20210305171150_create_bulk_updates.rb +9 -0
  113. data/lib/generators/spotlight/templates/config/initializers/riiif.rb +7 -5
  114. data/lib/generators/spotlight/templates/config/initializers/spotlight_initializer.rb +1 -1
  115. data/lib/generators/spotlight/templates/solr/config/schema.xml +1 -1
  116. data/lib/migration/iiif.rb +3 -3
  117. data/lib/spotlight/engine.rb +14 -0
  118. data/lib/spotlight/version.rb +1 -1
  119. data/spec/controllers/spotlight/bulk_actions_controller_spec.rb +124 -0
  120. data/spec/controllers/spotlight/bulk_updates_controller_spec.rb +77 -0
  121. data/spec/controllers/spotlight/catalog_controller_spec.rb +12 -12
  122. data/spec/controllers/spotlight/featured_images_controller_spec.rb +3 -3
  123. data/spec/controllers/spotlight/job_trackers_controller_spec.rb +37 -0
  124. data/spec/controllers/spotlight/tags_controller_spec.rb +5 -1
  125. data/spec/examples.txt +1495 -1443
  126. data/spec/factories/bulk_updates.rb +15 -0
  127. data/spec/factories/exhibits.rb +4 -0
  128. data/spec/factories/job_trackers.rb +2 -0
  129. data/spec/factories/users.rb +27 -8
  130. data/spec/features/add_items_spec.rb +1 -1
  131. data/spec/features/bulk_actions_spec.rb +72 -0
  132. data/spec/features/catalog_spec.rb +1 -0
  133. data/spec/features/import_exhibit_spec.rb +5 -1
  134. data/spec/features/javascript/blocks/solr_documents_block_spec.rb +3 -3
  135. data/spec/features/javascript/blocks/uploaded_items_block_spec.rb +27 -1
  136. data/spec/features/site_users_management_spec.rb +4 -4
  137. data/spec/fixtures/bulk-update-template.csv +57 -0
  138. data/spec/fixtures/updated-bulk-update-template-w-tags.csv +4 -0
  139. data/spec/fixtures/updated-bulk-update-template.csv +4 -0
  140. data/spec/helpers/spotlight/application_helper_spec.rb +0 -1
  141. data/spec/helpers/spotlight/pages_helper_spec.rb +0 -15
  142. data/spec/helpers/spotlight/roles_helper_spec.rb +1 -1
  143. data/spec/i18n_spec.rb +1 -0
  144. data/spec/jobs/spotlight/add_tags_job_spec.rb +34 -0
  145. data/spec/jobs/spotlight/add_uploads_from_csv_spec.rb +4 -1
  146. data/spec/jobs/spotlight/change_visibility_job_spec.rb +30 -0
  147. data/spec/jobs/spotlight/process_bulk_updates_csv_job_spec.rb +78 -0
  148. data/spec/jobs/spotlight/reindex_job_spec.rb +4 -1
  149. data/spec/jobs/spotlight/remove_tags_job_spec.rb +39 -0
  150. data/spec/lib/migration/iiif_spec.rb +1 -1
  151. data/spec/models/spotlight/ability_spec.rb +27 -0
  152. data/spec/models/spotlight/{reindex_progress_spec.rb → background_job_progress_spec.rb} +15 -2
  153. data/spec/models/spotlight/blacklight_configuration_spec.rb +8 -3
  154. data/spec/models/spotlight/exhibit_spec.rb +1 -1
  155. data/spec/models/spotlight/featured_image_spec.rb +1 -1
  156. data/spec/models/spotlight/resource_spec.rb +23 -0
  157. data/spec/models/spotlight/solr_document/atomic_updates_spec.rb +10 -0
  158. data/spec/services/spotlight/bulk_updates_csv_template_service_spec.rb +26 -0
  159. data/spec/test_app_templates/Gemfile.extra +1 -0
  160. data/spec/uploaders/spotlight/featured_image_uploader_spec.rb +2 -2
  161. data/spec/views/spotlight/catalog/_edit_default.html.erb_spec.rb +1 -1
  162. data/spec/views/spotlight/dashboards/_reindexing_activity.html.erb_spec.rb +2 -0
  163. data/spec/views/spotlight/job_trackers/show.html.erb_spec.rb +65 -0
  164. data/spec/views/spotlight/tags/index.html.erb_spec.rb +5 -2
  165. metadata +80 -17
  166. data/app/assets/images/blacklight/add_circle.svg +0 -1
  167. data/app/assets/images/blacklight/custom_fullscreen.svg +0 -1
  168. data/app/assets/images/blacklight/remove_circle.svg +0 -1
  169. data/app/assets/images/blacklight/resize_small.svg +0 -1
data/config/routes.rb CHANGED
@@ -109,7 +109,15 @@ Spotlight::Engine.routes.draw do
109
109
  end
110
110
  end
111
111
 
112
- resources :tags, only: %i[index destroy]
112
+ resources :tags, only: %i[index destroy] do
113
+ collection do
114
+ patch :update_all
115
+ end
116
+
117
+ member do
118
+ post :rename
119
+ end
120
+ end
113
121
 
114
122
  resources :contacts, only: %i[edit update destroy]
115
123
 
@@ -141,10 +149,29 @@ Spotlight::Engine.routes.draw do
141
149
  get :clone
142
150
  end
143
151
  end
152
+ resource :bulk_actions, only: [] do
153
+ member do
154
+ post :change_visibility
155
+ post :add_tags
156
+ post :remove_tags
157
+ end
158
+ end
159
+
160
+ resource :bulk_updates, only: %i[edit update] do
161
+ collection do
162
+ get :monitor
163
+ end
164
+
165
+ member do
166
+ post :download_template
167
+ end
168
+ end
169
+
144
170
  post '/pages/:id/preview' => 'pages#preview', as: :preview_block
145
171
  get '/pages' => 'pages#index', constraints: { format: 'json' }
146
172
 
147
173
  resources :lock, only: [:destroy]
174
+ resources :job_trackers, only: [:show]
148
175
 
149
176
  resources :roles, path: 'users', only: %i[index create destroy] do
150
177
  collection do
@@ -3,7 +3,7 @@
3
3
  class CreateEvents < ActiveRecord::Migration[5.2]
4
4
  def change
5
5
  create_table :spotlight_events do |t|
6
- t.references :exhibit, null: false, polymorphic: true
6
+ t.references :exhibit, null: true
7
7
  t.references :resource, null: false, polymorphic: true, index: true
8
8
  t.string :type
9
9
  t.string :collation_key
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Remove the class field from the block; ostruct 0.3 helpfully allows it to override
4
+ # this field and that confuses sir trevor..
5
+ class RemoveClassFromSirtrevorImageBlocks < ActiveRecord::Migration[5.2]
6
+ def up
7
+ Spotlight::Page.reset_column_information
8
+ image = SirTrevorRails::Block.block_class('image')
9
+
10
+ Spotlight::Page.find_each do |page|
11
+ next unless page.content.any? { |block| block.is_a? image }
12
+ page.content.select { |block| block.is_a?(image) && block.respond_to?(:class=) }.each do |block|
13
+ block.delete_field(:class)
14
+ block.attachment = Spotlight::Attachment.find(block.id).to_global_id rescue nil
15
+ end
16
+
17
+ page.update(content: page.content)
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,9 @@
1
+ class CreateBulkUpdates < ActiveRecord::Migration[5.2]
2
+ def change
3
+ create_table :spotlight_bulk_updates do |t|
4
+ t.string :file, null: false
5
+ t.references :exhibit
6
+ t.timestamps
7
+ end
8
+ end
9
+ end
@@ -1,9 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- Riiif::Image.file_resolver = Spotlight::CarrierwaveFileResolver.new
3
+ ActiveSupport::Reloader.to_prepare do
4
+ Riiif::Image.file_resolver = Spotlight::CarrierwaveFileResolver.new
4
5
 
5
- # Riiif::Image.authorization_service = IIIFAuthorizationService
6
+ # Riiif::Image.authorization_service = IIIFAuthorizationService
6
7
 
7
- # Riiif.not_found_image = 'app/assets/images/us_404.svg'
8
- #
9
- Riiif::Engine.config.cache_duration = 365.days
8
+ # Riiif.not_found_image = 'app/assets/images/us_404.svg'
9
+ #
10
+ Riiif::Engine.config.cache_duration = 365.days
11
+ end
@@ -73,7 +73,7 @@
73
73
  # These are set by default by Spotlight's configuration,
74
74
  # but you can customize them here, or in the SirTrevorRails::Block#custom_block_types method
75
75
  # Spotlight::Engine.config.sir_trevor_widgets = %w(
76
- # Heading Text List Quote Iframe Video Oembed Rule UploadedItems Browse BrowseGroupCategories
76
+ # Heading Text List Quote Iframe Video Oembed Rule UploadedItems Browse BrowseGroupCategories LinkToSearch
77
77
  # FeaturedPages SolrDocuments SolrDocumentsCarousel SolrDocumentsEmbed
78
78
  # SolrDocumentsFeatures SolrDocumentsGrid SearchResults
79
79
  # )
@@ -306,7 +306,7 @@
306
306
  <filter class="solr.EdgeNGramFilterFactory" minGramSize="3" maxGramSize="15" />
307
307
  </analyzer>
308
308
 
309
- <analyzer type="index">
309
+ <analyzer type="query">
310
310
  <tokenizer class="solr.ICUTokenizerFactory"/>
311
311
  <filter class="solr.ICUFoldingFilterFactory"/> <!-- NFKC, case folding, diacritics removed -->
312
312
  <filter class="solr.EnglishPossessiveFilterFactory"/>
@@ -73,7 +73,7 @@ module Migration
73
73
 
74
74
  old_file = File.new(filepath)
75
75
  image = contact.create_avatar { |i| i.image.store!(old_file) }
76
- iiif_tilesource = riiif.info_path(image.id)
76
+ iiif_tilesource = riiif.info_path(image)
77
77
  image.update(iiif_tilesource: iiif_tilesource, iiif_region: avatar_coordinates(contact))
78
78
  image
79
79
  end
@@ -87,7 +87,7 @@ module Migration
87
87
 
88
88
  old_file = File.new(filepath)
89
89
  image = upload.create_upload { |i| i.image.store!(old_file) }
90
- iiif_tilesource = riiif.info_path(image.id)
90
+ iiif_tilesource = riiif.info_path(image)
91
91
  image.update(iiif_tilesource: iiif_tilesource)
92
92
  upload.upload_id = image.id
93
93
  upload.save_and_index
@@ -95,7 +95,7 @@ module Migration
95
95
 
96
96
  def update_iiif_url(image)
97
97
  image.update(
98
- iiif_tilesource: riiif.info_url(image.id, host: hostname),
98
+ iiif_tilesource: riiif.info_url(image, host: hostname),
99
99
  iiif_region: coordinates(image)
100
100
  )
101
101
  end
@@ -17,6 +17,8 @@ require 'leaflet-rails'
17
17
  require 'i18n/active_record'
18
18
  require 'spotlight/upload_field_config'
19
19
  require 'riiif'
20
+ require 'faraday'
21
+ require 'faraday_middleware'
20
22
 
21
23
  module Spotlight
22
24
  ##
@@ -290,7 +292,19 @@ module Spotlight
290
292
 
291
293
  config.reindexing_batch_size = nil
292
294
  config.reindexing_batch_count = nil
295
+ config.hidden_job_classes = %w[Spotlight::ReindexJob]
296
+
297
+ config.bulk_actions_batch_size = 1000
298
+
299
+ config.bulk_updates = OpenStruct.new
300
+ config.bulk_updates.csv_id = 'Item ID'
301
+ config.bulk_updates.csv_title = 'Item Title'
302
+ config.bulk_updates.csv_visibility = 'Visibility'
303
+ config.bulk_updates.csv_tags_prefix = 'Tag:'
304
+ config.bulk_updates.csv_tags = 'Tag: %s'
293
305
 
294
306
  config.assign_default_roles_to_first_user = true
307
+
308
+ config.exhibit_roles = %w[admin curator viewer]
295
309
  end
296
310
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Spotlight
4
- VERSION = '3.0.0.rc4'
4
+ VERSION = '3.0.0.rc5'
5
5
  end
@@ -0,0 +1,124 @@
1
+ # frozen_string_literal: true
2
+
3
+ describe Spotlight::BulkActionsController, type: :controller do
4
+ routes { Spotlight::Engine.routes }
5
+ let(:exhibit) { FactoryBot.create(:skinny_exhibit) }
6
+
7
+ # rubocop:disable RSpec/BeforeAfterAll
8
+ before(:all) do
9
+ ActiveJob::Base.queue_adapter = :test
10
+ end
11
+
12
+ after(:all) do
13
+ ActiveJob::Base.queue_adapter = :inline
14
+ end
15
+ # rubocop:enable RSpec/BeforeAfterAll
16
+
17
+ describe 'when the user is not authorized' do
18
+ before do
19
+ sign_in FactoryBot.create(:exhibit_visitor)
20
+ end
21
+
22
+ describe 'POST change_visibility' do
23
+ it 'denies access' do
24
+ post :change_visibility, params: { exhibit_id: exhibit }
25
+ expect(response).to redirect_to main_app.root_path
26
+ expect(flash[:alert]).to be_present
27
+ end
28
+ end
29
+
30
+ describe 'POST add_tags' do
31
+ it 'denies access' do
32
+ post :add_tags, params: { exhibit_id: exhibit }
33
+ expect(response).to redirect_to main_app.root_path
34
+ expect(flash[:alert]).to be_present
35
+ end
36
+ end
37
+
38
+ describe 'POST remove_tags' do
39
+ it 'denies access' do
40
+ post :remove_tags, params: { exhibit_id: exhibit }
41
+ expect(response).to redirect_to main_app.root_path
42
+ expect(flash[:alert]).to be_present
43
+ end
44
+ end
45
+ end
46
+
47
+ describe 'when the user is a curator' do
48
+ before do
49
+ sign_in FactoryBot.create(:exhibit_curator, exhibit: exhibit)
50
+ end
51
+
52
+ let(:search) { FactoryBot.create(:search, exhibit: exhibit) }
53
+ let(:search_session) { instance_double('Blacklight::Search', query_params: { q: 'map' }) }
54
+
55
+ describe 'POST change_visibility' do
56
+ it 'redirects and sets a notice' do
57
+ allow(controller).to receive(:current_search_session).and_return(search_session)
58
+ request.env['HTTP_REFERER'] = '/referring_url'
59
+ post :change_visibility, params: { 'visibility' => 'private', 'q' => 'map', exhibit_id: exhibit }
60
+ expect(response).to redirect_to '/referring_url'
61
+ expect(flash[:notice]).to eq 'Visibility of 55 items is being updated.'
62
+ end
63
+
64
+ # rubocop:disable Style/MultilineBlockChain
65
+ it 'enqueues the job' do
66
+ allow(controller).to receive(:current_search_session).and_return(search_session)
67
+ expect do
68
+ post :change_visibility, params: { 'visibility' => 'private', 'q' => 'map', exhibit_id: exhibit }
69
+ end.to have_enqueued_job(Spotlight::ChangeVisibilityJob).with do |solr_params, exhb, visibility|
70
+ expect(solr_params).to.not be_nil
71
+ expect(exhb).to eq exhibit
72
+ expect(visibility).to eq 'private'
73
+ end
74
+ end
75
+ # rubocop:enable Style/MultilineBlockChain
76
+ end
77
+
78
+ describe 'POST add_tags' do
79
+ it 'redirects and sets a notice' do
80
+ allow(controller).to receive(:current_search_session).and_return(search_session)
81
+ request.env['HTTP_REFERER'] = '/referring_url'
82
+ post :add_tags, params: { 'tags' => 'howdy,planet', 'q' => 'map', exhibit_id: exhibit }
83
+ expect(response).to redirect_to '/referring_url'
84
+ expect(flash[:notice]).to eq 'Tags are being added for 55 items.'
85
+ end
86
+
87
+ # rubocop:disable Style/MultilineBlockChain
88
+ it 'enqueues the job' do
89
+ allow(controller).to receive(:current_search_session).and_return(search_session)
90
+ expect do
91
+ post :add_tags, params: { 'tags' => 'howdy,planet', 'q' => 'map', exhibit_id: exhibit }
92
+ end.to have_enqueued_job(Spotlight::AddTagsJob).with do |solr_params, exhb, tags|
93
+ expect(solr_params).to.not be_nil
94
+ expect(exhb).to eq exhibit
95
+ expect(tags).to eq %w[howdy planet]
96
+ end
97
+ end
98
+ # rubocop:enable Style/MultilineBlockChain
99
+ end
100
+
101
+ describe 'POST remove_tags' do
102
+ it 'redirects and sets a notice' do
103
+ allow(controller).to receive(:current_search_session).and_return(search_session)
104
+ request.env['HTTP_REFERER'] = '/referring_url'
105
+ post :remove_tags, params: { 'tags' => 'hello,world', 'q' => 'map', exhibit_id: exhibit }
106
+ expect(response).to redirect_to '/referring_url'
107
+ expect(flash[:notice]).to eq 'Tags are being removed for 55 items.'
108
+ end
109
+
110
+ # rubocop:disable Style/MultilineBlockChain
111
+ it 'enqueues the job' do
112
+ allow(controller).to receive(:current_search_session).and_return(search_session)
113
+ expect do
114
+ post :remove_tags, params: { 'tags' => 'howdy,planet', 'q' => 'map', exhibit_id: exhibit }
115
+ end.to have_enqueued_job(Spotlight::RemoveTagsJob).with do |solr_params, exhb, tags|
116
+ expect(solr_params).to.not be_nil
117
+ expect(exhb).to eq exhibit
118
+ expect(tags).to eq %w[howdy planet]
119
+ end
120
+ end
121
+ # rubocop:enable Style/MultilineBlockChain
122
+ end
123
+ end
124
+ end
@@ -0,0 +1,77 @@
1
+ # frozen_string_literal: true
2
+
3
+ describe Spotlight::BulkUpdatesController, type: :controller do
4
+ routes { Spotlight::Engine.routes }
5
+ let(:exhibit) { FactoryBot.create(:exhibit) }
6
+
7
+ describe 'when the user is not authorized' do
8
+ before do
9
+ sign_in FactoryBot.create(:exhibit_visitor)
10
+ end
11
+
12
+ describe 'GET edit' do
13
+ it 'denies access' do
14
+ get :edit, params: { exhibit_id: exhibit }
15
+ expect(response).to redirect_to main_app.root_path
16
+ expect(flash[:alert]).to be_present
17
+ end
18
+ end
19
+
20
+ describe 'POST download_template' do
21
+ it 'denies access' do
22
+ post :download_template, params: { exhibit_id: exhibit }
23
+ expect(response).to redirect_to main_app.root_path
24
+ expect(flash[:alert]).to be_present
25
+ end
26
+ end
27
+ end
28
+
29
+ describe 'when the user is a curator' do
30
+ before do
31
+ sign_in FactoryBot.create(:exhibit_curator, exhibit: exhibit)
32
+ end
33
+
34
+ describe 'GET edit' do
35
+ it 'is allowed' do
36
+ get :edit, params: { exhibit_id: exhibit }
37
+ expect(response).to be_successful
38
+ end
39
+ end
40
+
41
+ describe 'POST download_template' do
42
+ it 'downloads a CSV template' do
43
+ post :download_template, params: {
44
+ exhibit_id: exhibit,
45
+ reference_fields: { item_id: 1, item_title: 1 },
46
+ updatable_fields: { tags: 0, visibility: 1 }
47
+ }
48
+
49
+ content = CSV.parse(response.body)
50
+ expect(content.length).to eq 56
51
+ expect(content[0]).to eq ['Item ID', 'Item Title', 'Visibility']
52
+ end
53
+ end
54
+
55
+ describe 'PATCH download_template' do
56
+ before { ActiveJob::Base.queue_adapter = :test }
57
+
58
+ after { ActiveJob::Base.queue_adapter = :inline }
59
+
60
+ it 'uploads the given CSV template and passes it to a job' do
61
+ expect do
62
+ patch :update, params: {
63
+ exhibit_id: exhibit,
64
+ file: fixture_file_upload('spec/fixtures/bulk-update-template.csv', 'text/csv')
65
+ }
66
+ end.to(have_enqueued_job(Spotlight::ProcessBulkUpdatesCsvJob).with do |job_exhibit, uploader|
67
+ expect(job_exhibit).to eq exhibit
68
+ expect(uploader).to be_a Spotlight::BulkUpdate
69
+ expect(uploader.file_identifier).to eq 'bulk-update-template.csv'
70
+ end)
71
+
72
+ expect(flash[:notice]).to eq 'The CSV file was uploaded successfully.'
73
+ expect(response).to redirect_to(spotlight.edit_exhibit_bulk_updates_path(exhibit))
74
+ end
75
+ end
76
+ end
77
+ end
@@ -29,7 +29,7 @@ describe Spotlight::CatalogController, type: :controller do
29
29
  let(:search) { FactoryBot.create(:search, exhibit: exhibit) }
30
30
 
31
31
  it 'shows the item' do
32
- expect(controller).to receive(:add_breadcrumb).with('Home', exhibit_path(exhibit, q: ''))
32
+ expect(controller).to receive(:add_breadcrumb).with('Home', exhibit_path(exhibit))
33
33
  expect(controller).to receive(:add_breadcrumb).with('L&#39;AMERIQUE', exhibit_solr_document_path(exhibit, document))
34
34
  get :show, params: { exhibit_id: exhibit, id: 'dq287tq6352' }
35
35
  expect(response).to be_successful
@@ -38,7 +38,7 @@ describe Spotlight::CatalogController, type: :controller do
38
38
  it 'shows the item with breadcrumbs to the browse page' do
39
39
  allow(controller).to receive_messages(current_browse_category: search)
40
40
 
41
- expect(controller).to receive(:add_breadcrumb).with('Home', exhibit_path(exhibit, q: ''))
41
+ expect(controller).to receive(:add_breadcrumb).with('Home', exhibit_path(exhibit))
42
42
  expect(controller).to receive(:add_breadcrumb).with('Browse', exhibit_browse_index_path(exhibit))
43
43
  expect(controller).to receive(:add_breadcrumb).with(search.title, exhibit_browse_path(exhibit, search))
44
44
  expect(controller).to receive(:add_breadcrumb).with('L&#39;AMERIQUE', exhibit_solr_document_path(exhibit, document))
@@ -50,7 +50,7 @@ describe Spotlight::CatalogController, type: :controller do
50
50
  feature_page = FactoryBot.create(:feature_page, exhibit: exhibit)
51
51
  allow(controller).to receive_messages(current_page_context: feature_page)
52
52
 
53
- expect(controller).to receive(:add_breadcrumb).with('Home', exhibit_path(exhibit, q: ''))
53
+ expect(controller).to receive(:add_breadcrumb).with('Home', exhibit_path(exhibit))
54
54
  expect(controller).to receive(:add_breadcrumb).with(feature_page.title, [exhibit, feature_page])
55
55
  expect(controller).to receive(:add_breadcrumb).with('L&#39;AMERIQUE', exhibit_solr_document_path(exhibit, document))
56
56
  get :show, params: { exhibit_id: exhibit, id: 'dq287tq6352' }
@@ -61,7 +61,7 @@ describe Spotlight::CatalogController, type: :controller do
61
61
  home_page = FactoryBot.create(:home_page)
62
62
  allow(controller).to receive_messages(current_page_context: home_page)
63
63
 
64
- expect(controller).to receive(:add_breadcrumb).with('Home', exhibit_path(exhibit, q: ''))
64
+ expect(controller).to receive(:add_breadcrumb).with('Home', exhibit_path(exhibit))
65
65
  expect(controller).to receive(:add_breadcrumb).with('L&#39;AMERIQUE', exhibit_solr_document_path(exhibit, document))
66
66
  get :show, params: { exhibit_id: exhibit, id: 'dq287tq6352' }
67
67
  expect(response).to be_successful
@@ -80,8 +80,8 @@ describe Spotlight::CatalogController, type: :controller do
80
80
 
81
81
  describe 'GET index' do
82
82
  it 'shows the index when there are parameters' do
83
- expect(controller).to receive(:add_breadcrumb).with('Home', exhibit_path(exhibit, q: ''))
84
- expect(controller).to receive(:add_breadcrumb).with('Search results', search_exhibit_catalog_path(exhibit, q: 'map'))
83
+ expect(controller).to receive(:add_breadcrumb).with('Home', exhibit_path(exhibit))
84
+ expect(controller).to receive(:add_breadcrumb).with('Search results', search_exhibit_catalog_path(exhibit, q: 'map'), current: true)
85
85
  get :index, params: { exhibit_id: exhibit, q: 'map' }
86
86
  expect(response).to be_successful
87
87
  end
@@ -216,7 +216,7 @@ describe Spotlight::CatalogController, type: :controller do
216
216
  before { sign_in FactoryBot.create(:exhibit_curator, exhibit: exhibit) }
217
217
 
218
218
  it 'shows all the items' do
219
- expect(controller).to receive(:add_breadcrumb).with('Home', exhibit_path(exhibit, q: ''))
219
+ expect(controller).to receive(:add_breadcrumb).with('Home', exhibit_path(exhibit))
220
220
  expect(controller).to receive(:add_breadcrumb).with('Curation', exhibit_dashboard_path(exhibit))
221
221
  expect(controller).to receive(:add_breadcrumb).with('Items', admin_exhibit_catalog_path(exhibit))
222
222
  get :admin, params: { exhibit_id: exhibit }
@@ -299,7 +299,7 @@ describe Spotlight::CatalogController, type: :controller do
299
299
  end
300
300
 
301
301
  describe 'when the user is a site admin' do
302
- before { sign_in FactoryBot.create(:site_admin, exhibit: exhibit) }
302
+ before { sign_in FactoryBot.create(:site_admin) }
303
303
 
304
304
  describe 'GET show' do
305
305
  it 'has a solr_json serialization' do
@@ -499,22 +499,22 @@ describe Spotlight::CatalogController, type: :controller do
499
499
 
500
500
  before { allow(controller).to receive_messages(current_exhibit: current_exhibit) }
501
501
 
502
- describe 'render_save_this_search?' do
502
+ describe 'render_curator_actions?' do
503
503
  it 'returns false if we are on the items admin screen' do
504
504
  allow(controller).to receive(:can?).with(:curate, current_exhibit).and_return(true)
505
505
  allow(controller).to receive(:params).and_return(controller: 'spotlight/catalog', action: 'admin')
506
- expect(controller).not_to be_render_save_this_search
506
+ expect(controller).not_to be_render_curator_actions
507
507
  end
508
508
 
509
509
  it 'returns true if we are not on the items admin screen' do
510
510
  allow(controller).to receive(:can?).with(:curate, current_exhibit).and_return(true)
511
511
  allow(controller).to receive(:params).and_return(controller: 'spotlight/catalog', action: 'index')
512
- expect(controller).to be_render_save_this_search
512
+ expect(controller).to be_render_curator_actions
513
513
  end
514
514
 
515
515
  it 'returns false if a user cannot curate the object' do
516
516
  allow(controller).to receive(:can?).with(:curate, current_exhibit).and_return(false)
517
- expect(controller).not_to be_render_save_this_search
517
+ expect(controller).not_to be_render_curator_actions
518
518
  end
519
519
  end
520
520
  end