sufia 6.0.0 → 6.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (290) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +2 -5
  3. data/CONTRIBUTING.md +4 -4
  4. data/Gemfile +2 -1
  5. data/History.md +69 -0
  6. data/README.md +84 -4
  7. data/SUFIA_VERSION +1 -1
  8. data/app/assets/images/zotero.png +0 -0
  9. data/app/assets/javascripts/sufia/featured_works.js +20 -3
  10. data/app/assets/stylesheets/generic_files.css.erb +2 -2
  11. data/app/assets/stylesheets/sufia.css.scss +2 -2
  12. data/app/assets/stylesheets/sufia/_buttons.scss +2 -2
  13. data/app/assets/stylesheets/sufia/_collections.scss +4 -4
  14. data/app/assets/stylesheets/sufia/_dashboard.scss +1 -1
  15. data/app/assets/stylesheets/sufia/_file-listing.scss +3 -0
  16. data/app/assets/stylesheets/sufia/_modal.scss +4 -0
  17. data/app/assets/stylesheets/sufia/_settings.scss +4 -3
  18. data/app/assets/stylesheets/sufia/_styles.scss +4 -0
  19. data/app/controllers/admin/stats_controller.rb +68 -0
  20. data/app/controllers/api/items_controller.rb +78 -0
  21. data/app/controllers/api/zotero_controller.rb +70 -0
  22. data/app/controllers/authorities_controller.rb +6 -5
  23. data/app/controllers/concerns/sufia/batch_edits_controller_behavior.rb +2 -1
  24. data/app/controllers/concerns/sufia/breadcrumbs.rb +1 -1
  25. data/app/controllers/concerns/sufia/depositors_controller_behavior.rb +11 -0
  26. data/app/controllers/concerns/sufia/files_controller/browse_everything.rb +1 -1
  27. data/app/controllers/concerns/sufia/files_controller/local_ingest_behavior.rb +1 -1
  28. data/app/controllers/concerns/sufia/files_controller_behavior.rb +23 -11
  29. data/app/controllers/concerns/sufia/my_controller_behavior.rb +1 -7
  30. data/app/controllers/concerns/sufia/users_controller_behavior.rb +1 -2
  31. data/app/controllers/my/collections_controller.rb +1 -0
  32. data/app/controllers/my/files_controller.rb +1 -1
  33. data/app/helpers/sufia/sufia_helper_behavior.rb +28 -16
  34. data/app/models/my_search_builder.rb +4 -0
  35. data/app/search_builders/sufia/my_search_builder_behavior.rb +20 -0
  36. data/app/search_builders/sufia/search_builder.rb +1 -1
  37. data/app/views/admin/stats/index.html.erb +68 -0
  38. data/app/views/collections/_action_menu.html.erb +22 -20
  39. data/app/views/collections/_collection.html.erb +1 -1
  40. data/app/views/collections/_form_for_select_collection.html.erb +5 -3
  41. data/app/views/generic_files/_show_actions.html.erb +4 -2
  42. data/app/views/generic_files/show.html.erb +1 -1
  43. data/app/views/layouts/sufia-dashboard.html.erb +5 -4
  44. data/app/views/layouts/sufia-one-column.html.erb +2 -0
  45. data/app/views/layouts/sufia-two-column.html.erb +6 -4
  46. data/app/views/my/_facet_layout.html.erb +2 -2
  47. data/app/views/my/_facets.html.erb +4 -6
  48. data/app/views/my/index.html.erb +4 -3
  49. data/app/views/users/_edit_primary.html.erb +18 -17
  50. data/app/views/users/_follower_modal.html.erb +5 -1
  51. data/app/views/users/_following_modal.html.erb +5 -1
  52. data/app/views/users/_user_info.html.erb +6 -1
  53. data/app/views/users/_zotero.html.erb +12 -0
  54. data/config/locales/sufia.en.yml +10 -1
  55. data/config/routes.rb +23 -1
  56. data/lib/generators/sufia/admin_stat_generator.rb +17 -0
  57. data/lib/generators/sufia/install_generator.rb +8 -3
  58. data/{sufia-models/lib/generators/sufia/models/templates/config/resque_admin.rb → lib/generators/sufia/templates/sufia/stats_admin.rb} +3 -3
  59. data/lib/generators/sufia/upgrade400_generator.rb +2 -2
  60. data/lib/sufia.rb +3 -0
  61. data/lib/sufia/arkivo.rb +11 -0
  62. data/lib/sufia/arkivo/actor.rb +95 -0
  63. data/lib/sufia/arkivo/config.rb +11 -0
  64. data/lib/sufia/arkivo/create_subscription_job.rb +67 -0
  65. data/lib/sufia/arkivo/metadata_munger.rb +51 -0
  66. data/lib/sufia/arkivo/schema_validator.rb +55 -0
  67. data/lib/sufia/form_builder.rb +1 -1
  68. data/lib/sufia/inflections.rb +3 -0
  69. data/lib/sufia/version.rb +1 -1
  70. data/lib/sufia/zotero.rb +6 -0
  71. data/lib/sufia/zotero/config.rb +15 -0
  72. data/solr_conf/conf/solrconfig.xml +11 -0
  73. data/spec/controllers/admin_stats_controller_spec.rb +73 -0
  74. data/spec/controllers/api/items_controller_spec.rb +476 -0
  75. data/spec/controllers/api/zotero_controller_spec.rb +178 -0
  76. data/spec/controllers/batch_edits_controller_spec.rb +7 -0
  77. data/spec/controllers/collections_controller_spec.rb +1 -1
  78. data/spec/controllers/dashboard_controller_spec.rb +1 -1
  79. data/spec/controllers/depositors_controller_spec.rb +9 -5
  80. data/spec/controllers/generic_files_controller_spec.rb +5 -4
  81. data/spec/controllers/mailbox_controller_spec.rb +2 -2
  82. data/spec/controllers/my/collections_controller_spec.rb +1 -2
  83. data/spec/controllers/my/files_controller_spec.rb +5 -5
  84. data/spec/controllers/my/shares_controller_spec.rb +15 -3
  85. data/spec/controllers/pages_controller_spec.rb +1 -1
  86. data/spec/controllers/users_controller_spec.rb +10 -9
  87. data/spec/factories/api_items.rb +91 -0
  88. data/spec/factories/generic_files.rb +4 -0
  89. data/spec/factories/users.rb +4 -4
  90. data/spec/features/featured_item_spec.rb +26 -0
  91. data/spec/features/ingest_upload_files_spec.rb +2 -3
  92. data/spec/features/proxy_spec.rb +0 -1
  93. data/spec/helpers/permissions_helper_spec.rb +2 -2
  94. data/spec/helpers/sufia_helper_spec.rb +11 -5
  95. data/spec/inputs/select_with_help_input_spec.rb +2 -2
  96. data/spec/javascripts/helpers/.gitkeep +0 -0
  97. data/spec/javascripts/helpers/jasmine-jquery.js +832 -0
  98. data/spec/javascripts/jasmine_spec.rb +31 -0
  99. data/spec/javascripts/notify_update_link_spec.js +8 -0
  100. data/spec/javascripts/single_use_link_spec.js.coffee +23 -0
  101. data/spec/javascripts/support/jasmine.yml +124 -0
  102. data/spec/javascripts/support/jasmine_helper.rb +15 -0
  103. data/spec/javascripts/terms_of_service_spec.js.coffee +32 -0
  104. data/spec/javascripts/toggle_icon_spec.js +11 -0
  105. data/spec/jobs/active_fedora_id_based_job_spec.rb +3 -3
  106. data/spec/jobs/import_url_job_spec.rb +0 -2
  107. data/spec/lib/sufia/arkivo/actor_spec.rb +139 -0
  108. data/spec/lib/sufia/arkivo/create_subscription_job_spec.rb +54 -0
  109. data/spec/lib/sufia/arkivo/metadata_munger_spec.rb +48 -0
  110. data/spec/lib/sufia/arkivo/schema_validator_spec.rb +65 -0
  111. data/spec/lib/sufia/upload_complete_behavior_spec.rb +1 -1
  112. data/spec/lib/sufia/user_stat_importer_spec.rb +60 -0
  113. data/spec/lib/sufia/zotero/config_spec.rb +30 -0
  114. data/spec/models/collection_spec.rb +36 -7
  115. data/spec/models/file_download_stat_spec.rb +5 -5
  116. data/spec/models/file_usage_spec.rb +23 -0
  117. data/spec/models/file_view_stat_spec.rb +6 -6
  118. data/spec/models/fits_datastream_spec.rb +0 -5
  119. data/spec/models/generic_file_spec.rb +49 -14
  120. data/spec/models/local_authority_spec.rb +1 -1
  121. data/spec/models/proxy_deposit_request_spec.rb +1 -1
  122. data/spec/models/trophy_spec.rb +8 -8
  123. data/spec/models/user_spec.rb +33 -0
  124. data/spec/presenters/sufia/collection_presenter_spec.rb +1 -1
  125. data/spec/routing/api_route_spec.rb +91 -0
  126. data/spec/routing/route_spec.rb +1 -1
  127. data/spec/services/generic_file_audit_service_spec.rb +44 -8
  128. data/spec/spec_helper.rb +18 -3
  129. data/spec/support/features.rb +0 -2
  130. data/spec/support/locations.rb +0 -21
  131. data/spec/support/rake.rb +41 -0
  132. data/spec/support/selectors.rb +0 -50
  133. data/spec/tasks/rake_spec.rb +33 -12
  134. data/spec/test_app_templates/lib/generators/test_app_generator.rb +12 -0
  135. data/spec/views/admin/stats/index.html.erb_spec.rb +45 -0
  136. data/spec/views/catalog/sort_and_per_page.html.erb_spec.rb +0 -1
  137. data/spec/views/dashboard/index_spec.rb +1 -1
  138. data/spec/views/generic_file/edit.html.erb_spec.rb +1 -1
  139. data/spec/views/generic_file/show.html.erb_spec.rb +1 -3
  140. data/spec/views/users/_follower_modal.html.erb_spec.rb +44 -7
  141. data/spec/views/users/_following_modal.html.erb_spec.rb +49 -7
  142. data/spec/views/users/edit.html.erb_spec.rb +72 -0
  143. data/spec/views/users/show.html.erb_spec.rb +1 -1
  144. data/sufia.gemspec +6 -2
  145. data/tasks/sufia-user.rake +14 -0
  146. metadata +130 -156
  147. data/spec/lib/sufia/id_service_spec.rb +0 -32
  148. data/spec/services/noid_spec.rb +0 -9
  149. data/spec/support/poltergeist.rb +0 -11
  150. data/spec/support/rake_output.rb +0 -20
  151. data/sufia-models/.gitignore +0 -17
  152. data/sufia-models/Gemfile +0 -4
  153. data/sufia-models/LICENSE.md +0 -177
  154. data/sufia-models/README.md +0 -39
  155. data/sufia-models/Rakefile +0 -1
  156. data/sufia-models/app/actors/sufia/generic_file/actor.rb +0 -137
  157. data/sufia-models/app/jobs/active_fedora_id_based_job.rb +0 -22
  158. data/sufia-models/app/jobs/active_fedora_pid_based_job.rb +0 -7
  159. data/sufia-models/app/jobs/audit_job.rb +0 -62
  160. data/sufia-models/app/jobs/batch_update_job.rb +0 -72
  161. data/sufia-models/app/jobs/characterize_job.rb +0 -10
  162. data/sufia-models/app/jobs/create_derivatives_job.rb +0 -14
  163. data/sufia-models/app/jobs/import_url_job.rb +0 -52
  164. data/sufia-models/app/jobs/ingest_local_file_job.rb +0 -46
  165. data/sufia-models/app/jobs/resolrize_job.rb +0 -9
  166. data/sufia-models/app/models/batch.rb +0 -36
  167. data/sufia-models/app/models/checksum_audit_log.rb +0 -21
  168. data/sufia-models/app/models/concerns/sufia/ability.rb +0 -61
  169. data/sufia-models/app/models/concerns/sufia/collection_behavior.rb +0 -24
  170. data/sufia-models/app/models/concerns/sufia/file_stat_utils.rb +0 -35
  171. data/sufia-models/app/models/concerns/sufia/generic_file.rb +0 -25
  172. data/sufia-models/app/models/concerns/sufia/generic_file/batches.rb +0 -28
  173. data/sufia-models/app/models/concerns/sufia/generic_file/characterization.rb +0 -89
  174. data/sufia-models/app/models/concerns/sufia/generic_file/content.rb +0 -13
  175. data/sufia-models/app/models/concerns/sufia/generic_file/derivatives.rb +0 -26
  176. data/sufia-models/app/models/concerns/sufia/generic_file/export.rb +0 -343
  177. data/sufia-models/app/models/concerns/sufia/generic_file/featured.rb +0 -11
  178. data/sufia-models/app/models/concerns/sufia/generic_file/full_text_indexing.rb +0 -43
  179. data/sufia-models/app/models/concerns/sufia/generic_file/indexing.rb +0 -14
  180. data/sufia-models/app/models/concerns/sufia/generic_file/metadata.rb +0 -98
  181. data/sufia-models/app/models/concerns/sufia/generic_file/mime_types.rb +0 -69
  182. data/sufia-models/app/models/concerns/sufia/generic_file/permissions.rb +0 -11
  183. data/sufia-models/app/models/concerns/sufia/generic_file/proxy_deposit.rb +0 -31
  184. data/sufia-models/app/models/concerns/sufia/generic_file/trophies.rb +0 -14
  185. data/sufia-models/app/models/concerns/sufia/generic_file/versions.rb +0 -16
  186. data/sufia-models/app/models/concerns/sufia/generic_file/virus_check.rb +0 -37
  187. data/sufia-models/app/models/concerns/sufia/model_methods.rb +0 -20
  188. data/sufia-models/app/models/concerns/sufia/user.rb +0 -137
  189. data/sufia-models/app/models/concerns/sufia/user_usage_stats.rb +0 -15
  190. data/sufia-models/app/models/datastreams/file_content_datastream.rb +0 -4
  191. data/sufia-models/app/models/datastreams/fits_datastream.rb +0 -152
  192. data/sufia-models/app/models/domain_term.rb +0 -5
  193. data/sufia-models/app/models/featured_work.rb +0 -22
  194. data/sufia-models/app/models/file_download_stat.rb +0 -18
  195. data/sufia-models/app/models/file_usage.rb +0 -34
  196. data/sufia-models/app/models/file_view_stat.rb +0 -18
  197. data/sufia-models/app/models/follow.rb +0 -12
  198. data/sufia-models/app/models/generic_file.rb +0 -3
  199. data/sufia-models/app/models/geo_names_resource.rb +0 -18
  200. data/sufia-models/app/models/group.rb +0 -8
  201. data/sufia-models/app/models/local_authority.rb +0 -86
  202. data/sufia-models/app/models/local_authority_entry.rb +0 -3
  203. data/sufia-models/app/models/proxy_deposit_request.rb +0 -85
  204. data/sufia-models/app/models/proxy_deposit_rights.rb +0 -4
  205. data/sufia-models/app/models/single_use_link.rb +0 -42
  206. data/sufia-models/app/models/subject_local_authority_entry.rb +0 -2
  207. data/sufia-models/app/models/sufia/avatar_uploader.rb +0 -20
  208. data/sufia-models/app/models/sufia/avatar_validator.rb +0 -8
  209. data/sufia-models/app/models/sufia/collection.rb +0 -5
  210. data/sufia-models/app/models/sufia/download.rb +0 -9
  211. data/sufia-models/app/models/sufia/orcid_validator.rb +0 -12
  212. data/sufia-models/app/models/sufia/pageview.rb +0 -9
  213. data/sufia-models/app/models/trophy.rb +0 -10
  214. data/sufia-models/app/models/user_stat.rb +0 -2
  215. data/sufia-models/app/models/version_committer.rb +0 -2
  216. data/sufia-models/app/services/sufia/analytics.rb +0 -50
  217. data/sufia-models/app/services/sufia/generic_file_audit_service.rb +0 -83
  218. data/sufia-models/app/services/sufia/generic_file_indexing_service.rb +0 -12
  219. data/sufia-models/app/services/sufia/id_service.rb +0 -45
  220. data/sufia-models/app/services/sufia/noid.rb +0 -22
  221. data/sufia-models/app/services/sufia/repository_audit_service.rb +0 -9
  222. data/sufia-models/config/locales/sufia.en.yml +0 -6
  223. data/sufia-models/lib/generators/sufia/models/abstract_migration_generator.rb +0 -30
  224. data/sufia-models/lib/generators/sufia/models/cached_stats_generator.rb +0 -24
  225. data/sufia-models/lib/generators/sufia/models/fulltext_generator.rb +0 -27
  226. data/sufia-models/lib/generators/sufia/models/install_generator.rb +0 -106
  227. data/sufia-models/lib/generators/sufia/models/orcid_field_generator.rb +0 -19
  228. data/sufia-models/lib/generators/sufia/models/proxies_generator.rb +0 -24
  229. data/sufia-models/lib/generators/sufia/models/templates/app/models/collection.rb +0 -2
  230. data/sufia-models/lib/generators/sufia/models/templates/config/analytics.yml +0 -9
  231. data/sufia-models/lib/generators/sufia/models/templates/config/clamav.rb +0 -1
  232. data/sufia-models/lib/generators/sufia/models/templates/config/mailboxer.rb +0 -17
  233. data/sufia-models/lib/generators/sufia/models/templates/config/mime_types.rb +0 -6
  234. data/sufia-models/lib/generators/sufia/models/templates/config/redis.yml +0 -9
  235. data/sufia-models/lib/generators/sufia/models/templates/config/redis_config.rb +0 -32
  236. data/sufia-models/lib/generators/sufia/models/templates/config/resque-pool.yml +0 -1
  237. data/sufia-models/lib/generators/sufia/models/templates/config/resque_config.rb +0 -5
  238. data/sufia-models/lib/generators/sufia/models/templates/config/setup_mail.rb +0 -3
  239. data/sufia-models/lib/generators/sufia/models/templates/config/solrconfig.xml +0 -223
  240. data/sufia-models/lib/generators/sufia/models/templates/config/sufia.rb +0 -144
  241. data/sufia-models/lib/generators/sufia/models/templates/migrations/acts_as_follower_migration.rb +0 -17
  242. data/sufia-models/lib/generators/sufia/models/templates/migrations/add_avatars_to_users.rb +0 -15
  243. data/sufia-models/lib/generators/sufia/models/templates/migrations/add_external_key_to_content_blocks.rb +0 -6
  244. data/sufia-models/lib/generators/sufia/models/templates/migrations/add_groups_to_users.rb +0 -11
  245. data/sufia-models/lib/generators/sufia/models/templates/migrations/add_ldap_attrs_to_user.rb +0 -27
  246. data/sufia-models/lib/generators/sufia/models/templates/migrations/add_linkedin_to_users.rb +0 -5
  247. data/sufia-models/lib/generators/sufia/models/templates/migrations/add_orcid_to_users.rb +0 -5
  248. data/sufia-models/lib/generators/sufia/models/templates/migrations/add_social_to_users.rb +0 -13
  249. data/sufia-models/lib/generators/sufia/models/templates/migrations/change_audit_log_pid_to_generic_file_id.rb +0 -5
  250. data/sufia-models/lib/generators/sufia/models/templates/migrations/change_proxy_deposit_request_pid_to_generic_file_id.rb +0 -5
  251. data/sufia-models/lib/generators/sufia/models/templates/migrations/create_checksum_audit_logs.rb +0 -19
  252. data/sufia-models/lib/generators/sufia/models/templates/migrations/create_content_blocks.rb +0 -10
  253. data/sufia-models/lib/generators/sufia/models/templates/migrations/create_featured_works.rb +0 -12
  254. data/sufia-models/lib/generators/sufia/models/templates/migrations/create_file_download_stats.rb +0 -12
  255. data/sufia-models/lib/generators/sufia/models/templates/migrations/create_file_view_stats.rb +0 -12
  256. data/sufia-models/lib/generators/sufia/models/templates/migrations/create_local_authorities.rb +0 -50
  257. data/sufia-models/lib/generators/sufia/models/templates/migrations/create_proxy_deposit_requests.rb +0 -16
  258. data/sufia-models/lib/generators/sufia/models/templates/migrations/create_proxy_deposit_rights.rb +0 -11
  259. data/sufia-models/lib/generators/sufia/models/templates/migrations/create_single_use_links.rb +0 -12
  260. data/sufia-models/lib/generators/sufia/models/templates/migrations/create_tinymce_assets.rb +0 -8
  261. data/sufia-models/lib/generators/sufia/models/templates/migrations/create_trophies.rb +0 -10
  262. data/sufia-models/lib/generators/sufia/models/templates/migrations/create_user_stats.rb +0 -19
  263. data/sufia-models/lib/generators/sufia/models/templates/migrations/create_version_committers.rb +0 -15
  264. data/sufia-models/lib/generators/sufia/models/update_content_blocks_generator.rb +0 -18
  265. data/sufia-models/lib/generators/sufia/models/upgrade400_generator.rb +0 -54
  266. data/sufia-models/lib/generators/sufia/models/upgrade600_generator.rb +0 -21
  267. data/sufia-models/lib/generators/sufia/models/usagestats_generator.rb +0 -19
  268. data/sufia-models/lib/generators/sufia/models/user_stats_generator.rb +0 -31
  269. data/sufia-models/lib/sufia/messages.rb +0 -66
  270. data/sufia-models/lib/sufia/models.rb +0 -34
  271. data/sufia-models/lib/sufia/models/active_fedora/redis.rb +0 -43
  272. data/sufia-models/lib/sufia/models/active_record/redis.rb +0 -56
  273. data/sufia-models/lib/sufia/models/engine.rb +0 -79
  274. data/sufia-models/lib/sufia/models/file_content.rb +0 -6
  275. data/sufia-models/lib/sufia/models/file_content/versions.rb +0 -21
  276. data/sufia-models/lib/sufia/models/resque.rb +0 -36
  277. data/sufia-models/lib/sufia/models/stats/user_stat_importer.rb +0 -108
  278. data/sufia-models/lib/sufia/models/user_local_directory_behavior.rb +0 -29
  279. data/sufia-models/lib/sufia/models/utils.rb +0 -22
  280. data/sufia-models/lib/sufia/models/version.rb +0 -5
  281. data/sufia-models/lib/sufia/models/virus_found_error.rb +0 -4
  282. data/sufia-models/lib/sufia/permissions.rb +0 -9
  283. data/sufia-models/lib/sufia/permissions/readable.rb +0 -20
  284. data/sufia-models/lib/sufia/permissions/writable.rb +0 -74
  285. data/sufia-models/lib/tasks/batch_cleanup.rake +0 -19
  286. data/sufia-models/lib/tasks/migrate.rake +0 -21
  287. data/sufia-models/lib/tasks/resque.rake +0 -13
  288. data/sufia-models/lib/tasks/stats_tasks.rake +0 -12
  289. data/sufia-models/lib/tasks/sufia-models_tasks.rake +0 -80
  290. data/sufia-models/sufia-models.gemspec +0 -52
@@ -0,0 +1,178 @@
1
+ require 'spec_helper'
2
+
3
+ describe API::ZoteroController, type: :controller do
4
+ let(:user) { FactoryGirl.find_or_create(:jill) }
5
+
6
+ context 'with an HTTP GET to /api/zotero' do
7
+ context 'with an unauthenticated client' do
8
+ before { get :initiate }
9
+
10
+ subject { response }
11
+
12
+ it { is_expected.to have_http_status(302) }
13
+ it 'describes the redirect' do
14
+ expect(flash[:alert]).to eq 'You need to sign in or sign up before continuing.'
15
+ end
16
+ end
17
+
18
+ context 'with an unregistered user' do
19
+ before do
20
+ allow_any_instance_of(Ability).to receive(:user_groups) { ['public'] }
21
+ sign_in user
22
+ get :initiate
23
+ end
24
+
25
+ subject { response }
26
+
27
+ it { is_expected.to have_http_status(302) }
28
+ it { is_expected.to redirect_to(root_path) }
29
+ it 'populates the flash with an alert' do
30
+ expect(flash[:alert]).to eq 'You are not authorized to perform this operation'
31
+ end
32
+ end
33
+
34
+ context 'with an invalid key/secret combo' do
35
+ before do
36
+ allow(Sufia::Zotero).to receive(:config) { broken_config }
37
+ sign_in user
38
+ get :initiate
39
+ end
40
+
41
+ let(:broken_config) { Hash.new(client_key: 'foo', client_secret: 'bar') }
42
+
43
+ subject { response }
44
+
45
+ it { is_expected.to have_http_status(302) }
46
+ it { is_expected.to redirect_to(root_path) }
47
+ it 'populates the flash with an alert' do
48
+ expect(flash[:alert]).to eq 'Invalid Zotero client key pair'
49
+ end
50
+ end
51
+
52
+ describe 'redirects to Zotero' do
53
+ before do
54
+ allow(controller).to receive(:client) { client }
55
+ allow(client).to receive(:get_request_token) { token }
56
+ allow_any_instance_of(User).to receive(:zotero_token=)
57
+ sign_in user
58
+ get :initiate
59
+ end
60
+
61
+ let(:token) { object_double(OAuth::RequestToken.new(client), authorize_url: 'https://www.zotero.org/oauth/authorize?identity=1&oauth_callback=http%3A%2F%2Ftest.host%2Fapi%2Fzotero%2Fcallback&oauth_token=bc2502f2750983c57224') }
62
+ let(:client) do
63
+ OAuth::Consumer.new(Sufia::Zotero.config['client_key'], Sufia::Zotero.config['client_secret'], {
64
+ site: 'https://www.zotero.org',
65
+ scheme: :query_string,
66
+ http_method: :get,
67
+ request_token_path: '/oauth/request',
68
+ access_token_path: '/oauth/access',
69
+ authorize_path: '/oauth/authorize'})
70
+ end
71
+
72
+ subject { response }
73
+
74
+ it { is_expected.to have_http_status(302) }
75
+ it 'has no flash alerts' do
76
+ expect(flash[:alert]).to be_nil
77
+ end
78
+ it 'has the expected callback URL' do
79
+ expect(subject.headers['Location']).to include('oauth_callback=http%3A%2F%2Ftest.host%2Fapi%2Fzotero%2Fcallback')
80
+ end
81
+ end
82
+ end
83
+
84
+ context 'with an HTTP POST/GET to /api/zotero/callback' do
85
+ context 'with an unauthenticated user' do
86
+ before { get :callback }
87
+
88
+ subject { response }
89
+
90
+ it { is_expected.to have_http_status(302) }
91
+ it 'describes the redirect' do
92
+ expect(flash[:alert]).to eq 'You need to sign in or sign up before continuing.'
93
+ end
94
+ end
95
+
96
+ context 'with an unregistered user' do
97
+ before do
98
+ allow_any_instance_of(Ability).to receive(:user_groups) { ['public'] }
99
+ sign_in user
100
+ get :callback
101
+ end
102
+
103
+ subject { response }
104
+
105
+ it { is_expected.to have_http_status(302) }
106
+ it { is_expected.to redirect_to(root_path) }
107
+ it 'populates the flash with an alert' do
108
+ expect(flash[:alert]).to eq 'You are not authorized to perform this operation'
109
+ end
110
+ end
111
+
112
+ context 'with a request lacking an oauth_token' do
113
+ before do
114
+ sign_in user
115
+ get :callback
116
+ end
117
+
118
+ subject { response }
119
+
120
+ it { is_expected.to have_http_status(302) }
121
+ it { is_expected.to redirect_to(routes.url_helpers.edit_profile_path(user)) }
122
+ it 'populates the flash with an alert' do
123
+ expect(flash[:alert]).to eq 'Malformed request from Zotero'
124
+ end
125
+ end
126
+
127
+ context 'with a non-matching token' do
128
+ before do
129
+ sign_in user
130
+ get :callback, oauth_token: 'woohoo', oauth_verifier: '12345'
131
+ end
132
+
133
+ subject { response }
134
+
135
+ it { is_expected.to have_http_status(302) }
136
+ it { is_expected.to redirect_to(routes.url_helpers.edit_profile_path(user)) }
137
+ it 'populates the flash with an alert' do
138
+ expect(flash[:alert]).to eq 'You have not yet connected to Zotero'
139
+ end
140
+ end
141
+
142
+ context 'with a signed-in, valid user' do
143
+ before do
144
+ allow_any_instance_of(User).to receive(:zotero_token) { user_token }
145
+ allow(Sufia.queue).to receive(:push)
146
+ sign_in user
147
+ get :callback, oauth_token: token_string, oauth_verifier: pin
148
+ end
149
+
150
+ let(:token_string) { 'woohoo' }
151
+ let(:pin) { '12345' }
152
+ let(:user_token) do
153
+ double('token',
154
+ params: { oauth_token: token_string },
155
+ get_access_token: access_token)
156
+ end
157
+ let(:zuserid) { 'myzuser' }
158
+ let(:access_token) do
159
+ double('access', params: { userID: zuserid })
160
+ end
161
+
162
+ subject { response }
163
+
164
+ it { is_expected.to have_http_status(302) }
165
+ it 'pushes an arkivo subscription job' do
166
+ expect(Sufia.queue).to have_received(:push).once
167
+ end
168
+ it { is_expected.to redirect_to(routes.url_helpers.profile_path(user)) }
169
+ it 'populates the flash with a notice' do
170
+ expect(flash[:alert]).to be_nil
171
+ expect(flash[:notice]).to eq 'Successfully connected to Zotero!'
172
+ end
173
+ it 'stores the userID in the user instance' do
174
+ expect(user.reload.zotero_userid).to eq zuserid
175
+ end
176
+ end
177
+ end
178
+ end
@@ -78,6 +78,13 @@ describe BatchEditsController, :type => :controller do
78
78
  expect(GenericFile.find(one.id).subject).to eq ["zzz"]
79
79
  expect(GenericFile.find(two.id).subject).to eq ["zzz"]
80
80
  end
81
+
82
+ it "should update permissions" do
83
+ put :update, update_type: "update", visibility: "authenticated"
84
+ expect(response).to be_redirect
85
+ expect(GenericFile.find(one.id).visibility).to eq "authenticated"
86
+ expect(GenericFile.find(two.id).visibility).to eq "authenticated"
87
+ end
81
88
  end
82
89
 
83
90
  end
@@ -111,7 +111,7 @@ describe CollectionsController do
111
111
  expect(asset_results["response"]["numFound"]).to eq 1
112
112
  doc = asset_results["response"]["docs"].first
113
113
  expect(doc["id"]).to eq @asset2.id
114
- afterupdate = GenericFile.find(@asset2.id)
114
+ GenericFile.find(@asset2.id)
115
115
  expect(doc[Solrizer.solr_name(:collection)]).to be_nil
116
116
  end
117
117
  end
@@ -66,7 +66,7 @@ describe DashboardController, :type => :controller do
66
66
  expect(assigns[:outgoing].first).to be_kind_of ProxyDepositRequest
67
67
  expect(assigns[:outgoing].first.generic_file_id).to eq(outgoing_file.id)
68
68
  end
69
- end
69
+ end
70
70
  end
71
71
 
72
72
  context "with activities" do
@@ -1,8 +1,8 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe DepositorsController, :type => :controller do
4
- let (:user) { FactoryGirl.find_or_create(:jill) }
5
- let (:grantee) { FactoryGirl.find_or_create(:archivist) }
3
+ describe DepositorsController do
4
+ let(:user) { FactoryGirl.create(:user) }
5
+ let(:grantee) { FactoryGirl.create(:user) }
6
6
 
7
7
  describe "as a logged in user" do
8
8
  before do
@@ -38,12 +38,16 @@ describe DepositorsController, :type => :controller do
38
38
  end
39
39
  describe "create" do
40
40
  it "should not be successful" do
41
- expect { post :create, user_id: user, grantee_id: grantee, format: 'json' }.to raise_error
41
+ post :create, user_id: user.user_key, grantee_id: grantee.user_key, format: 'json'
42
+ expect(response).to redirect_to root_path
43
+ expect(flash[:alert]).to eq "You are not authorized to access this page."
42
44
  end
43
45
  end
44
46
  describe "destroy" do
45
47
  it "should not be successful" do
46
- expect { delete :destroy, user_id: user, id: grantee, format: 'json' }.to raise_error
48
+ delete :destroy, user_id: user.user_key, id: grantee.user_key, format: 'json'
49
+ expect(response).to redirect_to root_path
50
+ expect(flash[:alert]).to eq "You are not authorized to access this page."
47
51
  end
48
52
  end
49
53
  end
@@ -524,6 +524,7 @@ describe GenericFilesController do
524
524
 
525
525
  describe "#show" do
526
526
  it "should show me the file and set breadcrumbs" do
527
+ expect(GenericFile).not_to receive(:find)
527
528
  expect(controller).to receive(:add_breadcrumb).with(I18n.t('sufia.dashboard.title'), Sufia::Engine.routes.url_helpers.dashboard_index_path)
528
529
  get :show, id: generic_file
529
530
  expect(response).to be_successful
@@ -565,14 +566,14 @@ describe GenericFilesController do
565
566
  end
566
567
 
567
568
  describe "batch creation" do
568
- context "when uploading a file" do
569
- let(:batch_id) { Sufia::IdService.mint }
569
+ context "when uploading a file" do
570
+ let(:batch_id) { ActiveFedora::Noid::Service.new.mint }
570
571
  let(:file1) { fixture_file_upload('/world.png','image/png') }
571
572
  let(:file2) { fixture_file_upload('/image.jpg','image/png') }
572
573
 
573
574
  it "should not create the batch on HTTP GET " do
574
575
  expect(Batch).to_not receive(:create)
575
- xhr :get, :new
576
+ xhr :get, :new
576
577
  expect(response).to be_success
577
578
  end
578
579
 
@@ -584,6 +585,6 @@ describe GenericFilesController do
584
585
  xhr :post, :create, files: [file2], Filename: 'An image', batch_id: batch_id, on_behalf_of: 'carolyn', terms_of_service: '1'
585
586
  expect(response).to be_success
586
587
  end
587
- end
588
+ end
588
589
  end
589
590
  end
@@ -40,8 +40,8 @@ describe MailboxController, :type => :controller do
40
40
  end
41
41
  describe "#delete_all" do
42
42
  it "should delete message" do
43
- rec1 = @another_user.send_message(@user, 'message 2', 'subject 2')
44
- rec2 = @another_user.send_message(@user, 'message 3', 'subject 3')
43
+ @another_user.send_message(@user, 'message 2', 'subject 2')
44
+ @another_user.send_message(@user, 'message 3', 'subject 3')
45
45
  expect(@user.mailbox.inbox.count).to eq(3)
46
46
  get :delete_all
47
47
  expect(@user.mailbox.inbox.count).to eq(0)
@@ -16,7 +16,7 @@ describe My::CollectionsController, :type => :controller do
16
16
  c.apply_depositor_metadata(@user.user_key)
17
17
  c.save!
18
18
  end
19
- @unrelated_collection = Collection.new(title: "test collection").tap do |c|
19
+ @unrelated_collection = Collection.create(title: "test collection") do |c|
20
20
  c.apply_depositor_metadata(FactoryGirl.create(:user).user_key)
21
21
  end
22
22
  end
@@ -27,7 +27,6 @@ describe My::CollectionsController, :type => :controller do
27
27
  end
28
28
 
29
29
  it "should paginate" do
30
- other_user = FactoryGirl.create(:user)
31
30
  Collection.new(title: "test collection").tap do |c|
32
31
  c.apply_depositor_metadata(@user.user_key)
33
32
  c.save!
@@ -58,14 +58,14 @@ describe My::FilesController, :type => :controller do
58
58
 
59
59
  describe "batch processing" do
60
60
  include Sufia::Messages
61
- let (:batch_id) {"batch_id"}
62
- let (:batch_id2) {"batch_id2"}
63
- let (:batch) {double}
61
+ let(:batch_id) {"batch_id"}
62
+ let(:batch_id2) {"batch_id2"}
63
+ let(:batch) {double}
64
64
 
65
65
  before do
66
66
  allow(batch).to receive(:id).and_return(batch_id)
67
- User.batchuser().send_message(user, single_success(batch_id, batch), success_subject, sanitize_text = false)
68
- User.batchuser().send_message(user, multiple_success(batch_id2, [batch]), success_subject, sanitize_text = false)
67
+ User.batchuser().send_message(user, single_success(batch_id, batch), success_subject, false)
68
+ User.batchuser().send_message(user, multiple_success(batch_id2, [batch]), success_subject, false)
69
69
  get :index
70
70
  end
71
71
  it "gets batches that are complete" do
@@ -14,21 +14,31 @@ describe My::SharesController, :type => :controller do
14
14
  let!(:my_file) { FactoryGirl.create(:generic_file, depositor: user) }
15
15
  let!(:unshared_file) { FactoryGirl.create(:generic_file, depositor: other_user) }
16
16
 
17
- let!(:shared_with_me) { FactoryGirl.create(:generic_file).tap do |r|
17
+ let!(:shared_with_me) {
18
+ FactoryGirl.create(:generic_file).tap do |r|
18
19
  r.apply_depositor_metadata other_user
19
20
  r.edit_users += [user.user_key]
20
21
  r.save!
21
22
  end
22
23
  }
23
24
 
24
- let!(:shared_with_someone_else) { FactoryGirl.create(:generic_file).tap do |r|
25
+ let!(:read_shared_with_me) {
26
+ FactoryGirl.create(:generic_file, depositor: other_user).tap do |r|
27
+ r.read_users += [user.user_key]
28
+ r.save!
29
+ end
30
+ }
31
+
32
+ let!(:shared_with_someone_else) {
33
+ FactoryGirl.create(:generic_file).tap do |r|
25
34
  r.apply_depositor_metadata user
26
35
  r.edit_users += [other_user.user_key]
27
36
  r.save!
28
37
  end
29
38
  }
30
39
 
31
- let!(:my_collection) { Collection.new(title: "My collection").tap do |c|
40
+ let!(:my_collection) {
41
+ Collection.new(title: "My collection").tap do |c|
32
42
  c.apply_depositor_metadata(user.user_key)
33
43
  c.save!
34
44
  end
@@ -68,6 +78,8 @@ describe My::SharesController, :type => :controller do
68
78
  expect(assigns[:document_list].map(&:id)).to_not include(shared_with_someone_else.id)
69
79
  # doesn't show my collections
70
80
  expect(assigns[:document_list].map(&:id)).to_not include my_collection.id
81
+ # doesn't show files I can see but have no edit access
82
+ expect(assigns[:document_list].map(&:id)).to_not include read_shared_with_me.id
71
83
  end
72
84
  end
73
85
  end
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe PagesController, :type => :controller do
4
- let (:page_name) {"about_page"}
4
+ let(:page_name) {"about_page"}
5
5
  context "content exists" do
6
6
  describe "GET #show" do
7
7
  let(:page) { ContentBlock.create!(name: page_name, value: "foo bar") }
@@ -28,6 +28,7 @@ describe UsersController, :type => :controller do
28
28
  let!(:trophy1) { user.trophies.create!(generic_file_id: file1.id) }
29
29
  let!(:trophy2) { user.trophies.create!(generic_file_id: file2.id) }
30
30
  let!(:trophy3) { user.trophies.create!(generic_file_id: file3.id) }
31
+ let!(:badtrophy) { user.trophies.create!(generic_file_id: 'not_a_generic_file') }
31
32
 
32
33
  it "show the user profile if user exists" do
33
34
  get :show, id: user.user_key
@@ -92,8 +93,8 @@ describe UsersController, :type => :controller do
92
93
  end
93
94
  end
94
95
  end
95
- describe "#edit" do
96
96
 
97
+ describe "#edit" do
97
98
  it "show edit form when user edits own profile" do
98
99
  get :edit, id: user.user_key
99
100
  expect(response).to be_success
@@ -124,7 +125,7 @@ describe UsersController, :type => :controller do
124
125
  end
125
126
  end
126
127
 
127
- describe "when the user has trophies" do
128
+ context "when the user has trophies" do
128
129
  let(:file1) { GenericFile.create { |f| f.apply_depositor_metadata(user) } }
129
130
  let(:file2) { GenericFile.create { |f| f.apply_depositor_metadata(user) } }
130
131
  let(:file3) { GenericFile.create { |f| f.apply_depositor_metadata(user) } }
@@ -235,7 +236,7 @@ describe UsersController, :type => :controller do
235
236
  end
236
237
  it "should remove a trophy" do
237
238
  expect {
238
- post :update, id: user.user_key, 'remove_trophy_'+file.id => 'yes'
239
+ post :update, id: user.user_key, 'remove_trophy_'+file.id => 'yes'
239
240
  }.to change { user.trophies.count }.by(-1)
240
241
  expect(response).to redirect_to(@routes.url_helpers.profile_path(user.to_param))
241
242
  expect(flash[:notice]).to include("Your profile has been updated")
@@ -296,21 +297,21 @@ describe UsersController, :type => :controller do
296
297
  end
297
298
 
298
299
  describe "#toggle_trophy" do
299
- let(:file) { GenericFile.create { |f| f.apply_depositor_metadata(user) } }
300
- let(:file_id) { file.id }
301
- let(:another_user) { FactoryGirl.create(:user) }
300
+ let(:file) { GenericFile.create { |f| f.apply_depositor_metadata(user) } }
301
+ let(:file_id) { file.id }
302
+ let(:another_user) { FactoryGirl.create(:user) }
302
303
 
303
- it "should trophy a file" do
304
+ it "should trophy a file" do
304
305
  post :toggle_trophy, {id: user.user_key, file_id: file_id}
305
306
  json = JSON.parse(response.body)
306
307
  expect(json['user_id']).to eq user.id
307
308
  expect(json['generic_file_id']).to eq file_id
308
309
  end
309
- it "should not trophy a file for a different user" do
310
+ it "should not trophy a file for a different user" do
310
311
  post :toggle_trophy, {id: another_user.user_key, file_id: file_id}
311
312
  expect(response).to_not be_success
312
313
  end
313
- it "should not trophy a file with no edit privs" do
314
+ it "should not trophy a file with no edit privs" do
314
315
  sign_in another_user
315
316
  post :toggle_trophy, {id: another_user.user_key, file_id: file_id}
316
317
  expect(response).to_not be_success
@@ -0,0 +1,91 @@
1
+ FactoryGirl.define do
2
+ factory :post_item, class: Hash do
3
+ skip_create
4
+
5
+ token 'mock_token'
6
+
7
+ metadata do
8
+ {
9
+ resourceType: 'Dataset',
10
+ title: 'Findings from NSF Study',
11
+ creators: [
12
+ {
13
+ creatorType: 'author',
14
+ firstName: 'John',
15
+ lastName: 'Doe'
16
+ },
17
+ {
18
+ creatorType: 'seriesEditor',
19
+ firstName: 'Rafael',
20
+ lastName: 'Nadal'
21
+ },
22
+ {
23
+ creatorType: 'inventor',
24
+ name: 'Babs McGee'
25
+ },
26
+ {
27
+ creatorType: 'contributor',
28
+ name: 'Jane Doeski'
29
+ },
30
+ ],
31
+ description: 'This was funded by the NSF in 2013',
32
+ publisher: 'National Science Foundation',
33
+ dateCreated: '2014-11-02T14:24:64Z',
34
+ basedNear: 'Paris, France',
35
+ identifier: 'isbn:1234567890',
36
+ url: 'http://example.org/nsf/2013/datasets/',
37
+ language: 'English--New Jerseyan',
38
+ rights: 'http://creativecommons.org/licenses/by-sa/3.0/us/',
39
+ tags: [
40
+ 'datasets',
41
+ 'nsf',
42
+ 'stuff'
43
+ ]
44
+ }
45
+ end
46
+
47
+ file do
48
+ {
49
+ base64: 'YXJraXZvCg==',
50
+ md5: 'f03313ded2feb96f0a641b8eb098aae0',
51
+ filename: 'file.txt',
52
+ contentType: 'text/plain'
53
+ }
54
+ end
55
+
56
+ initialize_with { attributes }
57
+ end
58
+
59
+ factory :put_item, class: Hash, parent: :post_item do
60
+ metadata do
61
+ {
62
+ resourceType: 'Article',
63
+ title: 'THE REAL FINDINGS',
64
+ creators: [
65
+ {
66
+ creatorType: 'author',
67
+ firstName: 'John',
68
+ lastName: 'Doe'
69
+ },
70
+ {
71
+ creatorType: 'inventor',
72
+ name: 'Babs McGee'
73
+ },
74
+ ],
75
+ rights: 'http://creativecommons.org/licenses/by-sa/3.0/us/',
76
+ tags: [
77
+ 'datasets'
78
+ ]
79
+ }
80
+ end
81
+
82
+ file do
83
+ {
84
+ base64: 'IyBIRUFERVIKClRoaXMgaXMgYSBwYXJhZ3JhcGghCg==',
85
+ md5: '3923077bb477097b8496dbcff5fa44b3',
86
+ filename: 'replaced.md',
87
+ contentType: 'text/x-markdown'
88
+ }
89
+ end
90
+ end
91
+ end