sufia 6.0.0 → 6.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.travis.yml +2 -5
- data/CONTRIBUTING.md +4 -4
- data/Gemfile +2 -1
- data/History.md +69 -0
- data/README.md +84 -4
- data/SUFIA_VERSION +1 -1
- data/app/assets/images/zotero.png +0 -0
- data/app/assets/javascripts/sufia/featured_works.js +20 -3
- data/app/assets/stylesheets/generic_files.css.erb +2 -2
- data/app/assets/stylesheets/sufia.css.scss +2 -2
- data/app/assets/stylesheets/sufia/_buttons.scss +2 -2
- data/app/assets/stylesheets/sufia/_collections.scss +4 -4
- data/app/assets/stylesheets/sufia/_dashboard.scss +1 -1
- data/app/assets/stylesheets/sufia/_file-listing.scss +3 -0
- data/app/assets/stylesheets/sufia/_modal.scss +4 -0
- data/app/assets/stylesheets/sufia/_settings.scss +4 -3
- data/app/assets/stylesheets/sufia/_styles.scss +4 -0
- data/app/controllers/admin/stats_controller.rb +68 -0
- data/app/controllers/api/items_controller.rb +78 -0
- data/app/controllers/api/zotero_controller.rb +70 -0
- data/app/controllers/authorities_controller.rb +6 -5
- data/app/controllers/concerns/sufia/batch_edits_controller_behavior.rb +2 -1
- data/app/controllers/concerns/sufia/breadcrumbs.rb +1 -1
- data/app/controllers/concerns/sufia/depositors_controller_behavior.rb +11 -0
- data/app/controllers/concerns/sufia/files_controller/browse_everything.rb +1 -1
- data/app/controllers/concerns/sufia/files_controller/local_ingest_behavior.rb +1 -1
- data/app/controllers/concerns/sufia/files_controller_behavior.rb +23 -11
- data/app/controllers/concerns/sufia/my_controller_behavior.rb +1 -7
- data/app/controllers/concerns/sufia/users_controller_behavior.rb +1 -2
- data/app/controllers/my/collections_controller.rb +1 -0
- data/app/controllers/my/files_controller.rb +1 -1
- data/app/helpers/sufia/sufia_helper_behavior.rb +28 -16
- data/app/models/my_search_builder.rb +4 -0
- data/app/search_builders/sufia/my_search_builder_behavior.rb +20 -0
- data/app/search_builders/sufia/search_builder.rb +1 -1
- data/app/views/admin/stats/index.html.erb +68 -0
- data/app/views/collections/_action_menu.html.erb +22 -20
- data/app/views/collections/_collection.html.erb +1 -1
- data/app/views/collections/_form_for_select_collection.html.erb +5 -3
- data/app/views/generic_files/_show_actions.html.erb +4 -2
- data/app/views/generic_files/show.html.erb +1 -1
- data/app/views/layouts/sufia-dashboard.html.erb +5 -4
- data/app/views/layouts/sufia-one-column.html.erb +2 -0
- data/app/views/layouts/sufia-two-column.html.erb +6 -4
- data/app/views/my/_facet_layout.html.erb +2 -2
- data/app/views/my/_facets.html.erb +4 -6
- data/app/views/my/index.html.erb +4 -3
- data/app/views/users/_edit_primary.html.erb +18 -17
- data/app/views/users/_follower_modal.html.erb +5 -1
- data/app/views/users/_following_modal.html.erb +5 -1
- data/app/views/users/_user_info.html.erb +6 -1
- data/app/views/users/_zotero.html.erb +12 -0
- data/config/locales/sufia.en.yml +10 -1
- data/config/routes.rb +23 -1
- data/lib/generators/sufia/admin_stat_generator.rb +17 -0
- data/lib/generators/sufia/install_generator.rb +8 -3
- data/{sufia-models/lib/generators/sufia/models/templates/config/resque_admin.rb → lib/generators/sufia/templates/sufia/stats_admin.rb} +3 -3
- data/lib/generators/sufia/upgrade400_generator.rb +2 -2
- data/lib/sufia.rb +3 -0
- data/lib/sufia/arkivo.rb +11 -0
- data/lib/sufia/arkivo/actor.rb +95 -0
- data/lib/sufia/arkivo/config.rb +11 -0
- data/lib/sufia/arkivo/create_subscription_job.rb +67 -0
- data/lib/sufia/arkivo/metadata_munger.rb +51 -0
- data/lib/sufia/arkivo/schema_validator.rb +55 -0
- data/lib/sufia/form_builder.rb +1 -1
- data/lib/sufia/inflections.rb +3 -0
- data/lib/sufia/version.rb +1 -1
- data/lib/sufia/zotero.rb +6 -0
- data/lib/sufia/zotero/config.rb +15 -0
- data/solr_conf/conf/solrconfig.xml +11 -0
- data/spec/controllers/admin_stats_controller_spec.rb +73 -0
- data/spec/controllers/api/items_controller_spec.rb +476 -0
- data/spec/controllers/api/zotero_controller_spec.rb +178 -0
- data/spec/controllers/batch_edits_controller_spec.rb +7 -0
- data/spec/controllers/collections_controller_spec.rb +1 -1
- data/spec/controllers/dashboard_controller_spec.rb +1 -1
- data/spec/controllers/depositors_controller_spec.rb +9 -5
- data/spec/controllers/generic_files_controller_spec.rb +5 -4
- data/spec/controllers/mailbox_controller_spec.rb +2 -2
- data/spec/controllers/my/collections_controller_spec.rb +1 -2
- data/spec/controllers/my/files_controller_spec.rb +5 -5
- data/spec/controllers/my/shares_controller_spec.rb +15 -3
- data/spec/controllers/pages_controller_spec.rb +1 -1
- data/spec/controllers/users_controller_spec.rb +10 -9
- data/spec/factories/api_items.rb +91 -0
- data/spec/factories/generic_files.rb +4 -0
- data/spec/factories/users.rb +4 -4
- data/spec/features/featured_item_spec.rb +26 -0
- data/spec/features/ingest_upload_files_spec.rb +2 -3
- data/spec/features/proxy_spec.rb +0 -1
- data/spec/helpers/permissions_helper_spec.rb +2 -2
- data/spec/helpers/sufia_helper_spec.rb +11 -5
- data/spec/inputs/select_with_help_input_spec.rb +2 -2
- data/spec/javascripts/helpers/.gitkeep +0 -0
- data/spec/javascripts/helpers/jasmine-jquery.js +832 -0
- data/spec/javascripts/jasmine_spec.rb +31 -0
- data/spec/javascripts/notify_update_link_spec.js +8 -0
- data/spec/javascripts/single_use_link_spec.js.coffee +23 -0
- data/spec/javascripts/support/jasmine.yml +124 -0
- data/spec/javascripts/support/jasmine_helper.rb +15 -0
- data/spec/javascripts/terms_of_service_spec.js.coffee +32 -0
- data/spec/javascripts/toggle_icon_spec.js +11 -0
- data/spec/jobs/active_fedora_id_based_job_spec.rb +3 -3
- data/spec/jobs/import_url_job_spec.rb +0 -2
- data/spec/lib/sufia/arkivo/actor_spec.rb +139 -0
- data/spec/lib/sufia/arkivo/create_subscription_job_spec.rb +54 -0
- data/spec/lib/sufia/arkivo/metadata_munger_spec.rb +48 -0
- data/spec/lib/sufia/arkivo/schema_validator_spec.rb +65 -0
- data/spec/lib/sufia/upload_complete_behavior_spec.rb +1 -1
- data/spec/lib/sufia/user_stat_importer_spec.rb +60 -0
- data/spec/lib/sufia/zotero/config_spec.rb +30 -0
- data/spec/models/collection_spec.rb +36 -7
- data/spec/models/file_download_stat_spec.rb +5 -5
- data/spec/models/file_usage_spec.rb +23 -0
- data/spec/models/file_view_stat_spec.rb +6 -6
- data/spec/models/fits_datastream_spec.rb +0 -5
- data/spec/models/generic_file_spec.rb +49 -14
- data/spec/models/local_authority_spec.rb +1 -1
- data/spec/models/proxy_deposit_request_spec.rb +1 -1
- data/spec/models/trophy_spec.rb +8 -8
- data/spec/models/user_spec.rb +33 -0
- data/spec/presenters/sufia/collection_presenter_spec.rb +1 -1
- data/spec/routing/api_route_spec.rb +91 -0
- data/spec/routing/route_spec.rb +1 -1
- data/spec/services/generic_file_audit_service_spec.rb +44 -8
- data/spec/spec_helper.rb +18 -3
- data/spec/support/features.rb +0 -2
- data/spec/support/locations.rb +0 -21
- data/spec/support/rake.rb +41 -0
- data/spec/support/selectors.rb +0 -50
- data/spec/tasks/rake_spec.rb +33 -12
- data/spec/test_app_templates/lib/generators/test_app_generator.rb +12 -0
- data/spec/views/admin/stats/index.html.erb_spec.rb +45 -0
- data/spec/views/catalog/sort_and_per_page.html.erb_spec.rb +0 -1
- data/spec/views/dashboard/index_spec.rb +1 -1
- data/spec/views/generic_file/edit.html.erb_spec.rb +1 -1
- data/spec/views/generic_file/show.html.erb_spec.rb +1 -3
- data/spec/views/users/_follower_modal.html.erb_spec.rb +44 -7
- data/spec/views/users/_following_modal.html.erb_spec.rb +49 -7
- data/spec/views/users/edit.html.erb_spec.rb +72 -0
- data/spec/views/users/show.html.erb_spec.rb +1 -1
- data/sufia.gemspec +6 -2
- data/tasks/sufia-user.rake +14 -0
- metadata +130 -156
- data/spec/lib/sufia/id_service_spec.rb +0 -32
- data/spec/services/noid_spec.rb +0 -9
- data/spec/support/poltergeist.rb +0 -11
- data/spec/support/rake_output.rb +0 -20
- data/sufia-models/.gitignore +0 -17
- data/sufia-models/Gemfile +0 -4
- data/sufia-models/LICENSE.md +0 -177
- data/sufia-models/README.md +0 -39
- data/sufia-models/Rakefile +0 -1
- data/sufia-models/app/actors/sufia/generic_file/actor.rb +0 -137
- data/sufia-models/app/jobs/active_fedora_id_based_job.rb +0 -22
- data/sufia-models/app/jobs/active_fedora_pid_based_job.rb +0 -7
- data/sufia-models/app/jobs/audit_job.rb +0 -62
- data/sufia-models/app/jobs/batch_update_job.rb +0 -72
- data/sufia-models/app/jobs/characterize_job.rb +0 -10
- data/sufia-models/app/jobs/create_derivatives_job.rb +0 -14
- data/sufia-models/app/jobs/import_url_job.rb +0 -52
- data/sufia-models/app/jobs/ingest_local_file_job.rb +0 -46
- data/sufia-models/app/jobs/resolrize_job.rb +0 -9
- data/sufia-models/app/models/batch.rb +0 -36
- data/sufia-models/app/models/checksum_audit_log.rb +0 -21
- data/sufia-models/app/models/concerns/sufia/ability.rb +0 -61
- data/sufia-models/app/models/concerns/sufia/collection_behavior.rb +0 -24
- data/sufia-models/app/models/concerns/sufia/file_stat_utils.rb +0 -35
- data/sufia-models/app/models/concerns/sufia/generic_file.rb +0 -25
- data/sufia-models/app/models/concerns/sufia/generic_file/batches.rb +0 -28
- data/sufia-models/app/models/concerns/sufia/generic_file/characterization.rb +0 -89
- data/sufia-models/app/models/concerns/sufia/generic_file/content.rb +0 -13
- data/sufia-models/app/models/concerns/sufia/generic_file/derivatives.rb +0 -26
- data/sufia-models/app/models/concerns/sufia/generic_file/export.rb +0 -343
- data/sufia-models/app/models/concerns/sufia/generic_file/featured.rb +0 -11
- data/sufia-models/app/models/concerns/sufia/generic_file/full_text_indexing.rb +0 -43
- data/sufia-models/app/models/concerns/sufia/generic_file/indexing.rb +0 -14
- data/sufia-models/app/models/concerns/sufia/generic_file/metadata.rb +0 -98
- data/sufia-models/app/models/concerns/sufia/generic_file/mime_types.rb +0 -69
- data/sufia-models/app/models/concerns/sufia/generic_file/permissions.rb +0 -11
- data/sufia-models/app/models/concerns/sufia/generic_file/proxy_deposit.rb +0 -31
- data/sufia-models/app/models/concerns/sufia/generic_file/trophies.rb +0 -14
- data/sufia-models/app/models/concerns/sufia/generic_file/versions.rb +0 -16
- data/sufia-models/app/models/concerns/sufia/generic_file/virus_check.rb +0 -37
- data/sufia-models/app/models/concerns/sufia/model_methods.rb +0 -20
- data/sufia-models/app/models/concerns/sufia/user.rb +0 -137
- data/sufia-models/app/models/concerns/sufia/user_usage_stats.rb +0 -15
- data/sufia-models/app/models/datastreams/file_content_datastream.rb +0 -4
- data/sufia-models/app/models/datastreams/fits_datastream.rb +0 -152
- data/sufia-models/app/models/domain_term.rb +0 -5
- data/sufia-models/app/models/featured_work.rb +0 -22
- data/sufia-models/app/models/file_download_stat.rb +0 -18
- data/sufia-models/app/models/file_usage.rb +0 -34
- data/sufia-models/app/models/file_view_stat.rb +0 -18
- data/sufia-models/app/models/follow.rb +0 -12
- data/sufia-models/app/models/generic_file.rb +0 -3
- data/sufia-models/app/models/geo_names_resource.rb +0 -18
- data/sufia-models/app/models/group.rb +0 -8
- data/sufia-models/app/models/local_authority.rb +0 -86
- data/sufia-models/app/models/local_authority_entry.rb +0 -3
- data/sufia-models/app/models/proxy_deposit_request.rb +0 -85
- data/sufia-models/app/models/proxy_deposit_rights.rb +0 -4
- data/sufia-models/app/models/single_use_link.rb +0 -42
- data/sufia-models/app/models/subject_local_authority_entry.rb +0 -2
- data/sufia-models/app/models/sufia/avatar_uploader.rb +0 -20
- data/sufia-models/app/models/sufia/avatar_validator.rb +0 -8
- data/sufia-models/app/models/sufia/collection.rb +0 -5
- data/sufia-models/app/models/sufia/download.rb +0 -9
- data/sufia-models/app/models/sufia/orcid_validator.rb +0 -12
- data/sufia-models/app/models/sufia/pageview.rb +0 -9
- data/sufia-models/app/models/trophy.rb +0 -10
- data/sufia-models/app/models/user_stat.rb +0 -2
- data/sufia-models/app/models/version_committer.rb +0 -2
- data/sufia-models/app/services/sufia/analytics.rb +0 -50
- data/sufia-models/app/services/sufia/generic_file_audit_service.rb +0 -83
- data/sufia-models/app/services/sufia/generic_file_indexing_service.rb +0 -12
- data/sufia-models/app/services/sufia/id_service.rb +0 -45
- data/sufia-models/app/services/sufia/noid.rb +0 -22
- data/sufia-models/app/services/sufia/repository_audit_service.rb +0 -9
- data/sufia-models/config/locales/sufia.en.yml +0 -6
- data/sufia-models/lib/generators/sufia/models/abstract_migration_generator.rb +0 -30
- data/sufia-models/lib/generators/sufia/models/cached_stats_generator.rb +0 -24
- data/sufia-models/lib/generators/sufia/models/fulltext_generator.rb +0 -27
- data/sufia-models/lib/generators/sufia/models/install_generator.rb +0 -106
- data/sufia-models/lib/generators/sufia/models/orcid_field_generator.rb +0 -19
- data/sufia-models/lib/generators/sufia/models/proxies_generator.rb +0 -24
- data/sufia-models/lib/generators/sufia/models/templates/app/models/collection.rb +0 -2
- data/sufia-models/lib/generators/sufia/models/templates/config/analytics.yml +0 -9
- data/sufia-models/lib/generators/sufia/models/templates/config/clamav.rb +0 -1
- data/sufia-models/lib/generators/sufia/models/templates/config/mailboxer.rb +0 -17
- data/sufia-models/lib/generators/sufia/models/templates/config/mime_types.rb +0 -6
- data/sufia-models/lib/generators/sufia/models/templates/config/redis.yml +0 -9
- data/sufia-models/lib/generators/sufia/models/templates/config/redis_config.rb +0 -32
- data/sufia-models/lib/generators/sufia/models/templates/config/resque-pool.yml +0 -1
- data/sufia-models/lib/generators/sufia/models/templates/config/resque_config.rb +0 -5
- data/sufia-models/lib/generators/sufia/models/templates/config/setup_mail.rb +0 -3
- data/sufia-models/lib/generators/sufia/models/templates/config/solrconfig.xml +0 -223
- data/sufia-models/lib/generators/sufia/models/templates/config/sufia.rb +0 -144
- data/sufia-models/lib/generators/sufia/models/templates/migrations/acts_as_follower_migration.rb +0 -17
- data/sufia-models/lib/generators/sufia/models/templates/migrations/add_avatars_to_users.rb +0 -15
- data/sufia-models/lib/generators/sufia/models/templates/migrations/add_external_key_to_content_blocks.rb +0 -6
- data/sufia-models/lib/generators/sufia/models/templates/migrations/add_groups_to_users.rb +0 -11
- data/sufia-models/lib/generators/sufia/models/templates/migrations/add_ldap_attrs_to_user.rb +0 -27
- data/sufia-models/lib/generators/sufia/models/templates/migrations/add_linkedin_to_users.rb +0 -5
- data/sufia-models/lib/generators/sufia/models/templates/migrations/add_orcid_to_users.rb +0 -5
- data/sufia-models/lib/generators/sufia/models/templates/migrations/add_social_to_users.rb +0 -13
- data/sufia-models/lib/generators/sufia/models/templates/migrations/change_audit_log_pid_to_generic_file_id.rb +0 -5
- data/sufia-models/lib/generators/sufia/models/templates/migrations/change_proxy_deposit_request_pid_to_generic_file_id.rb +0 -5
- data/sufia-models/lib/generators/sufia/models/templates/migrations/create_checksum_audit_logs.rb +0 -19
- data/sufia-models/lib/generators/sufia/models/templates/migrations/create_content_blocks.rb +0 -10
- data/sufia-models/lib/generators/sufia/models/templates/migrations/create_featured_works.rb +0 -12
- data/sufia-models/lib/generators/sufia/models/templates/migrations/create_file_download_stats.rb +0 -12
- data/sufia-models/lib/generators/sufia/models/templates/migrations/create_file_view_stats.rb +0 -12
- data/sufia-models/lib/generators/sufia/models/templates/migrations/create_local_authorities.rb +0 -50
- data/sufia-models/lib/generators/sufia/models/templates/migrations/create_proxy_deposit_requests.rb +0 -16
- data/sufia-models/lib/generators/sufia/models/templates/migrations/create_proxy_deposit_rights.rb +0 -11
- data/sufia-models/lib/generators/sufia/models/templates/migrations/create_single_use_links.rb +0 -12
- data/sufia-models/lib/generators/sufia/models/templates/migrations/create_tinymce_assets.rb +0 -8
- data/sufia-models/lib/generators/sufia/models/templates/migrations/create_trophies.rb +0 -10
- data/sufia-models/lib/generators/sufia/models/templates/migrations/create_user_stats.rb +0 -19
- data/sufia-models/lib/generators/sufia/models/templates/migrations/create_version_committers.rb +0 -15
- data/sufia-models/lib/generators/sufia/models/update_content_blocks_generator.rb +0 -18
- data/sufia-models/lib/generators/sufia/models/upgrade400_generator.rb +0 -54
- data/sufia-models/lib/generators/sufia/models/upgrade600_generator.rb +0 -21
- data/sufia-models/lib/generators/sufia/models/usagestats_generator.rb +0 -19
- data/sufia-models/lib/generators/sufia/models/user_stats_generator.rb +0 -31
- data/sufia-models/lib/sufia/messages.rb +0 -66
- data/sufia-models/lib/sufia/models.rb +0 -34
- data/sufia-models/lib/sufia/models/active_fedora/redis.rb +0 -43
- data/sufia-models/lib/sufia/models/active_record/redis.rb +0 -56
- data/sufia-models/lib/sufia/models/engine.rb +0 -79
- data/sufia-models/lib/sufia/models/file_content.rb +0 -6
- data/sufia-models/lib/sufia/models/file_content/versions.rb +0 -21
- data/sufia-models/lib/sufia/models/resque.rb +0 -36
- data/sufia-models/lib/sufia/models/stats/user_stat_importer.rb +0 -108
- data/sufia-models/lib/sufia/models/user_local_directory_behavior.rb +0 -29
- data/sufia-models/lib/sufia/models/utils.rb +0 -22
- data/sufia-models/lib/sufia/models/version.rb +0 -5
- data/sufia-models/lib/sufia/models/virus_found_error.rb +0 -4
- data/sufia-models/lib/sufia/permissions.rb +0 -9
- data/sufia-models/lib/sufia/permissions/readable.rb +0 -20
- data/sufia-models/lib/sufia/permissions/writable.rb +0 -74
- data/sufia-models/lib/tasks/batch_cleanup.rake +0 -19
- data/sufia-models/lib/tasks/migrate.rake +0 -21
- data/sufia-models/lib/tasks/resque.rake +0 -13
- data/sufia-models/lib/tasks/stats_tasks.rake +0 -12
- data/sufia-models/lib/tasks/sufia-models_tasks.rake +0 -80
- data/sufia-models/sufia-models.gemspec +0 -52
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
|
2
|
+
|
|
3
|
+
class Admin::StatsController < ApplicationController
|
|
4
|
+
def index
|
|
5
|
+
# total user count
|
|
6
|
+
@users_count = User.count
|
|
7
|
+
|
|
8
|
+
# The most recent users to join
|
|
9
|
+
@users_stats = params.fetch(:users_stats, {})
|
|
10
|
+
@recent_users = recent_users
|
|
11
|
+
|
|
12
|
+
# Query Solr for top depositors
|
|
13
|
+
@active_users = top_depositors
|
|
14
|
+
|
|
15
|
+
# Count of documents by permissions
|
|
16
|
+
@files_count = document_by_permission
|
|
17
|
+
|
|
18
|
+
# Query Solr for top file formats
|
|
19
|
+
@top_formats = top_formats
|
|
20
|
+
|
|
21
|
+
render 'index'
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
private
|
|
25
|
+
|
|
26
|
+
def top_depositors_count
|
|
27
|
+
count = params[:dep_count].to_i
|
|
28
|
+
count.in?(5..20) ? count : 5
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def document_by_permission
|
|
32
|
+
files_count = {}
|
|
33
|
+
files_count[:total] = GenericFile.count
|
|
34
|
+
files_count[:public] = GenericFile.where(Solrizer.solr_name('read_access_group', :symbol) => 'public').count
|
|
35
|
+
files_count[:registered] = GenericFile.where(Solrizer.solr_name('read_access_group', :symbol) =>'registered').count
|
|
36
|
+
files_count[:private] = files_count[:total] - (files_count[:registered] + files_count[:public])
|
|
37
|
+
files_count
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def top_depositors
|
|
41
|
+
depositor_key = Solrizer.solr_name('depositor', :stored_searchable, type: :string)
|
|
42
|
+
top_data(depositor_key, top_depositors_count)
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def top_formats
|
|
46
|
+
format_key = Solrizer.solr_name('file_format', Solrizer::Descriptor.new(:string, :indexed, :multivalued))
|
|
47
|
+
top_data(format_key, 5)
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def top_data (key, limit)
|
|
51
|
+
query_url = "#{ActiveFedora.solr_config[:url]}/terms?terms.fl=#{key}&terms.sort=count&terms.limit=#{limit}&wt=json&omitHeader=true"
|
|
52
|
+
# Parse JSON response (looks like {"terms":{"depositor_tesim":["mjg36",3]}} for depositor)
|
|
53
|
+
json = open(query_url).read
|
|
54
|
+
tuples = JSON.parse(json)['terms'][key] rescue []
|
|
55
|
+
# Change to hash where keys = logins and values = counts
|
|
56
|
+
Hash[*tuples]
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def recent_users
|
|
60
|
+
# users since date
|
|
61
|
+
if @users_stats[:start_date]
|
|
62
|
+
return User.where('created_at >= ?', @users_stats[:start_date])
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
# 5 most recent
|
|
66
|
+
User.order('created_at DESC').limit(5)
|
|
67
|
+
end
|
|
68
|
+
end
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
module API
|
|
2
|
+
# Adds an endpoint that consumes and RESTfully emits JSON from Arkivo
|
|
3
|
+
# representing new and updated Zotero-managed publications. An item in the
|
|
4
|
+
# Zotero parlance is mapped to a GenericFile in Sufia.
|
|
5
|
+
class ItemsController < ApplicationController
|
|
6
|
+
skip_before_action :verify_authenticity_token
|
|
7
|
+
before_filter :validate_item, only: [:create, :update]
|
|
8
|
+
before_filter :authorize_token
|
|
9
|
+
before_filter :my_load_and_authorize_resource, only: [:update, :destroy, :show]
|
|
10
|
+
|
|
11
|
+
attr_reader :item
|
|
12
|
+
|
|
13
|
+
def create
|
|
14
|
+
head :created, location: sufia.api_item_path(actor.create_file_from_item)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def update
|
|
18
|
+
actor.update_file_from_item(@file)
|
|
19
|
+
head :no_content
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def destroy
|
|
23
|
+
actor.destroy_file(@file)
|
|
24
|
+
head :no_content
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def show
|
|
28
|
+
head :no_content
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
private
|
|
32
|
+
|
|
33
|
+
def my_load_and_authorize_resource
|
|
34
|
+
@file = GenericFile.find(params[:id])
|
|
35
|
+
|
|
36
|
+
unless user.can? :edit, @file
|
|
37
|
+
return render plain: "#{user} lacks access to #{@file}", status: :unauthorized
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
if @file.arkivo_checksum.nil?
|
|
41
|
+
return render plain: "Forbidden: #{@file} not deposited via Arkivo", status: :forbidden
|
|
42
|
+
end
|
|
43
|
+
rescue ActiveFedora::ObjectNotFoundError
|
|
44
|
+
return render plain: "id '#{params[:id]}' not found", status: :not_found
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def actor
|
|
48
|
+
Sufia::Arkivo::Actor.new(user, item)
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def token
|
|
52
|
+
(request.get? || request.delete?) ? params[:token] : item['token']
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def user
|
|
56
|
+
User.find_by(arkivo_token: token)
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def validate_item
|
|
60
|
+
return render plain: 'no item parameter', status: :bad_request if params[:item].blank?
|
|
61
|
+
Sufia::Arkivo::SchemaValidator.new(params[:item]).call
|
|
62
|
+
rescue Sufia::Arkivo::InvalidItem => exception
|
|
63
|
+
return render plain: "invalid item parameter: #{exception.message}", status: :bad_request
|
|
64
|
+
else
|
|
65
|
+
@item = JSON.parse(params[:item])
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def authorize_token
|
|
69
|
+
unless valid_token?
|
|
70
|
+
return render plain: "invalid user token: #{token}", status: :unauthorized
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
def valid_token?
|
|
75
|
+
user.present?
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
end
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
require 'oauth'
|
|
2
|
+
|
|
3
|
+
module API
|
|
4
|
+
# Adds the ability to authenticate against Zotero's OAuth endpoint
|
|
5
|
+
class ZoteroController < ApplicationController
|
|
6
|
+
before_filter :authenticate_user!
|
|
7
|
+
before_filter :authorize_user!
|
|
8
|
+
before_filter :validate_params, only: :callback
|
|
9
|
+
|
|
10
|
+
def initiate
|
|
11
|
+
request_token = client.get_request_token(oauth_callback: callback_url)
|
|
12
|
+
session[:request_token] = request_token
|
|
13
|
+
current_user.zotero_token = request_token
|
|
14
|
+
current_user.save
|
|
15
|
+
redirect_to request_token.authorize_url({ identity: '1', oauth_callback: callback_url })
|
|
16
|
+
rescue OAuth::Unauthorized
|
|
17
|
+
redirect_to root_url, alert: 'Invalid Zotero client key pair'
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def callback
|
|
21
|
+
access_token = current_token.get_access_token({ oauth_verifier: params['oauth_verifier'] })
|
|
22
|
+
# parse userID and API key out of token and store in user instance
|
|
23
|
+
current_user.zotero_userid = access_token.params[:userID]
|
|
24
|
+
current_user.save
|
|
25
|
+
Sufia.queue.push(Sufia::Arkivo::CreateSubscriptionJob.new(current_user.user_key))
|
|
26
|
+
redirect_to sufia.profile_path(current_user), notice: 'Successfully connected to Zotero!'
|
|
27
|
+
rescue OAuth::Unauthorized
|
|
28
|
+
redirect_to sufia.edit_profile_path(current_user.to_param), alert: 'Please re-authenticate with Zotero'
|
|
29
|
+
ensure
|
|
30
|
+
current_user.zotero_token = nil
|
|
31
|
+
current_user.save
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
private
|
|
35
|
+
|
|
36
|
+
def authorize_user!
|
|
37
|
+
authorize! :create, ::GenericFile
|
|
38
|
+
rescue CanCan::AccessDenied
|
|
39
|
+
return redirect_to root_url, alert: 'You are not authorized to perform this operation'
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def validate_params
|
|
43
|
+
return redirect_to sufia.edit_profile_path(current_user.to_param), alert: "Malformed request from Zotero" if params[:oauth_token].blank? || params[:oauth_verifier].blank?
|
|
44
|
+
return redirect_to sufia.edit_profile_path(current_user.to_param), alert: "You have not yet connected to Zotero" if !current_token || current_token.params[:oauth_token] != params[:oauth_token]
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def client
|
|
48
|
+
::OAuth::Consumer.new(Sufia::Zotero.config['client_key'], Sufia::Zotero.config['client_secret'], options)
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def current_token
|
|
52
|
+
current_user.zotero_token
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def callback_url
|
|
56
|
+
"#{request.base_url}/api/zotero/callback"
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def options
|
|
60
|
+
{
|
|
61
|
+
site: 'https://www.zotero.org',
|
|
62
|
+
scheme: :query_string,
|
|
63
|
+
http_method: :get,
|
|
64
|
+
request_token_path: '/oauth/request',
|
|
65
|
+
access_token_path: '/oauth/access',
|
|
66
|
+
authorize_path: '/oauth/authorize'
|
|
67
|
+
}
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
end
|
|
@@ -4,11 +4,12 @@ require 'cgi'
|
|
|
4
4
|
class AuthoritiesController < ApplicationController
|
|
5
5
|
def query
|
|
6
6
|
s = params.fetch("q", "")
|
|
7
|
-
hits =
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
7
|
+
hits =
|
|
8
|
+
if params[:term] == "location"
|
|
9
|
+
GeoNamesResource.find_location(s)
|
|
10
|
+
else
|
|
11
|
+
LocalAuthority.entries_by_term(params[:model], params[:term], s) rescue []
|
|
12
|
+
end
|
|
12
13
|
render json: hits
|
|
13
14
|
end
|
|
14
15
|
end
|
|
@@ -84,7 +84,8 @@ module Sufia
|
|
|
84
84
|
end
|
|
85
85
|
|
|
86
86
|
def generic_file_params
|
|
87
|
-
|
|
87
|
+
file_params = params[:generic_file] || ActionController::Parameters.new()
|
|
88
|
+
Forms::BatchEditForm.model_attributes(file_params)
|
|
88
89
|
end
|
|
89
90
|
|
|
90
91
|
def redirect_to_return_controller
|
|
@@ -7,6 +7,17 @@ module Sufia
|
|
|
7
7
|
before_filter :validate_users, only: :create
|
|
8
8
|
end
|
|
9
9
|
|
|
10
|
+
|
|
11
|
+
# Overriding the default behavior from Hydra::Core::ContorllerBehavior
|
|
12
|
+
def deny_access(exception)
|
|
13
|
+
if current_user and current_user.persisted?
|
|
14
|
+
redirect_to root_path, alert: exception.message
|
|
15
|
+
else
|
|
16
|
+
session['user_return_to'.freeze] = request.url
|
|
17
|
+
redirect_to new_user_session_path, alert: exception.message
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
|
|
10
21
|
def create
|
|
11
22
|
grantor = authorize_and_return_grantor
|
|
12
23
|
grantee = ::User.from_url_component(params[:grantee_id])
|
|
@@ -24,7 +24,7 @@ module Sufia::FilesController
|
|
|
24
24
|
# Generic utility for creating GenericFile from a URL
|
|
25
25
|
# Used in to import files using URLs from a file picker like browse_everything
|
|
26
26
|
def create_file_from_url(url, file_name)
|
|
27
|
-
|
|
27
|
+
::GenericFile.new(import_url: url, label: file_name) do |gf|
|
|
28
28
|
actor = Sufia::GenericFile::Actor.new(gf, current_user)
|
|
29
29
|
actor.create_metadata(params[:batch_id])
|
|
30
30
|
gf.save!
|
|
@@ -54,7 +54,7 @@ module Sufia
|
|
|
54
54
|
def ingest_one(filename, unarranged)
|
|
55
55
|
basename = File.basename(filename)
|
|
56
56
|
# do not remove ::
|
|
57
|
-
|
|
57
|
+
::GenericFile.new(label: basename) do |gf|
|
|
58
58
|
gf.relative_path = filename if filename != basename
|
|
59
59
|
actor = Sufia::GenericFile::Actor.new(gf, current_user)
|
|
60
60
|
actor.create_metadata(params[:batch_id])
|
|
@@ -39,16 +39,27 @@ module Sufia
|
|
|
39
39
|
before_filter :has_access?, except: [:show]
|
|
40
40
|
before_filter :build_breadcrumbs, only: [:show, :edit, :stats]
|
|
41
41
|
load_resource only: [:audit]
|
|
42
|
-
load_and_authorize_resource except: [:index, :audit]
|
|
42
|
+
load_and_authorize_resource except: [:index, :audit, :show]
|
|
43
|
+
|
|
44
|
+
# since we are only displaying data we are makingthe show action fast by loading the information from solr
|
|
45
|
+
# these two steps replace load_and_authorize_resource for the show action
|
|
46
|
+
before_filter :load_resource_from_solr, only: [:show]
|
|
47
|
+
authorize_resource only: [:show]
|
|
43
48
|
|
|
44
49
|
class_attribute :edit_form_class, :presenter_class
|
|
45
50
|
self.edit_form_class = Sufia::Forms::GenericFileEditForm
|
|
46
51
|
self.presenter_class = Sufia::GenericFilePresenter
|
|
47
52
|
end
|
|
48
53
|
|
|
54
|
+
# Load the GenericFile from solr instead of fedora
|
|
55
|
+
# this replaces the load_resource from CanCan that is usually called by load_and_authorize_resource
|
|
56
|
+
def load_resource_from_solr
|
|
57
|
+
@generic_file = ::GenericFile.load_instance_from_solr(params[:id])
|
|
58
|
+
end
|
|
59
|
+
|
|
49
60
|
# routed to /files/new
|
|
50
61
|
def new
|
|
51
|
-
@batch_id =
|
|
62
|
+
@batch_id = ActiveFedora::Noid::Service.new.mint
|
|
52
63
|
end
|
|
53
64
|
|
|
54
65
|
# routed to /files/:id/edit
|
|
@@ -118,15 +129,16 @@ module Sufia
|
|
|
118
129
|
|
|
119
130
|
# routed to /files/:id (PUT)
|
|
120
131
|
def update
|
|
121
|
-
success =
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
132
|
+
success =
|
|
133
|
+
if wants_to_revert?
|
|
134
|
+
update_version
|
|
135
|
+
elsif wants_to_upload_new_version?
|
|
136
|
+
update_file
|
|
137
|
+
elsif params.has_key? :generic_file
|
|
138
|
+
update_metadata
|
|
139
|
+
elsif params.has_key? :visibility
|
|
140
|
+
update_visibility
|
|
141
|
+
end
|
|
130
142
|
|
|
131
143
|
if success
|
|
132
144
|
redirect_to sufia.edit_generic_file_path(tab: params[:redirect_tab]), notice:
|
|
@@ -11,6 +11,7 @@ module Sufia
|
|
|
11
11
|
include Blacklight::Configurable
|
|
12
12
|
|
|
13
13
|
self.copy_blacklight_config_from(CatalogController)
|
|
14
|
+
self.blacklight_config.search_builder_class = Sufia::MySearchBuilder
|
|
14
15
|
|
|
15
16
|
before_filter :authenticate_user!
|
|
16
17
|
before_filter :enforce_show_permissions, only: :show
|
|
@@ -54,12 +55,5 @@ module Sufia
|
|
|
54
55
|
end
|
|
55
56
|
end
|
|
56
57
|
|
|
57
|
-
protected
|
|
58
|
-
|
|
59
|
-
# show only files with edit permissions in lib/hydra/access_controls_enforcement.rb apply_gated_discovery
|
|
60
|
-
def discovery_permissions
|
|
61
|
-
["edit"]
|
|
62
|
-
end
|
|
63
|
-
|
|
64
58
|
end
|
|
65
59
|
end
|
|
@@ -58,7 +58,7 @@ module Sufia::UsersControllerBehavior
|
|
|
58
58
|
end
|
|
59
59
|
# TODO this should be moved to TrophiesController
|
|
60
60
|
params.keys.select {|k, v| k.starts_with? 'remove_trophy_' }.each do |smash_trophy|
|
|
61
|
-
smash_trophy = smash_trophy.sub
|
|
61
|
+
smash_trophy = smash_trophy.sub(/^remove_trophy_/, '')
|
|
62
62
|
current_user.trophies.where(generic_file_id: smash_trophy).destroy_all
|
|
63
63
|
end
|
|
64
64
|
Sufia.queue.push(UserEditProfileEventJob.new(@user.user_key))
|
|
@@ -114,7 +114,6 @@ module Sufia::UsersControllerBehavior
|
|
|
114
114
|
:twitter_handle, :googleplus_handle, :linkedin_handle, :remove_avatar, :orcid)
|
|
115
115
|
end
|
|
116
116
|
|
|
117
|
-
|
|
118
117
|
# You can override base_query to return a list of arguments
|
|
119
118
|
def base_query
|
|
120
119
|
[nil]
|
|
@@ -4,15 +4,24 @@ module Sufia
|
|
|
4
4
|
"#{image_tag 'orcid.png', { alt: t('sufia.user_profile.orcid.alt'), class: style_class }} #{t('sufia.user_profile.orcid.label')}".html_safe
|
|
5
5
|
end
|
|
6
6
|
|
|
7
|
+
def zotero_label(opts={})
|
|
8
|
+
html_class = opts[:html_class] || ''
|
|
9
|
+
"#{image_tag 'zotero.png', { alt: t('sufia.user_profile.zotero.alt'), class: html_class }} #{t('sufia.user_profile.zotero.label')}".html_safe
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def zotero_profile_url(zotero_user_id)
|
|
13
|
+
"https://www.zotero.org/users/#{zotero_user_id}"
|
|
14
|
+
end
|
|
15
|
+
|
|
7
16
|
def error_messages_for(object)
|
|
8
17
|
if object.try(:errors) and object.errors.full_messages.any?
|
|
9
18
|
content_tag(:div, class: 'alert alert-block alert-error validation-errors') do
|
|
10
19
|
content_tag(:h4, I18n.t('sufia.errors.header', model: object.class.model_name.human.downcase), class: 'alert-heading') +
|
|
11
20
|
content_tag(:ul) do
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
21
|
+
object.errors.full_messages.map do |message|
|
|
22
|
+
content_tag(:li, message)
|
|
23
|
+
end.join('').html_safe
|
|
24
|
+
end
|
|
16
25
|
end
|
|
17
26
|
else
|
|
18
27
|
'' # return empty string
|
|
@@ -37,13 +46,15 @@ module Sufia
|
|
|
37
46
|
|
|
38
47
|
# file
|
|
39
48
|
else
|
|
40
|
-
path =
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
49
|
+
path =
|
|
50
|
+
if document.image? || document.pdf? || document.video? || document.office_document?
|
|
51
|
+
sufia.download_path document, file: 'thumbnail'
|
|
52
|
+
elsif document.audio?
|
|
53
|
+
"audio.png"
|
|
54
|
+
else
|
|
55
|
+
"default.png"
|
|
56
|
+
end
|
|
57
|
+
options[:alt] = " "
|
|
47
58
|
image_tag path, options
|
|
48
59
|
end
|
|
49
60
|
end
|
|
@@ -110,11 +121,12 @@ module Sufia
|
|
|
110
121
|
user = ::User.find_by_user_key(login)
|
|
111
122
|
return login if user.nil?
|
|
112
123
|
|
|
113
|
-
text =
|
|
114
|
-
user.name
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
124
|
+
text =
|
|
125
|
+
if user.respond_to? :name
|
|
126
|
+
user.name
|
|
127
|
+
else
|
|
128
|
+
login
|
|
129
|
+
end
|
|
118
130
|
|
|
119
131
|
link_to text, Sufia::Engine.routes.url_helpers.profile_path(user)
|
|
120
132
|
end
|