blacklight-spotlight 0.4.1 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (367) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +22 -8
  3. data/Rakefile +40 -39
  4. data/app/assets/javascripts/spotlight/blacklight_configuration.js +16 -0
  5. data/app/assets/javascripts/spotlight/blocks/resources_block.js +3 -1
  6. data/app/assets/stylesheets/spotlight/_blacklight_configuration.scss +2 -2
  7. data/app/assets/stylesheets/spotlight/_blacklight_overrides.scss +24 -0
  8. data/app/assets/stylesheets/spotlight/_header.scss +150 -47
  9. data/app/assets/stylesheets/spotlight/_pages.scss +62 -11
  10. data/app/assets/stylesheets/spotlight/_report_a_problem.scss +1 -0
  11. data/app/assets/stylesheets/spotlight/_spotlight.scss +1 -0
  12. data/app/builders/spotlight/bootstrap_breadcrumbs_builder.rb +28 -21
  13. data/app/controllers/spotlight/about_pages_controller.rb +25 -14
  14. data/app/controllers/spotlight/appearances_controller.rb +34 -30
  15. data/app/controllers/spotlight/application_controller.rb +2 -1
  16. data/app/controllers/spotlight/attachments_controller.rb +9 -7
  17. data/app/controllers/spotlight/browse_controller.rb +13 -9
  18. data/app/controllers/spotlight/catalog_controller.rb +179 -161
  19. data/app/controllers/spotlight/concerns/application_controller.rb +22 -20
  20. data/app/controllers/spotlight/concerns/catalog_search_context.rb +44 -0
  21. data/app/controllers/spotlight/confirmations_controller.rb +5 -2
  22. data/app/controllers/spotlight/contact_forms_controller.rb +13 -7
  23. data/app/controllers/spotlight/contacts_controller.rb +13 -4
  24. data/app/controllers/spotlight/custom_fields_controller.rb +48 -40
  25. data/app/controllers/spotlight/dashboards_controller.rb +17 -8
  26. data/app/controllers/spotlight/default_controller.rb +3 -1
  27. data/app/controllers/spotlight/exhibits_controller.rb +69 -62
  28. data/app/controllers/spotlight/feature_pages_controller.rb +21 -11
  29. data/app/controllers/spotlight/home_pages_controller.rb +6 -5
  30. data/app/controllers/spotlight/lock_controller.rb +3 -1
  31. data/app/controllers/spotlight/metadata_configurations_controller.rb +49 -0
  32. data/app/controllers/spotlight/pages_controller.rb +28 -18
  33. data/app/controllers/spotlight/resources/upload_controller.rb +53 -46
  34. data/app/controllers/spotlight/resources_controller.rb +9 -5
  35. data/app/controllers/spotlight/roles_controller.rb +26 -22
  36. data/app/controllers/spotlight/search_configurations_controller.rb +66 -0
  37. data/app/controllers/spotlight/searches_controller.rb +91 -82
  38. data/app/controllers/spotlight/solr_controller.rb +20 -13
  39. data/app/controllers/spotlight/tags_controller.rb +5 -3
  40. data/app/controllers/spotlight/versions_controller.rb +15 -12
  41. data/app/controllers/spotlight/view_configurations_controller.rb +17 -0
  42. data/app/helpers/spotlight/application_helper.rb +44 -32
  43. data/app/helpers/spotlight/browse_helper.rb +13 -1
  44. data/app/helpers/spotlight/crud_link_helpers.rb +22 -14
  45. data/app/helpers/spotlight/jcrop_helper.rb +4 -2
  46. data/app/helpers/spotlight/main_app_helpers.rb +45 -41
  47. data/app/helpers/spotlight/navbar_helper.rb +6 -0
  48. data/app/helpers/spotlight/pages_helper.rb +23 -15
  49. data/app/helpers/spotlight/roles_helper.rb +10 -4
  50. data/app/helpers/spotlight/search_configurations_helper.rb +22 -0
  51. data/app/helpers/spotlight/title_helper.rb +16 -13
  52. data/app/jobs/spotlight/add_uploads_from_csv.rb +13 -9
  53. data/app/jobs/spotlight/reindex_job.rb +9 -9
  54. data/app/jobs/spotlight/rename_sidecar_field_job.rb +3 -0
  55. data/app/mailers/spotlight/confirmation_mailer.rb +2 -0
  56. data/app/mailers/spotlight/indexing_complete_mailer.rb +4 -2
  57. data/app/models/ability.rb +3 -0
  58. data/app/models/concerns/spotlight/ar_light.rb +49 -25
  59. data/app/models/concerns/spotlight/blacklight_configuration_defaults.rb +25 -10
  60. data/app/models/concerns/spotlight/exhibit_analytics.rb +28 -0
  61. data/app/models/concerns/spotlight/image_derivatives.rb +25 -26
  62. data/app/models/concerns/spotlight/resources/open_graph.rb +23 -19
  63. data/app/models/concerns/spotlight/resources/web.rb +25 -24
  64. data/app/models/concerns/spotlight/solr_document.rb +40 -34
  65. data/app/models/concerns/spotlight/solr_document/active_model_concern.rb +29 -40
  66. data/app/models/concerns/spotlight/solr_document/atomic_updates.rb +22 -18
  67. data/app/models/concerns/spotlight/solr_document/finder.rb +23 -18
  68. data/app/models/concerns/spotlight/solr_document/spotlight_images.rb +43 -39
  69. data/app/models/concerns/spotlight/solr_document/uploaded_resource.rb +41 -29
  70. data/app/models/concerns/spotlight/user.rb +25 -19
  71. data/app/models/sir_trevor_rails/blocks/browse_block.rb +36 -30
  72. data/app/models/sir_trevor_rails/blocks/featured_pages_block.rb +24 -18
  73. data/app/models/sir_trevor_rails/blocks/oembed_block.rb +8 -4
  74. data/app/models/sir_trevor_rails/blocks/search_results_block.rb +29 -23
  75. data/app/models/sir_trevor_rails/blocks/solr_documents_block.rb +43 -42
  76. data/app/models/sir_trevor_rails/blocks/solr_documents_carousel_block.rb +16 -12
  77. data/app/models/sir_trevor_rails/blocks/solr_documents_embed_block.rb +7 -3
  78. data/app/models/sir_trevor_rails/blocks/solr_documents_features_block.rb +7 -3
  79. data/app/models/sir_trevor_rails/blocks/solr_documents_grid_block.rb +7 -3
  80. data/app/models/sir_trevor_rails/blocks/textable.rb +18 -18
  81. data/app/models/spotlight/ability.rb +32 -33
  82. data/app/models/spotlight/about_page.rb +3 -1
  83. data/app/models/spotlight/analytics/ga.rb +46 -27
  84. data/app/models/spotlight/attachment.rb +3 -1
  85. data/app/models/spotlight/blacklight_configuration.rb +146 -68
  86. data/app/models/spotlight/contact.rb +35 -30
  87. data/app/models/spotlight/contact_email.rb +6 -3
  88. data/app/models/spotlight/contact_form.rb +4 -3
  89. data/app/models/spotlight/custom_field.rb +41 -33
  90. data/app/models/spotlight/exhibit.rb +104 -130
  91. data/app/models/spotlight/feature_page.rb +9 -7
  92. data/app/models/spotlight/featured_image.rb +10 -10
  93. data/app/models/spotlight/field_metadata.rb +46 -0
  94. data/app/models/spotlight/home_page.rb +8 -5
  95. data/app/models/spotlight/lock.rb +4 -3
  96. data/app/models/spotlight/main_navigation.rb +9 -3
  97. data/app/models/spotlight/masthead.rb +17 -16
  98. data/app/models/spotlight/page.rb +16 -16
  99. data/app/models/spotlight/resource.rb +69 -22
  100. data/app/models/spotlight/resources/csv_upload.rb +8 -4
  101. data/app/models/spotlight/resources/upload.rb +68 -57
  102. data/app/models/spotlight/role.rb +30 -34
  103. data/app/models/spotlight/search.rb +74 -63
  104. data/app/models/spotlight/solr_document_sidecar.rb +17 -15
  105. data/app/serializers/spotlight/exhibit_export_serializer.rb +65 -29
  106. data/app/serializers/spotlight/page_representer.rb +10 -6
  107. data/app/uploaders/spotlight/attachment_uploader.rb +4 -6
  108. data/app/uploaders/spotlight/avatar_uploader.rb +4 -3
  109. data/app/uploaders/spotlight/featured_image_uploader.rb +15 -14
  110. data/app/uploaders/spotlight/item_uploader.rb +3 -1
  111. data/app/uploaders/spotlight/masthead_uploader.rb +4 -2
  112. data/app/views/catalog/_search_form.html.erb +24 -0
  113. data/app/views/shared/_browse_navbar.html.erb +1 -1
  114. data/app/views/shared/_exhibit_navbar.html.erb +1 -1
  115. data/app/views/spotlight/appearances/edit.html.erb +13 -45
  116. data/app/views/spotlight/catalog/_edit_default.html.erb +1 -1
  117. data/app/views/spotlight/custom_fields/_form.html.erb +1 -1
  118. data/app/views/spotlight/exhibits/edit.html.erb +4 -4
  119. data/app/views/spotlight/home_pages/_empty.html.erb +1 -3
  120. data/app/views/spotlight/home_pages/_page_options.html.erb +1 -1
  121. data/app/views/spotlight/{blacklight_configurations → metadata_configurations}/_metadata_field.html.erb +0 -0
  122. data/app/views/spotlight/{blacklight_configurations/edit_metadata_fields.html.erb → metadata_configurations/edit.html.erb} +1 -1
  123. data/app/views/spotlight/pages/show.html.erb +2 -2
  124. data/app/views/spotlight/search_configurations/_default_per_page.html.erb +5 -0
  125. data/app/views/spotlight/search_configurations/_document_index_view_types.html.erb +7 -0
  126. data/app/views/spotlight/search_configurations/_facets.html.erb +38 -0
  127. data/app/views/spotlight/search_configurations/_search_fields.html.erb +58 -0
  128. data/app/views/spotlight/search_configurations/_sort.html.erb +53 -0
  129. data/app/views/spotlight/search_configurations/edit.html.erb +46 -0
  130. data/app/views/spotlight/searches/_search.html.erb +1 -1
  131. data/app/views/spotlight/shared/_admin_sidebar.html.erb +0 -2
  132. data/app/views/spotlight/shared/_curation_sidebar.html.erb +2 -3
  133. data/app/views/spotlight/shared/_report_a_problem.html.erb +2 -2
  134. data/app/views/spotlight/sir_trevor/blocks/_oembed_block.html.erb +5 -1
  135. data/app/views/spotlight/sir_trevor/blocks/_solr_documents_block.html.erb +7 -5
  136. data/app/views/spotlight/sir_trevor/blocks/_solr_documents_carousel_block.html.erb +2 -2
  137. data/app/views/spotlight/sir_trevor/blocks/_solr_documents_embed_block.html.erb +7 -5
  138. data/app/views/spotlight/sir_trevor/blocks/_solr_documents_features_block.html.erb +2 -2
  139. data/app/views/spotlight/sir_trevor/blocks/_solr_documents_grid_block.html.erb +14 -9
  140. data/config/locales/spotlight.en.yml +94 -49
  141. data/config/routes.rb +11 -20
  142. data/db/migrate/20150410180014_add_taggings_counter_cache_to_tags.acts_as_taggable_on_engine.rb +15 -0
  143. data/db/migrate/20150410180015_add_missing_taggable_index.acts_as_taggable_on_engine.rb +10 -0
  144. data/db/migrate/20150410180016_change_collation_for_tag_names.acts_as_taggable_on_engine.rb +10 -0
  145. data/db/migrate/20150713160101_change_spotlight_searches_to_published.rb +5 -0
  146. data/db/migrate/20151016092343_remove_searchable_from_exhibit.rb +20 -0
  147. data/lib/blacklight/spotlight.rb +1 -1
  148. data/lib/generators/spotlight/install_generator.rb +27 -25
  149. data/lib/generators/spotlight/templates/catalog_controller.rb +7 -5
  150. data/lib/generators/spotlight/templates/jetty.rake +8 -2
  151. data/lib/generators/spotlight/templates/spotlight_helper.rb +3 -1
  152. data/lib/spotlight.rb +4 -2
  153. data/lib/spotlight/base.rb +21 -14
  154. data/lib/spotlight/catalog.rb +10 -9
  155. data/lib/spotlight/catalog/access_controls_enforcement.rb +30 -15
  156. data/lib/spotlight/config.rb +4 -2
  157. data/lib/spotlight/controller.rb +12 -11
  158. data/lib/spotlight/engine.rb +30 -22
  159. data/lib/spotlight/rails/routes.rb +7 -4
  160. data/lib/spotlight/version.rb +2 -1
  161. data/lib/tasks/spotlight_tasks.rake +56 -50
  162. data/spec/controllers/application_controller_spec.rb +13 -13
  163. data/spec/controllers/spotlight/about_pages_controller_spec.rb +63 -59
  164. data/spec/controllers/spotlight/appearances_controller_spec.rb +29 -24
  165. data/spec/controllers/spotlight/application_controller_spec.rb +3 -3
  166. data/spec/controllers/spotlight/attachments_controller_spec.rb +10 -10
  167. data/spec/controllers/spotlight/browse_controller_spec.rb +23 -25
  168. data/spec/controllers/spotlight/catalog_controller_spec.rb +82 -87
  169. data/spec/controllers/spotlight/confirmations_controller_spec.rb +13 -11
  170. data/spec/controllers/spotlight/contact_forms_controller_spec.rb +17 -12
  171. data/spec/controllers/spotlight/contacts_controller_spec.rb +36 -36
  172. data/spec/controllers/spotlight/custom_fields_controller_spec.rb +26 -26
  173. data/spec/controllers/spotlight/dashboards_controller_spec.rb +14 -14
  174. data/spec/controllers/spotlight/exhibits_controller_spec.rb +59 -54
  175. data/spec/controllers/spotlight/feature_pages_controller_spec.rb +59 -59
  176. data/spec/controllers/spotlight/home_pages_controller_spec.rb +28 -29
  177. data/spec/controllers/spotlight/metadata_configurations_controller_spec.rb +84 -0
  178. data/spec/controllers/spotlight/resources/upload_controller_spec.rb +42 -33
  179. data/spec/controllers/spotlight/resources_controller_spec.rb +25 -29
  180. data/spec/controllers/spotlight/roles_controller_spec.rb +37 -19
  181. data/spec/controllers/spotlight/search_configurations_controller_spec.rb +125 -0
  182. data/spec/controllers/spotlight/searches_controller_spec.rb +84 -63
  183. data/spec/controllers/spotlight/solr_controller_spec.rb +13 -14
  184. data/spec/controllers/spotlight/tags_controller_spec.rb +16 -16
  185. data/spec/controllers/spotlight/versions_controller_spec.rb +15 -18
  186. data/spec/controllers/spotlight/view_configurations_controller_spec.rb +31 -0
  187. data/spec/factories/contacts.rb +1 -3
  188. data/spec/factories/custom_fields.rb +2 -4
  189. data/spec/factories/exhibits.rb +4 -2
  190. data/spec/factories/pages.rb +8 -11
  191. data/spec/factories/resources.rb +4 -4
  192. data/spec/factories/searches.rb +10 -13
  193. data/spec/factories/tags.rb +0 -3
  194. data/spec/factories/users.rb +2 -4
  195. data/spec/features/about_page_spec.rb +19 -19
  196. data/spec/features/add_contacts_spec.rb +34 -34
  197. data/spec/features/add_custom_field_metadata_spec.rb +24 -26
  198. data/spec/features/add_item_bookmarklet_spec.rb +12 -12
  199. data/spec/features/browse_category_admin_spec.rb +39 -39
  200. data/spec/features/catalog_spec.rb +9 -10
  201. data/spec/features/confirm_email_spec.rb +10 -10
  202. data/spec/features/create_exhibit_spec.rb +18 -15
  203. data/spec/features/create_page_spec.rb +8 -8
  204. data/spec/features/curator_items.rb +3 -3
  205. data/spec/features/dashboard_spec.rb +15 -16
  206. data/spec/features/edit_contact_spec.rb +8 -10
  207. data/spec/features/edit_search_fields_spec.rb +79 -0
  208. data/spec/features/exhibits/add_tags_spec.rb +15 -16
  209. data/spec/features/exhibits/administration_spec.rb +25 -25
  210. data/spec/features/exhibits/custom_metadata_fields_spec.rb +41 -43
  211. data/spec/features/exhibits/edit_metadata_fields_spec.rb +19 -19
  212. data/spec/features/feature_page_spec.rb +49 -48
  213. data/spec/features/home_page_spec.rb +38 -38
  214. data/spec/features/import_exhibit_spec.rb +23 -20
  215. data/spec/features/item_admin_spec.rb +28 -29
  216. data/spec/features/javascript/about_page_admin_spec.rb +9 -9
  217. data/spec/features/javascript/block_controls_spec.rb +16 -18
  218. data/spec/features/javascript/blocks/featured_browse_categories_block_spec.rb +11 -12
  219. data/spec/features/javascript/blocks/featured_pages_block_spec.rb +12 -13
  220. data/spec/features/javascript/blocks/search_result_block_spec.rb +17 -17
  221. data/spec/features/javascript/blocks/solr_documents_block_spec.rb +67 -65
  222. data/spec/features/javascript/edit_in_place_spec.rb +30 -56
  223. data/spec/features/javascript/feature_page_admin_spec.rb +73 -59
  224. data/spec/features/javascript/home_page_edit_spec.rb +6 -6
  225. data/spec/features/javascript/metadata_admin_spec.rb +15 -15
  226. data/spec/features/javascript/multi_image_select_spec.rb +17 -18
  227. data/spec/features/javascript/preview_block_spec.rb +11 -12
  228. data/spec/features/javascript/rule_block_spec.rb +7 -7
  229. data/spec/features/javascript/search_config_admin_spec.rb +144 -0
  230. data/spec/features/javascript/search_context_spec.rb +41 -42
  231. data/spec/features/main_navigation_spec.rb +22 -22
  232. data/spec/features/metadata_admin_spec.rb +8 -8
  233. data/spec/features/multiple_exhibits_spec.rb +15 -17
  234. data/spec/features/report_a_problem_spec.rb +23 -17
  235. data/spec/features/site_masthead_spec.rb +46 -46
  236. data/spec/features/slideshow_spec.rb +8 -9
  237. data/spec/features/tags_admin_spec.rb +11 -11
  238. data/spec/features/upload_non_repository_item_spec.rb +32 -32
  239. data/spec/features/user_admin_spec.rb +7 -7
  240. data/spec/helpers/spotlight/application_helper_spec.rb +63 -56
  241. data/spec/helpers/spotlight/browse_helper_spec.rb +6 -6
  242. data/spec/helpers/spotlight/crud_link_helpers_spec.rb +58 -52
  243. data/spec/helpers/spotlight/main_app_helpers_spec.rb +44 -24
  244. data/spec/helpers/spotlight/navbar_helper_spec.rb +4 -4
  245. data/spec/helpers/spotlight/pages_helper_spec.rb +56 -37
  246. data/spec/helpers/spotlight/roles_helper_spec.rb +3 -3
  247. data/spec/helpers/spotlight/search_configurations_helper_spec.rb +24 -0
  248. data/spec/helpers/spotlight/title_helper_spec.rb +33 -35
  249. data/spec/jobs/spotlight/reindex_job_spec.rb +6 -6
  250. data/spec/jobs/spotlight/rename_sidecar_field_job_spec.rb +7 -7
  251. data/spec/lib/spotlight/catalog/access_controls_enforcement_spec.rb +41 -26
  252. data/spec/lib/spotlight/controller_spec.rb +10 -10
  253. data/spec/lib/spotlight/routes_spec.rb +4 -4
  254. data/spec/mailers/spotlight/indexing_complete_mailer_spec.rb +13 -13
  255. data/spec/models/sir_trevor_rails/blocks/solr_documents_block_spec.rb +8 -8
  256. data/spec/models/{spotlight/sir_trevor_blocks → sir_trevor_rails/blocks}/textable_spec.rb +7 -8
  257. data/spec/models/solr_document_spec.rb +49 -50
  258. data/spec/models/spotlight/ability_spec.rb +17 -20
  259. data/spec/models/spotlight/about_page_spec.rb +6 -6
  260. data/spec/models/spotlight/analytics/ga_spec.rb +2 -2
  261. data/spec/models/spotlight/blacklight_configuration_spec.rb +196 -133
  262. data/spec/models/spotlight/contact_email_spec.rb +28 -24
  263. data/spec/models/spotlight/contact_spec.rb +6 -7
  264. data/spec/models/spotlight/custom_field_spec.rb +51 -52
  265. data/spec/models/spotlight/exhibit_spec.rb +102 -60
  266. data/spec/models/spotlight/feature_page_spec.rb +32 -32
  267. data/spec/models/spotlight/featured_image_spec.rb +5 -5
  268. data/spec/models/spotlight/field_metadata_spec.rb +78 -0
  269. data/spec/models/spotlight/home_page_spec.rb +11 -20
  270. data/spec/models/spotlight/{spotlight_image_derivatives_spec.rb → image_derivatives_spec.rb} +2 -2
  271. data/spec/models/spotlight/main_navigation_spec.rb +7 -9
  272. data/spec/models/spotlight/masthead_spec.rb +6 -6
  273. data/spec/models/spotlight/page_spec.rb +26 -29
  274. data/spec/models/spotlight/resource_spec.rb +56 -26
  275. data/spec/models/spotlight/resources/open_graph_spec.rb +16 -18
  276. data/spec/models/spotlight/resources/upload_spec.rb +32 -35
  277. data/spec/models/spotlight/resources/web_spec.rb +9 -11
  278. data/spec/models/spotlight/role_spec.rb +20 -20
  279. data/spec/models/spotlight/search_spec.rb +32 -15
  280. data/spec/models/spotlight/solr_document/atomic_updates_spec.rb +34 -0
  281. data/spec/models/spotlight/{solr_document_images_spec.rb → solr_document/spotlight_images_spec.rb} +18 -10
  282. data/spec/models/spotlight/solr_document/uploaded_resource_spec.rb +52 -0
  283. data/spec/models/spotlight/solr_document_sidecar_spec.rb +3 -4
  284. data/spec/routing/spotlight/exhibit_catalog_spec.rb +5 -5
  285. data/spec/routing/spotlight/pages_routing_spec.rb +24 -25
  286. data/spec/serializers/spotlight/exhibit_export_serializer_spec.rb +88 -68
  287. data/spec/spec_helper.rb +13 -22
  288. data/spec/support/features/test_features_helpers.rb +50 -46
  289. data/spec/support/views/test_view_helpers.rb +1 -1
  290. data/spec/test_app_templates/Gemfile.extra +0 -1
  291. data/spec/test_app_templates/carrierwave.rb +2 -2
  292. data/spec/test_app_templates/catalog_controller.rb +42 -42
  293. data/spec/test_app_templates/lib/generators/test_app_generator.rb +20 -11
  294. data/spec/test_app_templates/spotlight_test.rake +3 -3
  295. data/spec/uploaders/spotlight/item_uploader_spec.rb +68 -0
  296. data/spec/views/_user_util_links.html.erb_spec.rb +14 -14
  297. data/spec/views/shared/_analytics.html.erb_spec.rb +4 -6
  298. data/spec/views/shared/_exhibit_masthead.html.erb_spec.rb +19 -20
  299. data/spec/views/shared/_exhibit_navbar.html.erb_spec.rb +129 -131
  300. data/spec/views/shared/_footer.html.erb_spec.rb +6 -7
  301. data/spec/views/shared/_header_navbar.html.erb_spec.rb +5 -5
  302. data/spec/views/spotlight/about_pages/_empty.html.erb_spec.rb +4 -4
  303. data/spec/views/spotlight/about_pages/_sidebar.html.erb_spec.rb +9 -11
  304. data/spec/views/spotlight/about_pages/index.html.erb_spec.rb +31 -28
  305. data/spec/views/spotlight/browse/_search.html.erb_spec.rb +6 -6
  306. data/spec/views/spotlight/browse/_sort_and_per_page.html.erb_spec.rb +10 -12
  307. data/spec/views/spotlight/browse/index.html.erb_spec.rb +6 -6
  308. data/spec/views/spotlight/browse/show.html.erb_spec.rb +19 -20
  309. data/spec/views/spotlight/catalog/_edit_default.html.erb_spec.rb +7 -7
  310. data/spec/views/spotlight/catalog/admin.html.erb_spec.rb +7 -7
  311. data/spec/views/spotlight/catalog/edit.html.erb_spec.rb +3 -6
  312. data/spec/views/spotlight/catalog/new.html.erb_spec.rb +8 -10
  313. data/spec/views/spotlight/contacts/edit.html.erb_spec.rb +8 -8
  314. data/spec/views/spotlight/dashboards/_analytics.html.erb_spec.rb +22 -22
  315. data/spec/views/spotlight/exhibits/edit.html.erb_spec.rb +7 -8
  316. data/spec/views/spotlight/feature_pages/_empty.html.erb_spec.rb +5 -5
  317. data/spec/views/spotlight/feature_pages/_sidebar.html.erb_spec.rb +24 -26
  318. data/spec/views/spotlight/home_pages/_empty.html.erb_spec.rb +13 -9
  319. data/spec/views/spotlight/home_pages/_sidebar.html.erb_spec.rb +6 -6
  320. data/spec/views/spotlight/metadata_configurations/_metadata_field.html.erb_spec.rb +26 -0
  321. data/spec/views/spotlight/metadata_configurations/edit.html.erb_spec.rb +22 -0
  322. data/spec/views/spotlight/pages/edit.html.erb_spec.rb +16 -16
  323. data/spec/views/spotlight/pages/index.html.erb_spec.rb +19 -17
  324. data/spec/views/spotlight/pages/new.html.erb_spec.rb +6 -6
  325. data/spec/views/spotlight/pages/show.html.erb_spec.rb +27 -28
  326. data/spec/views/spotlight/roles/index.html.erb_spec.rb +6 -6
  327. data/spec/views/spotlight/search_configurations/_search_fields.html.erb_spec.rb +54 -0
  328. data/spec/views/spotlight/search_configurations/_sort.html.erb_spec.rb +28 -0
  329. data/spec/views/spotlight/searches/_search.html.erb_spec.rb +20 -10
  330. data/spec/views/spotlight/searches/edit.html.erb_spec.rb +12 -11
  331. data/spec/views/spotlight/searches/index.html.erb_spec.rb +12 -7
  332. data/spec/views/spotlight/sir_trevor/blocks/_iframe_block.html.erb_spec.rb +7 -8
  333. data/spec/views/spotlight/sir_trevor/blocks/_rule_block.html.erb_spec.rb +4 -4
  334. data/spec/views/spotlight/sir_trevor/blocks/_solr_documents_block.html.erb_spec.rb +38 -0
  335. data/spec/views/spotlight/sir_trevor/blocks/_solr_documents_carousel_block.html.erb_spec.rb +7 -8
  336. data/spec/views/spotlight/sir_trevor/blocks/_solr_documents_embed_block.html.erb_spec.rb +18 -13
  337. data/spec/views/spotlight/sir_trevor/blocks/_solr_documents_features_block.html.erb_spec.rb +14 -12
  338. data/spec/views/spotlight/sir_trevor/blocks/_solr_documents_grid_block.html.erb_spec.rb +11 -12
  339. data/spec/views/spotlight/tags/index.html.erb_spec.rb +9 -9
  340. metadata +167 -83
  341. data/app/controllers/spotlight/blacklight_configurations_controller.rb +0 -101
  342. data/app/controllers/spotlight/resources/csv_controller.rb +0 -23
  343. data/app/forms/spotlight/appearance.rb +0 -86
  344. data/app/helpers/spotlight/attachments_helper.rb +0 -4
  345. data/app/helpers/spotlight/blacklight_configurations_helper.rb +0 -15
  346. data/app/jobs/spotlight/set_default_thumbnail_job.rb +0 -16
  347. data/app/models/spotlight/resources/csv.rb +0 -80
  348. data/app/uploaders/spotlight/csv_uploader.rb +0 -15
  349. data/app/views/spotlight/blacklight_configurations/edit_facet_fields.html.erb +0 -47
  350. data/app/views/spotlight/blacklight_configurations/edit_sort_fields.html.erb +0 -65
  351. data/app/views/spotlight/resources/csv/_form.html.erb +0 -17
  352. data/app/views/spotlight/resources/csv/new.html.erb +0 -3
  353. data/spec/controllers/spotlight/blacklight_configurations_controller_spec.rb +0 -167
  354. data/spec/features/edit_sort_fields_spec.rb +0 -42
  355. data/spec/features/exhibits/edit_facet_fields_spec.rb +0 -37
  356. data/spec/features/javascript/facet_admin_spec.rb +0 -36
  357. data/spec/features/search_facets_admin_spec.rb +0 -19
  358. data/spec/features/update_appearance_spec.rb +0 -58
  359. data/spec/helpers/spotlight/blacklight_configurations_helper_spec.rb +0 -12
  360. data/spec/models/spotlight/appearance_spec.rb +0 -33
  361. data/spec/models/spotlight/resources/csv_spec.rb +0 -101
  362. data/spec/models/spotlight/solr_document_atomic_updates_spec.rb +0 -29
  363. data/spec/models/spotlight/solr_document_uploaded_resource_spec.rb +0 -45
  364. data/spec/uploaders/item_uploader_spec.rb +0 -62
  365. data/spec/views/spotlight/blacklight_configuration/_metadata_field.html.erb_spec.rb +0 -27
  366. data/spec/views/spotlight/blacklight_configuration/edit_metadata_fields.html.erb_spec.rb +0 -23
  367. data/spec/views/spotlight/blacklight_configuration/edit_sort_fields.html.erb_spec.rb +0 -19
@@ -1,30 +1,40 @@
1
1
  module Spotlight
2
+ ##
3
+ # CRUD actions for feature pages
2
4
  class FeaturePagesController < PagesController
3
-
4
5
  load_and_authorize_resource through: :exhibit, instance_name: 'page'
5
- before_filter :attach_breadcrumbs
6
+ before_action :attach_breadcrumbs
6
7
 
7
8
  protected
9
+
8
10
  def attach_breadcrumbs
9
11
  super
10
12
 
11
- if action_name == 'edit'
12
- add_breadcrumb t(:'spotlight.curation.sidebar.feature_pages'), exhibit_feature_pages_path(@exhibit)
13
- end
14
-
15
13
  if @page
16
- add_breadcrumb @page.parent_page.title, [@page.exhibit, @page.parent_page] unless @page.top_level_page?
17
- add_breadcrumb @page.title, action_name == 'edit' ? [:edit, @page.exhibit, @page] : [@page.exhibit, @page]
14
+ attach_page_breadcrumbs
18
15
  elsif action_name == 'index'
19
- add_breadcrumb t(:'spotlight.curation.sidebar.header'), exhibit_dashboard_path(@exhibit)
16
+ attach_index_breadcrumbs
17
+ end
18
+ end
19
+
20
+ def attach_page_breadcrumbs
21
+ if action_name == 'edit'
20
22
  add_breadcrumb t(:'spotlight.curation.sidebar.feature_pages'), exhibit_feature_pages_path(@exhibit)
21
23
  end
24
+
25
+ add_breadcrumb @page.parent_page.title, [@page.exhibit, @page.parent_page] unless @page.top_level_page?
26
+ add_breadcrumb @page.title, action_name == 'edit' ? [:edit, @page.exhibit, @page] : [@page.exhibit, @page]
27
+ end
28
+
29
+ def attach_index_breadcrumbs
30
+ add_breadcrumb t(:'spotlight.curation.sidebar.header'), exhibit_dashboard_path(@exhibit)
31
+ add_breadcrumb t(:'spotlight.curation.sidebar.feature_pages'), exhibit_feature_pages_path(@exhibit)
22
32
  end
23
33
 
24
34
  def update_all_page_params
25
35
  params.require(:exhibit).permit(
26
- "feature_pages_attributes" => page_attributes,
27
- "home_page_attributes" => [:id, :title, :display_title]
36
+ 'feature_pages_attributes' => page_attributes,
37
+ 'home_page_attributes' => [:id, :title, :display_title]
28
38
  )
29
39
  end
30
40
 
@@ -1,11 +1,13 @@
1
1
  module Spotlight
2
+ ##
3
+ # CRUD actions for the exhibit home page
2
4
  class HomePagesController < Spotlight::PagesController
3
5
  include Blacklight::SearchHelper
4
6
  include Spotlight::Catalog
5
7
 
6
8
  load_and_authorize_resource through: :exhibit, singleton: true, instance_name: 'page'
7
9
 
8
- before_filter :attach_breadcrumbs, except: :show
10
+ before_action :attach_breadcrumbs, except: :show
9
11
 
10
12
  def edit
11
13
  add_breadcrumb t(:'spotlight.curation.sidebar.feature_pages'), exhibit_feature_pages_path(@exhibit)
@@ -18,11 +20,9 @@ module Spotlight
18
20
  end
19
21
 
20
22
  def show
21
- if @page.display_sidebar?
22
- @response, @document_list = get_search_results
23
- end
23
+ @response, @document_list = search_results({}, search_params_logic) if @page.display_sidebar?
24
24
 
25
- if @page.nil? or !@page.published?
25
+ if @page.nil? || !@page.published?
26
26
  render '/catalog/index'
27
27
  else
28
28
  render 'show'
@@ -30,6 +30,7 @@ module Spotlight
30
30
  end
31
31
 
32
32
  private
33
+
33
34
  alias_method :search_action_url, :exhibit_search_action_url
34
35
  alias_method :search_facet_url, :exhibit_search_facet_url
35
36
 
@@ -1,4 +1,6 @@
1
1
  module Spotlight
2
+ ##
3
+ # Locking mechanism for page-level locks
2
4
  class LockController < Spotlight::ApplicationController
3
5
  load_and_authorize_resource
4
6
 
@@ -6,7 +8,7 @@ module Spotlight
6
8
  def destroy
7
9
  @lock.destroy
8
10
 
9
- render text: "", status: 204
11
+ render text: '', status: 204
10
12
  end
11
13
  end
12
14
  end
@@ -0,0 +1,49 @@
1
+ module Spotlight
2
+ ##
3
+ # CRUD actions for Blacklight metadata fields (e.g. index/show fields for
4
+ # various view types)
5
+ class MetadataConfigurationsController < Spotlight::ApplicationController
6
+ before_action :authenticate_user!
7
+ load_and_authorize_resource :exhibit, class: Spotlight::Exhibit
8
+ load_and_authorize_resource :blacklight_configuration, through: :exhibit, singleton: true, parent: false
9
+
10
+ def show
11
+ respond_to do |format|
12
+ format.json do
13
+ render json: @blacklight_configuration.blacklight_config.index_fields.as_json
14
+ end
15
+ end
16
+ end
17
+
18
+ def edit
19
+ add_breadcrumb t(:'spotlight.exhibits.breadcrumb', title: @exhibit.title), @exhibit
20
+ add_breadcrumb t(:'spotlight.curation.sidebar.header'), exhibit_dashboard_path(@exhibit)
21
+ add_breadcrumb t(:'spotlight.curation.sidebar.metadata'), edit_exhibit_metadata_configuration_path(@exhibit)
22
+ end
23
+
24
+ def update
25
+ if @blacklight_configuration.update(exhibit_params)
26
+ flash[:notice] = t(:'helpers.submit.blacklight_configuration.updated', model: @blacklight_configuration.class.model_name.human.downcase)
27
+ redirect_to edit_exhibit_metadata_configuration_path(@exhibit)
28
+ else
29
+ render action: 'edit'
30
+ end
31
+ end
32
+
33
+ private
34
+
35
+ def exhibit_params
36
+ params.require(:blacklight_configuration).permit(
37
+ index_fields: [exhibit_configuration_index_params]
38
+ )
39
+ end
40
+
41
+ def exhibit_configuration_index_params
42
+ views = @blacklight_configuration.default_blacklight_config.view.keys | [:show]
43
+
44
+ @blacklight_configuration.blacklight_config.index_fields.keys.each_with_object({}) do |element, result|
45
+ result[element] = ([:enabled, :label, :weight] | views)
46
+ end
47
+ end
48
+ end
49
+ end
@@ -1,6 +1,8 @@
1
1
  module Spotlight
2
+ ##
3
+ # Base CRUD controller for pages
2
4
  class PagesController < Spotlight::ApplicationController
3
- before_filter :authenticate_user!, except: [:show]
5
+ before_action :authenticate_user!, except: [:show]
4
6
  load_and_authorize_resource :exhibit, class: Spotlight::Exhibit
5
7
 
6
8
  helper Openseadragon::OpenseadragonHelper
@@ -8,7 +10,7 @@ module Spotlight
8
10
  include Blacklight::Catalog::SearchContext
9
11
  include Spotlight::Catalog::AccessControlsEnforcement
10
12
 
11
- helper_method :get_search_results, :search_results, :fetch, :page_collection_name
13
+ helper_method :get_search_results, :search_results, :search_params_logic, :fetch, :page_collection_name
12
14
 
13
15
  # GET /exhibits/1/pages
14
16
  def index
@@ -62,7 +64,7 @@ module Spotlight
62
64
  @page.lock.delete if @page.lock
63
65
 
64
66
  if @page.update(page_params.merge(last_edited_by: current_user))
65
- redirect_to [@page.exhibit, @page], flash: { html_safe: true }, notice: view_context.safe_join([t(:'helpers.submit.page.updated', model: @page.class.model_name.human.downcase), undo_link], " ")
67
+ redirect_to [@page.exhibit, @page], flash: { html_safe: true }, notice: undo_notice(:updated)
66
68
  else
67
69
  render action: 'edit'
68
70
  end
@@ -72,28 +74,32 @@ module Spotlight
72
74
  def destroy
73
75
  @page.destroy
74
76
 
75
- redirect_to [@page.exhibit, page_collection_name], flash: { html_safe: true }, notice: view_context.safe_join([t(:'helpers.submit.page.destroyed', model: @page.class.model_name.human.downcase), undo_link], " ")
77
+ redirect_to [@page.exhibit, page_collection_name], flash: { html_safe: true }, notice: undo_notice(:destroyed)
76
78
  end
77
79
 
78
80
  def update_all
79
81
  notice = if @exhibit.update update_all_page_params
80
- t(:'helpers.submit.page.batch_updated', model: human_name)
81
- else
82
- t(:'helpers.submit.page.batch_error', model: human_name)
83
- end
82
+ t(:'helpers.submit.page.batch_updated', model: human_name)
83
+ else
84
+ t(:'helpers.submit.page.batch_error', model: human_name)
85
+ end
84
86
  redirect_to :back, notice: notice
85
87
  end
86
88
 
89
+ protected
90
+
87
91
  def _prefixes
88
92
  @_prefixes ||= super + ['catalog']
89
93
  end
90
94
 
91
95
  def undo_link
92
96
  return unless can? :manage, @page
93
- view_context.link_to(t(:'spotlight.versions.undo'), revert_version_path(@page.versions.last), :method => :post)
97
+ view_context.link_to(t(:'spotlight.versions.undo'), revert_version_path(@page.versions.last), method: :post)
94
98
  end
95
99
 
96
- protected
100
+ def undo_notice(key)
101
+ view_context.safe_join([t(:"helpers.submit.page.#{key}", model: @page.class.model_name.human.downcase), undo_link], ' ')
102
+ end
97
103
 
98
104
  ##
99
105
  # Browsing an exhibit should start a new search session
@@ -102,7 +108,7 @@ module Spotlight
102
108
  end
103
109
 
104
110
  def page_attributes
105
- [:id, :published, :title, :weight, :display_sidebar, :parent_page_id ]
111
+ [:id, :published, :title, :weight, :display_sidebar, :parent_page_id]
106
112
  end
107
113
 
108
114
  def allowed_page_params
@@ -110,17 +116,20 @@ module Spotlight
110
116
  end
111
117
 
112
118
  def featured_image_attributes
113
- [:source, :image, :remote_image_url, :document_global_id, :image_crop_x, :image_crop_y, :image_crop_w, :image_crop_h]
119
+ [
120
+ :source, :image, :remote_image_url, :document_global_id,
121
+ :image_crop_x, :image_crop_y, :image_crop_w, :image_crop_h
122
+ ]
114
123
  end
115
124
 
116
125
  def human_name
117
126
  @human_name ||= page_collection_name.humanize
118
127
  end
119
128
 
120
- alias page_collection_name controller_name
129
+ alias_method :page_collection_name, :controller_name
121
130
 
122
131
  def attach_breadcrumbs
123
- if view_context.current_page? "/"
132
+ if view_context.current_page? '/'
124
133
  add_breadcrumb t(:'spotlight.exhibits.breadcrumb', title: current_exhibit.title), main_app.root_path
125
134
  else
126
135
  add_breadcrumb t(:'spotlight.exhibits.breadcrumb', title: current_exhibit.title), spotlight.exhibit_root_path(current_exhibit)
@@ -128,9 +137,10 @@ module Spotlight
128
137
  end
129
138
 
130
139
  private
131
- # Only allow a trusted parameter "white list" through.
132
- def page_params
133
- params.require(controller_name.singularize).permit(allowed_page_params)
134
- end
140
+
141
+ # Only allow a trusted parameter "white list" through.
142
+ def page_params
143
+ params.require(controller_name.singularize).permit(allowed_page_params)
144
+ end
135
145
  end
136
146
  end
@@ -1,67 +1,74 @@
1
1
  # encoding: utf-8
2
2
  require 'csv'
3
3
 
4
- module Spotlight::Resources
5
- class UploadController < ApplicationController
6
- helper :all
4
+ module Spotlight
5
+ module Resources
6
+ ##
7
+ # Creating new exhibit items from single-item entry forms
8
+ # or batch CSV upload
9
+ class UploadController < ApplicationController
10
+ helper :all
7
11
 
8
- before_filter :authenticate_user!
12
+ before_action :authenticate_user!
9
13
 
10
- load_and_authorize_resource :exhibit, class: Spotlight::Exhibit
11
- before_filter :build_resource, only: [:new, :create, :template]
14
+ load_and_authorize_resource :exhibit, class: Spotlight::Exhibit
15
+ before_action :build_resource, only: [:new, :create, :template]
12
16
 
13
- load_and_authorize_resource class: 'Spotlight::Resources::Upload', through_association: "exhibit.resources", instance_name: 'resource'
14
- def new
15
- add_breadcrumb t(:'spotlight.exhibits.breadcrumb', title: @exhibit.title), exhibit_root_path(@exhibit)
16
- add_breadcrumb t(:'spotlight.curation.sidebar.header'), exhibit_dashboard_path(@exhibit)
17
- add_breadcrumb t(:'spotlight.curation.sidebar.items'), admin_exhibit_catalog_index_path(@exhibit)
18
- add_breadcrumb t(:'spotlight.resources.upload.new.header'), new_exhibit_resources_upload_path(@exhibit)
19
- end
17
+ load_and_authorize_resource class: 'Spotlight::Resources::Upload', through_association: 'exhibit.resources', instance_name: 'resource'
18
+ def new
19
+ add_breadcrumb t(:'spotlight.exhibits.breadcrumb', title: @exhibit.title), exhibit_root_path(@exhibit)
20
+ add_breadcrumb t(:'spotlight.curation.sidebar.header'), exhibit_dashboard_path(@exhibit)
21
+ add_breadcrumb t(:'spotlight.curation.sidebar.items'), admin_exhibit_catalog_index_path(@exhibit)
22
+ add_breadcrumb t(:'spotlight.resources.upload.new.header'), new_exhibit_resources_upload_path(@exhibit)
23
+ end
20
24
 
21
- def create
22
- @resource.attributes = resource_params
25
+ # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
26
+ def create
27
+ @resource.attributes = resource_params
23
28
 
24
- if @resource.save_and_commit
25
- flash[:notice] = t('spotlight.resources.upload.success')
26
- if params["add-and-continue"]
27
- redirect_to new_exhibit_resources_upload_path(@resource.exhibit)
29
+ if @resource.save_and_commit
30
+ flash[:notice] = t('spotlight.resources.upload.success')
31
+ if params['add-and-continue']
32
+ redirect_to new_exhibit_resources_upload_path(@resource.exhibit)
33
+ else
34
+ redirect_to admin_exhibit_catalog_index_path(@resource.exhibit, sort: :timestamp)
35
+ end
28
36
  else
37
+ flash[:error] = t('spotlight.resources.upload.error')
29
38
  redirect_to admin_exhibit_catalog_index_path(@resource.exhibit, sort: :timestamp)
30
39
  end
31
- else
32
- flash[:error] = t('spotlight.resources.upload.error')
33
- redirect_to admin_exhibit_catalog_index_path(@resource.exhibit, sort: :timestamp)
34
40
  end
35
- end
41
+ # rubocop:enable Metrics/AbcSize, Metrics/MethodLength
36
42
 
37
- def csv_upload
38
- file = csv_params[:url]
39
- csv = CSV.parse(file.read, {headers:true, return_headers: false, encoding: 'utf-8'}).map(&:to_hash)
40
- Spotlight::AddUploadsFromCSV.perform_later(csv, current_exhibit, current_user)
41
- flash[:notice] = t('spotlight.resources.upload.csv.success', file_name: file.original_filename)
42
- redirect_to :back
43
- end
43
+ def csv_upload
44
+ file = csv_params[:url]
45
+ csv = CSV.parse(file.read, headers: true, return_headers: false, encoding: 'utf-8').map(&:to_hash)
46
+ Spotlight::AddUploadsFromCSV.perform_later(csv, current_exhibit, current_user)
47
+ flash[:notice] = t('spotlight.resources.upload.csv.success', file_name: file.original_filename)
48
+ redirect_to :back
49
+ end
44
50
 
45
- def template
46
- render text: CSV.generate { |csv| csv << data_param_keys.unshift(:url) }, content_type: 'text/csv'
47
- end
51
+ def template
52
+ render text: CSV.generate { |csv| csv << data_param_keys.unshift(:url) }, content_type: 'text/csv'
53
+ end
48
54
 
49
- private
50
- def build_resource
51
- @resource ||= Spotlight::Resources::Upload.new exhibit: current_exhibit
52
- end
55
+ private
53
56
 
54
- def csv_params
55
- params.require(:resources_csv_upload).permit(:url)
56
- end
57
+ def build_resource
58
+ @resource ||= Spotlight::Resources::Upload.new exhibit: current_exhibit
59
+ end
57
60
 
58
- def resource_params
59
- params.require(:resources_upload).permit(:url, data: data_param_keys)
60
- end
61
+ def csv_params
62
+ params.require(:resources_csv_upload).permit(:url)
63
+ end
61
64
 
62
- def data_param_keys
63
- Spotlight::Resources::Upload.fields(current_exhibit).collect(&:field_name) + current_exhibit.custom_fields.collect(&:field)
64
- end
65
+ def resource_params
66
+ params.require(:resources_upload).permit(:url, data: data_param_keys)
67
+ end
65
68
 
69
+ def data_param_keys
70
+ Spotlight::Resources::Upload.fields(current_exhibit).map(&:field_name) + current_exhibit.custom_fields.map(&:field)
71
+ end
72
+ end
66
73
  end
67
74
  end
@@ -1,15 +1,16 @@
1
1
  module Spotlight
2
+ ##
3
+ # CRUD actions for exhibit resources
2
4
  class ResourcesController < Spotlight::ApplicationController
3
- before_filter :authenticate_user!, except: [:show]
5
+ before_action :authenticate_user!, except: [:show]
4
6
 
5
7
  load_and_authorize_resource :exhibit, class: Spotlight::Exhibit
6
- before_filter :build_resource, only: [:create]
8
+ before_action :build_resource, only: [:create]
7
9
 
8
10
  load_and_authorize_resource through: :exhibit
9
11
  helper_method :from_popup?
10
12
 
11
13
  def new
12
-
13
14
  @resource.attributes = resource_params if params[:resource]
14
15
  @resource = @resource.becomes_provider
15
16
 
@@ -21,13 +22,14 @@ module Spotlight
21
22
  end
22
23
  end
23
24
 
25
+ # rubocop:disable Metrics/MethodLength
24
26
  def create
25
27
  @resource.attributes = resource_params
26
28
  @resource = @resource.becomes_provider
27
29
 
28
30
  if @resource.save_and_commit
29
31
  if from_popup?
30
- render layout: false, text: "<html><script>window.close();</script></html>"
32
+ render layout: false, text: '<html><script>window.close();</script></html>'
31
33
  else
32
34
  redirect_to admin_exhibit_catalog_index_path(@resource.exhibit, sort: :timestamp)
33
35
  end
@@ -35,6 +37,7 @@ module Spotlight
35
37
  render action: 'new'
36
38
  end
37
39
  end
40
+ # rubocop:enable Metrics/MethodLength
38
41
 
39
42
  def reindex_all
40
43
  @exhibit.reindex_later
@@ -43,8 +46,9 @@ module Spotlight
43
46
  end
44
47
 
45
48
  protected
49
+
46
50
  def resource_params
47
- params.require(:resource).permit(:url)
51
+ params.require(:resource).permit(:url, data: params[:resource][:data].try(:keys))
48
52
  end
49
53
 
50
54
  def build_resource
@@ -1,57 +1,61 @@
1
1
  module Spotlight
2
+ ##
3
+ # CRUD actions for assigning exhibit roles to
4
+ # existing users
2
5
  class RolesController < Spotlight::ApplicationController
3
- before_filter :authenticate_user!
6
+ before_action :authenticate_user!
4
7
  load_and_authorize_resource :exhibit, class: Spotlight::Exhibit
5
8
  load_and_authorize_resource through: :exhibit, except: [:update_all]
6
9
 
7
10
  def index
8
11
  role = @exhibit.roles.build
9
12
  authorize! :edit, role
10
-
13
+
11
14
  add_breadcrumb t(:'spotlight.exhibits.breadcrumb', title: @exhibit.title), @exhibit
12
15
  add_breadcrumb t(:'spotlight.administration.sidebar.header'), exhibit_dashboard_path(@exhibit)
13
16
  add_breadcrumb t(:'spotlight.administration.sidebar.users'), exhibit_roles_path(@exhibit)
14
17
  end
15
18
 
16
19
  def update_all
17
- attrs = params.require(:exhibit).permit(:roles_attributes => [:id, :user_key, :role, :_destroy])
20
+ authorize_nested_attributes! exhibit_params[:roles_attributes], Role
18
21
 
19
- any_deleted = authorize_nested_attributes(attrs[:roles_attributes], Role)
22
+ any_deleted = exhibit_params[:roles_attributes].values.any? { |item| item['_destroy'].present? }
20
23
 
21
- if @exhibit.update(attrs)
22
- notice = any_deleted > 0 ? t(:'helpers.submit.role.destroyed') : t(:'helpers.submit.role.updated')
23
- redirect_to exhibit_roles_path(@exhibit), notice: notice
24
+ if @exhibit.update(exhibit_params)
25
+ notice = any_deleted ? t(:'helpers.submit.role.destroyed') : t(:'helpers.submit.role.updated')
26
+ redirect_to exhibit_roles_path(@exhibit), notice: notice
24
27
  else
25
28
  flash[:alert] = t(:'helpers.submit.role.batch_error')
26
29
  render action: 'index'
27
30
  end
28
-
29
31
  end
30
32
 
31
33
  protected
32
34
 
35
+ def exhibit_params
36
+ params.require(:exhibit).permit(roles_attributes: [:id, :user_key, :role, :_destroy])
37
+ end
33
38
 
34
39
  # When nested attributes are passed in, ensure we have authorization to update each row.
35
40
  # @param attr [Hash,Array] the nested attributes
36
41
  # @param klass [Class] the class that is getting created
37
42
  # @return [Integer] a count of the number of deleted records
38
- def authorize_nested_attributes(attrs, klass)
39
- attrs = attrs.values if attrs.is_a? Hash
40
- delete_count = 0
41
- attrs.each do |item|
42
- if item[:id]
43
- if item['_destroy'].present?
44
- authorize! :destroy, klass.find(item[:id])
45
- delete_count += 1
46
- else
47
- authorize! :update, klass.find(item[:id])
48
- end
43
+ def authorize_nested_attributes!(attrs, klass)
44
+ attrs.each do |_, item|
45
+ authorize_item item, klass
46
+ end
47
+ end
48
+
49
+ def authorize_item(item, klass)
50
+ if item[:id]
51
+ if item['_destroy'].present?
52
+ authorize! :destroy, klass.find(item[:id])
49
53
  else
50
- authorize! :create, klass
54
+ authorize! :update, klass.find(item[:id])
51
55
  end
56
+ else
57
+ authorize! :create, klass
52
58
  end
53
- delete_count
54
59
  end
55
-
56
60
  end
57
61
  end