sufia 6.2.0 → 6.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +146 -0
- data/.travis.yml +4 -7
- data/Gemfile +2 -0
- data/History.md +29 -1
- data/README.md +25 -9
- data/SUFIA_VERSION +1 -1
- data/app/assets/stylesheets/sufia/_collections.scss +15 -0
- data/app/assets/stylesheets/sufia/_file-listing.scss +7 -0
- data/app/assets/stylesheets/sufia/_home-page.scss +10 -0
- data/app/builders/sufia/bootstrap_breadcrumbs_builder.rb +3 -5
- data/app/controllers/admin/stats_controller.rb +1 -76
- data/app/controllers/api/items_controller.rb +4 -6
- data/app/controllers/api/zotero_controller.rb +5 -5
- data/app/controllers/authorities_controller.rb +5 -1
- data/app/controllers/batch_edits_controller.rb +3 -3
- data/app/controllers/concerns/sufia/admin/depositor_stats.rb +41 -0
- data/app/controllers/concerns/sufia/admin/stats_behavior.rb +94 -0
- data/app/controllers/concerns/sufia/batch_controller_behavior.rb +16 -18
- data/app/controllers/concerns/sufia/batch_edits_controller_behavior.rb +54 -56
- data/app/controllers/concerns/sufia/breadcrumbs.rb +3 -6
- data/app/controllers/concerns/sufia/collections_controller_behavior.rb +39 -39
- data/app/controllers/concerns/sufia/controller.rb +10 -10
- data/app/controllers/concerns/sufia/dashboard_controller_behavior.rb +17 -18
- data/app/controllers/concerns/sufia/depositors_controller_behavior.rb +9 -12
- data/app/controllers/concerns/sufia/files_controller/browse_everything.rb +6 -7
- data/app/controllers/concerns/sufia/files_controller/local_ingest_behavior.rb +39 -40
- data/app/controllers/concerns/sufia/files_controller/upload_complete_behavior.rb +1 -1
- data/app/controllers/concerns/sufia/files_controller_behavior.rb +109 -110
- data/app/controllers/concerns/sufia/homepage_controller.rb +8 -8
- data/app/controllers/concerns/sufia/my_controller_behavior.rb +13 -10
- data/app/controllers/concerns/sufia/single_use_links_controller_behavior.rb +11 -14
- data/app/controllers/concerns/sufia/single_use_links_viewer_controller_behavior.rb +27 -21
- data/app/controllers/concerns/sufia/transfers_controller_behavior.rb +17 -17
- data/app/controllers/concerns/sufia/users_controller_behavior.rb +54 -54
- data/app/controllers/contact_form_controller.rb +1 -1
- data/app/controllers/content_blocks_controller.rb +11 -12
- data/app/controllers/directory_controller.rb +2 -3
- data/app/controllers/featured_work_lists_controller.rb +1 -1
- data/app/controllers/featured_works_controller.rb +2 -4
- data/app/controllers/homepage_controller.rb +1 -2
- data/app/controllers/mailbox_controller.rb +12 -32
- data/app/controllers/my/collections_controller.rb +3 -4
- data/app/controllers/my/files_controller.rb +4 -6
- data/app/controllers/my/highlights_controller.rb +4 -6
- data/app/controllers/my/shares_controller.rb +3 -5
- data/app/controllers/pages_controller.rb +1 -3
- data/app/controllers/single_use_links_controller.rb +0 -1
- data/app/controllers/single_use_links_viewer_controller.rb +0 -1
- data/app/controllers/static_controller.rb +1 -0
- data/app/forms/sufia/forms/collection_edit_form.rb +2 -2
- data/app/helpers/batch_edits_helper.rb +1 -3
- data/app/helpers/content_block_helper.rb +7 -8
- data/app/helpers/generic_file_helper.rb +23 -24
- data/app/helpers/sufia/blacklight_override.rb +6 -7
- data/app/helpers/sufia/dashboard_helper_behavior.rb +4 -7
- data/app/helpers/sufia/permissions_helper.rb +3 -4
- data/app/helpers/sufia/sufia_helper_behavior.rb +30 -29
- data/app/helpers/trophy_helper.rb +15 -15
- data/app/inputs/select_with_modal_help_input.rb +3 -3
- data/app/inputs/with_help_icon.rb +4 -4
- data/app/jobs/content_delete_event_job.rb +0 -1
- data/app/jobs/content_depositor_change_event_job.rb +1 -2
- data/app/jobs/event_job.rb +0 -1
- data/app/jobs/user_unfollow_event_job.rb +1 -0
- data/app/models/concerns/sufia/solr_document_behavior.rb +1 -2
- data/app/models/contact_form.rb +6 -6
- data/app/models/content_block.rb +1 -2
- data/app/models/featured_work_list.rb +3 -5
- data/app/models/user_mailbox.rb +44 -0
- data/app/presenters/sufia/collection_presenter.rb +6 -8
- data/app/presenters/sufia/generic_file_presenter.rb +2 -2
- data/app/presenters/sufia/presenter_renderer.rb +2 -2
- data/app/presenters/sufia/version_list_presenter.rb +1 -1
- data/app/presenters/sufia/version_presenter.rb +3 -6
- data/app/search_builders/deposit_search_builder.rb +19 -0
- data/app/search_builders/sufia/my_search_builder_behavior.rb +1 -2
- data/app/search_builders/sufia/search_builder.rb +1 -3
- data/app/uploaders/tinymce_asset_uploader.rb +0 -2
- data/app/views/_controls.html.erb +5 -5
- data/app/views/admin/stats/_deposits.html.erb +19 -0
- data/app/views/admin/stats/index.html.erb +2 -0
- data/app/views/batch_edits/edit.html.erb +2 -2
- data/app/views/collections/_edit_actions.html.erb +3 -3
- data/app/views/collections/_form_for_select_collection.html.erb +2 -2
- data/app/views/collections/_sort_and_per_page.html.erb +12 -9
- data/app/views/collections/_view_type_group.html.erb +1 -1
- data/app/views/collections/edit.html.erb +5 -5
- data/app/views/collections/show.html.erb +7 -6
- data/app/views/homepage/_announcement.html.erb +5 -0
- data/app/views/homepage/_home.html.erb +1 -0
- data/app/views/my/_sort_and_per_page.html.erb +14 -10
- data/app/views/my/index.html.erb +1 -1
- data/app/views/pages/show.html.erb +0 -2
- data/app/views/single_use_links/new_download.html.erb +1 -1
- data/app/views/single_use_links_viewer/show.html.erb +1 -1
- data/app/views/users/_notify_link.html.erb +1 -1
- data/app/views/users/_notify_number.html.erb +2 -2
- data/config/initializers/simple_form.rb +1 -1
- data/config/initializers/simple_form_bootstrap.rb +1 -1
- data/config/locales/sufia.en.yml +4 -0
- data/config/routes.rb +2 -3
- data/lib/generators/sufia/admin_stat_generator.rb +0 -3
- data/lib/generators/sufia/install_generator.rb +8 -9
- data/lib/generators/sufia/templates/catalog_controller.rb +2 -3
- data/lib/generators/sufia/templates/config/action_dispatch_http_upload_monkey_patch.rb +1 -0
- data/lib/generators/sufia/upgrade400_generator.rb +9 -9
- data/lib/generators/sufia/upgrade600_generator.rb +1 -4
- data/lib/sufia.rb +2 -2
- data/lib/sufia/arkivo/actor.rb +1 -1
- data/lib/sufia/arkivo/create_subscription_job.rb +30 -30
- data/lib/sufia/arkivo/metadata_munger.rb +7 -7
- data/lib/sufia/arkivo/schema_validator.rb +1 -1
- data/lib/sufia/single_use_error.rb +0 -1
- data/lib/sufia/version.rb +1 -1
- data/lib/sufia/zotero/config.rb +13 -13
- data/spec/actors/generic_file/actor_spec.rb +17 -18
- data/spec/controllers/admin_stats_controller_spec.rb +56 -5
- data/spec/controllers/api/zotero_controller_spec.rb +10 -9
- data/spec/controllers/authorities_controller_spec.rb +8 -8
- data/spec/controllers/batch_controller_spec.rb +19 -20
- data/spec/controllers/batch_edits_controller_spec.rb +8 -9
- data/spec/controllers/catalog_controller_spec.rb +7 -9
- data/spec/controllers/collections_controller_spec.rb +30 -32
- data/spec/controllers/content_blocks_controller_spec.rb +4 -4
- data/spec/controllers/dashboard_controller_spec.rb +12 -12
- data/spec/controllers/depositors_controller_spec.rb +8 -8
- data/spec/controllers/downloads_controller_spec.rb +10 -11
- data/spec/controllers/featured_work_lists_controller_spec.rb +4 -4
- data/spec/controllers/featured_works_controller_spec.rb +11 -12
- data/spec/controllers/generic_files_controller_spec.rb +154 -125
- data/spec/controllers/homepage_controller_spec.rb +22 -15
- data/spec/controllers/mailbox_controller_spec.rb +20 -36
- data/spec/controllers/my/collections_controller_spec.rb +4 -5
- data/spec/controllers/my/files_controller_spec.rb +10 -11
- data/spec/controllers/my/highlights_controller_spec.rb +4 -5
- data/spec/controllers/my/shares_controller_spec.rb +12 -14
- data/spec/controllers/my_controller_spec.rb +1 -3
- data/spec/controllers/pages_controller_spec.rb +4 -4
- data/spec/controllers/single_use_links_controller_spec.rb +1 -3
- data/spec/controllers/single_use_links_viewer_controller_spec.rb +1 -2
- data/spec/controllers/static_controller_spec.rb +1 -1
- data/spec/controllers/tinymce_assets_controller_spec.rb +8 -9
- data/spec/controllers/transfers_controller_spec.rb +19 -19
- data/spec/controllers/users_controller_spec.rb +33 -35
- data/spec/factories/api_items.rb +2 -2
- data/spec/factories/content_blocks.rb +1 -1
- data/spec/factories/featured_works.rb +1 -1
- data/spec/factories/generic_files.rb +3 -3
- data/spec/factories/users.rb +7 -8
- data/spec/features/browse_dashboard_files_spec.rb +14 -18
- data/spec/features/browse_files_spec.rb +3 -4
- data/spec/features/catalog_search_spec.rb +3 -5
- data/spec/features/cloud_upload_spec.rb +2 -2
- data/spec/features/collection_spec.rb +21 -21
- data/spec/features/contact_form_spec.rb +10 -11
- data/spec/features/display_dashboard_spec.rb +5 -9
- data/spec/features/edit_file_spec.rb +8 -9
- data/spec/features/featured_item_spec.rb +1 -1
- data/spec/features/ingest_upload_files_spec.rb +5 -5
- data/spec/features/notifications_spec.rb +2 -6
- data/spec/features/ownership_transfer_spec.rb +2 -2
- data/spec/features/proxy_spec.rb +2 -2
- data/spec/features/search_spec.rb +3 -4
- data/spec/features/single_use_links_spec.rb +1 -1
- data/spec/features/users_spec.rb +4 -5
- data/spec/forms/collection_edit_form_spec.rb +2 -2
- data/spec/forms/generic_file_edit_form_spec.rb +6 -7
- data/spec/helpers/batch_edits_helper_spec.rb +9 -13
- data/spec/helpers/content_block_helper_spec.rb +3 -3
- data/spec/helpers/dashboard_helper_spec.rb +19 -24
- data/spec/helpers/generic_file_helper_spec.rb +5 -7
- data/spec/helpers/sufia_helper_spec.rb +43 -54
- data/spec/helpers/trophy_helper_spec.rb +5 -5
- data/spec/inputs/multi_value_with_help_input_spec.rb +1 -2
- data/spec/inputs/select_with_help_input_spec.rb +19 -15
- data/spec/javascripts/jasmine_spec.rb +4 -5
- data/spec/javascripts/support/jasmine_helper.rb +9 -9
- data/spec/jobs/active_fedora_id_based_job_spec.rb +7 -5
- data/spec/jobs/audit_job_spec.rb +7 -7
- data/spec/jobs/batch_update_job_spec.rb +5 -6
- data/spec/jobs/characterize_job_spec.rb +1 -1
- data/spec/jobs/content_depositor_change_event_job_spec.rb +1 -1
- data/spec/jobs/create_derivatives_job_spec.rb +5 -5
- data/spec/jobs/event_jobs_spec.rb +16 -16
- data/spec/jobs/import_url_job_spec.rb +36 -5
- data/spec/jobs/ingest_local_file_job_spec.rb +31 -20
- data/spec/jobs/sufia_resque_queue_spec.rb +1 -1
- data/spec/lib/sufia/analytics_spec.rb +0 -1
- data/spec/lib/sufia/arkivo/actor_spec.rb +6 -6
- data/spec/lib/sufia/arkivo/schema_validator_spec.rb +18 -18
- data/spec/lib/sufia/breadcrumbs_spec.rb +5 -6
- data/spec/lib/sufia/messages_spec.rb +11 -12
- data/spec/lib/sufia/readable_permissions_spec.rb +8 -10
- data/spec/lib/sufia/upload_complete_behavior_spec.rb +6 -7
- data/spec/lib/sufia/user_stat_importer_spec.rb +30 -33
- data/spec/lib/sufia/writable_permissions_spec.rb +1 -3
- data/spec/lib/sufia/zotero/config_spec.rb +4 -6
- data/spec/models/ability_spec.rb +11 -9
- data/spec/models/batch_spec.rb +13 -13
- data/spec/models/characterization_spec.rb +2 -3
- data/spec/models/checksum_audit_log_spec.rb +18 -19
- data/spec/models/collection_spec.rb +11 -12
- data/spec/models/content_block_spec.rb +33 -22
- data/spec/models/download_spec.rb +3 -5
- data/spec/models/featured_work_list_spec.rb +3 -3
- data/spec/models/featured_work_spec.rb +12 -14
- data/spec/models/file_content_datastream_spec.rb +9 -7
- data/spec/models/file_download_stat_spec.rb +34 -40
- data/spec/models/file_usage_spec.rb +46 -52
- data/spec/models/file_view_stat_spec.rb +35 -41
- data/spec/models/fits_datastream_spec.rb +23 -25
- data/spec/models/generic_file/visibility_spec.rb +10 -5
- data/spec/models/generic_file_spec.rb +86 -88
- data/spec/models/geo_names_resource_spec.rb +3 -5
- data/spec/models/local_authority_spec.rb +30 -33
- data/spec/models/pageview_spec.rb +3 -3
- data/spec/models/proxy_deposit_request_spec.rb +3 -3
- data/spec/models/single_use_link_spec.rb +36 -36
- data/spec/models/solr_document_spec.rb +3 -6
- data/spec/models/trophy_spec.rb +8 -9
- data/spec/models/user_mailbox_spec.rb +62 -0
- data/spec/models/user_spec.rb +28 -29
- data/spec/presenters/presenter_renderer_spec.rb +1 -1
- data/spec/presenters/sufia/generic_file_presenter_spec.rb +5 -5
- data/spec/presenters/sufia/version_list_presenter_spec.rb +2 -2
- data/spec/presenters/sufia/version_presenter_spec.rb +1 -1
- data/spec/routing/featured_works_route_spec.rb +4 -4
- data/spec/routing/ownership_transfers_route_spec.rb +1 -1
- data/spec/routing/route_spec.rb +89 -89
- data/spec/services/generic_file_audit_service_spec.rb +8 -8
- data/spec/services/repository_audit_service_spec.rb +7 -3
- data/spec/spec_helper.rb +5 -4
- data/spec/support/features/session_helpers.rb +1 -1
- data/spec/support/input_support.rb +1 -2
- data/spec/support/rake.rb +1 -1
- data/spec/support/selectors.rb +1 -6
- data/spec/support/statistic_helper.rb +1 -1
- data/spec/support/uploaded_file_monkeypatch.rb +1 -1
- data/spec/tasks/rake_spec.rb +3 -5
- data/spec/views/admin/stats/index.html.erb_spec.rb +16 -16
- data/spec/views/batch/edit.html.erb_spec.rb +1 -3
- data/spec/views/batch_edits/check_all_spec.rb +5 -5
- data/spec/views/batch_edits/edit.html.erb_spec.rb +1 -3
- data/spec/views/catalog/index.html.erb_spec.rb +1 -3
- data/spec/views/catalog/sort_and_per_page.html.erb_spec.rb +4 -5
- data/spec/views/collections/_form.html.erb_spec.rb +5 -3
- data/spec/views/collections/_show_descriptions.html.erb_spec.rb +7 -8
- data/spec/views/collections/_show_document_list.erb_spec.rb +4 -6
- data/spec/views/dashboard/index_spec.rb +14 -21
- data/spec/views/generic_file/_browse_everything.html.erb_spec.rb +2 -2
- data/spec/views/generic_file/_permission_form.html.erb_spec.rb +8 -9
- data/spec/views/generic_file/edit.html.erb_spec.rb +7 -7
- data/spec/views/generic_file/show.html.erb_spec.rb +24 -25
- data/spec/views/generic_file/stats.html.erb_spec.rb +19 -19
- data/spec/views/homepage/_announcement.html.erb_spec.rb +51 -0
- data/spec/views/homepage/_featured_works.html.erb_spec.rb +5 -9
- data/spec/views/homepage/_home_header.html.erb_spec.rb +2 -2
- data/spec/views/my/facet.html.erb_spec.rb +4 -4
- data/spec/views/single_use_links/new_download.html.erb_spec.rb +28 -0
- data/spec/views/single_use_links_viewer/show.html.erb_spec.rb +29 -0
- data/spec/views/users/_follower_modal.html.erb_spec.rb +7 -8
- data/spec/views/users/_following_modal.html.erb_spec.rb +4 -5
- data/spec/views/users/_notify_number.html.erb_spec.rb +2 -5
- data/spec/views/users/_user_util_links.html.erb_spec.rb +5 -8
- data/spec/views/users/index.html.erb_spec.rb +4 -6
- data/spec/views/users/show.html.erb_spec.rb +4 -7
- data/tasks/sufia-dev.rake +19 -3
- metadata +20 -5
@@ -5,7 +5,7 @@ module Sufia::Controller
|
|
5
5
|
# Adds Hydra behaviors into the application controller
|
6
6
|
include Hydra::Controller::ControllerBehavior
|
7
7
|
|
8
|
-
|
8
|
+
before_action :notifications_number
|
9
9
|
end
|
10
10
|
|
11
11
|
def current_ability
|
@@ -28,24 +28,24 @@ module Sufia::Controller
|
|
28
28
|
end
|
29
29
|
|
30
30
|
def notifications_number
|
31
|
+
# These instance variables must appear above the return statements
|
31
32
|
@notify_number = 0
|
32
33
|
@batches = []
|
33
34
|
return if action_name == "index" && controller_name == "mailbox"
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
end
|
35
|
+
return unless user_signed_in?
|
36
|
+
@notify_number = current_user.mailbox.inbox(unread: true).count
|
37
|
+
@batches = current_user.mailbox.inbox.map { |msg| msg.last_message.body[/<span id="(.*)"><a (href=|data-content=|rel=)(.*)/, 1] }.select { |val| !val.blank? }
|
38
38
|
end
|
39
39
|
|
40
40
|
# Override Devise method to redirect to dashboard after signing in
|
41
|
-
def after_sign_in_path_for(
|
41
|
+
def after_sign_in_path_for(_resource)
|
42
42
|
sufia.dashboard_index_path
|
43
43
|
end
|
44
44
|
|
45
45
|
protected
|
46
46
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
47
|
+
### Hook which is overridden in Sufia::Ldap::Controller
|
48
|
+
def has_access?
|
49
|
+
true
|
50
|
+
end
|
51
51
|
end
|
@@ -5,7 +5,7 @@ module Sufia
|
|
5
5
|
included do
|
6
6
|
include ActionView::Helpers::DateHelper
|
7
7
|
|
8
|
-
|
8
|
+
before_action :authenticate_user!
|
9
9
|
|
10
10
|
layout "sufia-dashboard"
|
11
11
|
end
|
@@ -14,7 +14,7 @@ module Sufia
|
|
14
14
|
def index
|
15
15
|
gather_dashboard_information
|
16
16
|
respond_to do |format|
|
17
|
-
format.html {
|
17
|
+
format.html {}
|
18
18
|
format.rss { render layout: false }
|
19
19
|
format.atom { render layout: false }
|
20
20
|
end
|
@@ -27,23 +27,22 @@ module Sufia
|
|
27
27
|
|
28
28
|
protected
|
29
29
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
end
|
40
|
-
|
41
|
-
# Formats the user's activities into human-readable strings used for rendering JSON
|
42
|
-
def human_readable_user_activity
|
43
|
-
current_user.get_all_user_activity.map do |event|
|
44
|
-
[event[:action], "#{time_ago_in_words(Time.at(event[:timestamp].to_i))} ago", event[:timestamp].to_i]
|
30
|
+
# Gathers all the information that we'll display in the user's dashboard.
|
31
|
+
# Override this method if you want to exclude or gather additional data elements
|
32
|
+
# in your dashboard view. You'll need to alter dashboard/index.html.erb accordingly.
|
33
|
+
def gather_dashboard_information
|
34
|
+
@user = current_user
|
35
|
+
@activity = current_user.all_user_activity(params[:since].blank? ? DateTime.now.to_i - Sufia.config.activity_to_show_default_seconds_since_now : params[:since].to_i)
|
36
|
+
@notifications = current_user.mailbox.inbox
|
37
|
+
@incoming = ProxyDepositRequest.where(receiving_user_id: current_user.id).reject(&:deleted_file?)
|
38
|
+
@outgoing = ProxyDepositRequest.where(sending_user_id: current_user.id)
|
45
39
|
end
|
46
|
-
end
|
47
40
|
|
41
|
+
# Formats the user's activities into human-readable strings used for rendering JSON
|
42
|
+
def human_readable_user_activity
|
43
|
+
current_user.all_user_activity.map do |event|
|
44
|
+
[event[:action], "#{time_ago_in_words(Time.at(event[:timestamp].to_i))} ago", event[:timestamp].to_i]
|
45
|
+
end
|
46
|
+
end
|
48
47
|
end
|
49
48
|
end
|
@@ -3,14 +3,13 @@ module Sufia
|
|
3
3
|
extend ActiveSupport::Concern
|
4
4
|
|
5
5
|
included do
|
6
|
-
|
7
|
-
|
6
|
+
before_action :authenticate_user!
|
7
|
+
before_action :validate_users, only: :create
|
8
8
|
end
|
9
9
|
|
10
|
-
|
11
10
|
# Overriding the default behavior from Hydra::Core::ContorllerBehavior
|
12
11
|
def deny_access(exception)
|
13
|
-
if current_user
|
12
|
+
if current_user && current_user.persisted?
|
14
13
|
redirect_to root_path, alert: exception.message
|
15
14
|
else
|
16
15
|
session['user_return_to'.freeze] = request.url
|
@@ -36,17 +35,15 @@ module Sufia
|
|
36
35
|
end
|
37
36
|
|
38
37
|
def validate_users
|
39
|
-
if params[:user_id] == params[:grantee_id]
|
40
|
-
head :ok
|
41
|
-
end
|
38
|
+
head :ok if params[:user_id] == params[:grantee_id]
|
42
39
|
end
|
43
40
|
|
44
41
|
private
|
45
42
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
43
|
+
def authorize_and_return_grantor
|
44
|
+
grantor = ::User.from_url_component(params[:user_id])
|
45
|
+
authorize! :edit, grantor
|
46
|
+
grantor
|
47
|
+
end
|
51
48
|
end
|
52
49
|
end
|
@@ -2,7 +2,7 @@ module Sufia::FilesController
|
|
2
2
|
module BrowseEverything
|
3
3
|
include ActiveSupport::Concern
|
4
4
|
|
5
|
-
def create
|
5
|
+
def create
|
6
6
|
if params[:selected_files].present?
|
7
7
|
create_from_browse_everything(params)
|
8
8
|
else
|
@@ -13,16 +13,16 @@ module Sufia::FilesController
|
|
13
13
|
protected
|
14
14
|
|
15
15
|
def create_from_browse_everything(params)
|
16
|
-
Batch.find_or_create(params[:batch_id])
|
17
|
-
params[:selected_files].each_pair do |
|
16
|
+
Batch.find_or_create(params[:batch_id])
|
17
|
+
params[:selected_files].each_pair do |_index, file_info|
|
18
18
|
next if file_info.blank? || file_info["url"].blank?
|
19
19
|
create_file_from_url(file_info["url"], file_info["file_name"])
|
20
20
|
end
|
21
|
-
redirect_to self.class.upload_complete_path(
|
21
|
+
redirect_to self.class.upload_complete_path(params[:batch_id])
|
22
22
|
end
|
23
|
-
|
23
|
+
|
24
24
|
# Generic utility for creating GenericFile from a URL
|
25
|
-
# Used in to import files using URLs from a file picker like browse_everything
|
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)
|
@@ -31,6 +31,5 @@ module Sufia::FilesController
|
|
31
31
|
Sufia.queue.push(ImportUrlJob.new(gf.id))
|
32
32
|
end
|
33
33
|
end
|
34
|
-
|
35
34
|
end
|
36
35
|
end
|
@@ -10,57 +10,56 @@ module Sufia
|
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
13
|
-
|
14
13
|
private
|
15
14
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
15
|
+
def perform_local_ingest
|
16
|
+
if Sufia.config.enable_local_ingest && current_user.respond_to?(:directory)
|
17
|
+
if ingest_local_file
|
18
|
+
redirect_to GenericFilesController.upload_complete_path(params[:batch_id])
|
19
|
+
else
|
20
|
+
flash[:alert] = "Error importing files from user directory."
|
21
|
+
render :new
|
22
|
+
end
|
20
23
|
else
|
21
|
-
flash[:alert] = "
|
24
|
+
flash[:alert] = "Your account is not configured for importing files from a user-directory on the server."
|
22
25
|
render :new
|
23
26
|
end
|
24
|
-
else
|
25
|
-
flash[:alert] = "Your account is not configured for importing files from a user-directory on the server."
|
26
|
-
render :new
|
27
27
|
end
|
28
|
-
end
|
29
28
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
29
|
+
def ingest_local_file
|
30
|
+
# Ingest files already on disk
|
31
|
+
has_directories = false
|
32
|
+
files = []
|
33
|
+
params[:local_file].each do |filename|
|
34
|
+
if File.directory?(File.join(current_user.directory, filename))
|
35
|
+
has_directories = true
|
36
|
+
Dir[File.join(current_user.directory, filename, '**', '*')].each do |single|
|
37
|
+
next if File.directory? single
|
38
|
+
logger.info("Ingesting file: #{single}")
|
39
|
+
files << single.sub(current_user.directory + '/', '')
|
40
|
+
logger.info("after removing the user directory #{current_user.directory} we have: #{files.last}")
|
41
|
+
end
|
42
|
+
else
|
43
|
+
files << filename
|
42
44
|
end
|
43
|
-
else
|
44
|
-
files << filename
|
45
45
|
end
|
46
|
+
Batch.find_or_create(params[:batch_id]) unless files.empty?
|
47
|
+
files.each do |filename|
|
48
|
+
ingest_one(filename, has_directories)
|
49
|
+
end
|
50
|
+
true
|
46
51
|
end
|
47
|
-
Batch.find_or_create(params[:batch_id]) unless files.empty?
|
48
|
-
files.each do |filename|
|
49
|
-
ingest_one(filename, has_directories)
|
50
|
-
end
|
51
|
-
true
|
52
|
-
end
|
53
52
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
53
|
+
def ingest_one(filename, _unarranged)
|
54
|
+
basename = File.basename(filename)
|
55
|
+
# do not remove ::
|
56
|
+
::GenericFile.new(label: basename) do |gf|
|
57
|
+
gf.relative_path = filename if filename != basename
|
58
|
+
actor = Sufia::GenericFile::Actor.new(gf, current_user)
|
59
|
+
actor.create_metadata(params[:batch_id])
|
60
|
+
gf.save!
|
61
|
+
Sufia.queue.push(IngestLocalFileJob.new(gf.id, current_user.directory, filename, current_user.user_key))
|
62
|
+
end
|
63
63
|
end
|
64
|
-
end
|
65
64
|
end # /FilesController::LocalIngestBehavior
|
66
65
|
end # /Sufia
|
@@ -19,13 +19,13 @@ module Sufia
|
|
19
19
|
|
20
20
|
layout "sufia-one-column"
|
21
21
|
|
22
|
-
|
22
|
+
copy_blacklight_config_from(CatalogController)
|
23
23
|
|
24
24
|
# Catch permission errors
|
25
25
|
rescue_from Hydra::AccessDenied, CanCan::AccessDenied do |exception|
|
26
26
|
if exception.action == :edit
|
27
|
-
redirect_to(sufia.url_for(
|
28
|
-
elsif current_user
|
27
|
+
redirect_to(sufia.url_for(action: 'show'), alert: "You do not have sufficient privileges to edit this document")
|
28
|
+
elsif current_user && current_user.persisted?
|
29
29
|
redirect_to root_url, alert: exception.message
|
30
30
|
else
|
31
31
|
session["user_return_to"] = request.url
|
@@ -35,15 +35,15 @@ module Sufia
|
|
35
35
|
|
36
36
|
# actions: audit, index, create, new, edit, show, update,
|
37
37
|
# destroy, permissions, citation, stats
|
38
|
-
|
39
|
-
|
40
|
-
|
38
|
+
before_action :authenticate_user!, except: [:show, :citation, :stats]
|
39
|
+
before_action :has_access?, except: [:show]
|
40
|
+
before_action :build_breadcrumbs, only: [:show, :edit, :stats]
|
41
41
|
load_resource only: [:audit]
|
42
42
|
load_and_authorize_resource except: [:index, :audit, :show]
|
43
43
|
|
44
44
|
# since we are only displaying data we are makingthe show action fast by loading the information from solr
|
45
45
|
# these two steps replace load_and_authorize_resource for the show action
|
46
|
-
|
46
|
+
before_action :load_resource_from_solr, only: [:show]
|
47
47
|
authorize_resource only: [:show]
|
48
48
|
|
49
49
|
class_attribute :edit_form_class, :presenter_class
|
@@ -86,20 +86,20 @@ module Sufia
|
|
86
86
|
|
87
87
|
def create_from_upload(params)
|
88
88
|
# check error condition No files
|
89
|
-
return json_error("Error! No file to save")
|
89
|
+
return json_error("Error! No file to save") unless params.key?(:files)
|
90
90
|
|
91
|
-
file = params[:files].detect {|f| f.respond_to?(:original_filename) }
|
91
|
+
file = params[:files].detect { |f| f.respond_to?(:original_filename) }
|
92
92
|
if !file
|
93
93
|
json_error "Error! No file for upload", 'unknown file', status: :unprocessable_entity
|
94
|
-
elsif
|
94
|
+
elsif empty_file?(file)
|
95
95
|
json_error "Error! Zero Length File!", file.original_filename
|
96
|
-
elsif
|
96
|
+
elsif !terms_accepted?
|
97
97
|
json_error "You must accept the terms of service!", file.original_filename
|
98
98
|
else
|
99
99
|
process_file(file)
|
100
100
|
end
|
101
101
|
rescue => error
|
102
|
-
logger.error "GenericFilesController::create rescued #{error.class}\n\t#{error
|
102
|
+
logger.error "GenericFilesController::create rescued #{error.class}\n\t#{error}\n #{error.backtrace.join("\n")}\n\n"
|
103
103
|
json_error "Error occurred while creating generic file."
|
104
104
|
ensure
|
105
105
|
# remove the tempfile (only if it is a temp file)
|
@@ -113,11 +113,11 @@ module Sufia
|
|
113
113
|
# routed to /files/:id
|
114
114
|
def show
|
115
115
|
respond_to do |format|
|
116
|
-
format.html
|
116
|
+
format.html do
|
117
117
|
@events = @generic_file.events(100)
|
118
118
|
@presenter = presenter
|
119
119
|
@audit_status = audit_service.human_readable_audit_status
|
120
|
-
|
120
|
+
end
|
121
121
|
format.endnote { render text: @generic_file.export_as_endnote }
|
122
122
|
end
|
123
123
|
end
|
@@ -134,9 +134,9 @@ module Sufia
|
|
134
134
|
update_version
|
135
135
|
elsif wants_to_upload_new_version?
|
136
136
|
update_file
|
137
|
-
elsif params.
|
137
|
+
elsif params.key? :generic_file
|
138
138
|
update_metadata
|
139
|
-
elsif params.
|
139
|
+
elsif params.key? :visibility
|
140
140
|
update_visibility
|
141
141
|
end
|
142
142
|
|
@@ -152,122 +152,121 @@ module Sufia
|
|
152
152
|
|
153
153
|
protected
|
154
154
|
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
def presenter
|
162
|
-
presenter_class.new(@generic_file)
|
163
|
-
end
|
164
|
-
|
165
|
-
def version_list
|
166
|
-
Sufia::VersionListPresenter.new(@generic_file.content.versions.all)
|
167
|
-
end
|
155
|
+
def set_variables_for_edit_form
|
156
|
+
@form = edit_form
|
157
|
+
@groups = current_user.groups
|
158
|
+
@version_list = version_list
|
159
|
+
end
|
168
160
|
|
169
|
-
|
170
|
-
|
171
|
-
|
161
|
+
def presenter
|
162
|
+
presenter_class.new(@generic_file)
|
163
|
+
end
|
172
164
|
|
173
|
-
|
174
|
-
|
175
|
-
|
165
|
+
def version_list
|
166
|
+
Sufia::VersionListPresenter.new(@generic_file.content.versions.all)
|
167
|
+
end
|
176
168
|
|
177
|
-
|
178
|
-
|
179
|
-
|
169
|
+
def edit_form
|
170
|
+
edit_form_class.new(@generic_file)
|
171
|
+
end
|
180
172
|
|
181
|
-
|
182
|
-
|
183
|
-
|
173
|
+
def audit_service
|
174
|
+
Sufia::GenericFileAuditService.new(@generic_file)
|
175
|
+
end
|
184
176
|
|
185
|
-
|
186
|
-
|
177
|
+
def wants_to_revert?
|
178
|
+
params.key?(:revision) && params[:revision] != @generic_file.content.latest_version.label
|
179
|
+
end
|
187
180
|
|
188
|
-
|
189
|
-
|
190
|
-
|
181
|
+
def wants_to_upload_new_version?
|
182
|
+
has_file_data = params.key?(:filedata)
|
183
|
+
on_version_tab = params[:redirect_tab] == 'versions'
|
191
184
|
|
192
|
-
|
193
|
-
|
194
|
-
end
|
185
|
+
has_file_data || (on_version_tab && !wants_to_revert?)
|
186
|
+
end
|
195
187
|
|
196
|
-
|
197
|
-
|
198
|
-
actor.update_content(params[:filedata], file_path)
|
199
|
-
else
|
200
|
-
flash[:error] = 'Please select a file.'
|
201
|
-
false
|
188
|
+
def actor
|
189
|
+
@actor ||= Sufia::GenericFile::Actor.new(@generic_file, current_user)
|
202
190
|
end
|
203
|
-
end
|
204
191
|
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
actor.update_metadata(file_attributes, params[:visibility])
|
209
|
-
end
|
192
|
+
def update_version
|
193
|
+
actor.revert_content(params[:revision])
|
194
|
+
end
|
210
195
|
|
211
|
-
|
212
|
-
|
213
|
-
|
196
|
+
def update_file
|
197
|
+
if params[:filedata]
|
198
|
+
actor.update_content(params[:filedata], file_path)
|
199
|
+
else
|
200
|
+
flash[:error] = 'Please select a file.'
|
201
|
+
false
|
202
|
+
end
|
203
|
+
end
|
214
204
|
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
205
|
+
# this is provided so that implementing application can override this behavior and map params to different attributes
|
206
|
+
def update_metadata
|
207
|
+
file_attributes = edit_form_class.model_attributes(params[:generic_file])
|
208
|
+
actor.update_metadata(file_attributes, params[:visibility])
|
209
|
+
end
|
220
210
|
|
221
|
-
|
222
|
-
|
223
|
-
|
211
|
+
def update_visibility
|
212
|
+
actor.update_metadata({}, params[:visibility])
|
213
|
+
end
|
224
214
|
|
225
|
-
|
215
|
+
def json_error(error, name = nil, additional_arguments = {})
|
216
|
+
args = { error: error }
|
217
|
+
args[:name] = name if name
|
218
|
+
render additional_arguments.merge(json: [args])
|
219
|
+
end
|
226
220
|
|
227
|
-
|
221
|
+
def empty_file?(file)
|
222
|
+
(file.respond_to?(:tempfile) && file.tempfile.size == 0) || (file.respond_to?(:size) && file.size == 0)
|
223
|
+
end
|
228
224
|
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
225
|
+
def process_file(file)
|
226
|
+
Batch.find_or_create(params[:batch_id])
|
227
|
+
|
228
|
+
update_metadata_from_upload_screen
|
229
|
+
actor.create_metadata(params[:batch_id])
|
230
|
+
if actor.create_content(file, file.original_filename, file_path, file.content_type)
|
231
|
+
respond_to do |format|
|
232
|
+
format.html do
|
233
|
+
render 'jq_upload', formats: 'json', content_type: 'text/html'
|
234
|
+
end
|
235
|
+
format.json do
|
236
|
+
render 'jq_upload'
|
237
|
+
end
|
238
|
+
end
|
239
|
+
else
|
240
|
+
msg = @generic_file.errors.full_messages.join(', ')
|
241
|
+
flash[:error] = msg
|
242
|
+
json_error "Error creating generic file: #{msg}"
|
239
243
|
end
|
240
|
-
else
|
241
|
-
msg = @generic_file.errors.full_messages.join(', ')
|
242
|
-
flash[:error] = msg
|
243
|
-
json_error "Error creating generic file: #{msg}"
|
244
244
|
end
|
245
|
-
end
|
246
245
|
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
246
|
+
# override this method if you want to change how the terms are accepted on upload.
|
247
|
+
def terms_accepted?
|
248
|
+
params[:terms_of_service] == '1'
|
249
|
+
end
|
251
250
|
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
251
|
+
# override this method if you need to initialize more complex RDF assertions (b-nodes)
|
252
|
+
# @deprecated use @generic_file.initialize_fields instead
|
253
|
+
def initialize_fields(file)
|
254
|
+
file.initialize_fields
|
255
|
+
end
|
257
256
|
|
258
|
-
|
257
|
+
ActiveSupport::Deprecation.deprecate_methods(FilesControllerBehavior, :initialize_fields)
|
259
258
|
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
259
|
+
# The path of the fedora node where we store the file data
|
260
|
+
def file_path
|
261
|
+
'content'
|
262
|
+
end
|
264
263
|
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
264
|
+
# this is provided so that implementing application can override this behavior and map params to different attributes
|
265
|
+
# called when creating or updating metadata
|
266
|
+
def update_metadata_from_upload_screen
|
267
|
+
# Relative path is set by the jquery uploader when uploading a directory
|
268
|
+
@generic_file.relative_path = params[:relative_path] if params[:relative_path]
|
269
|
+
@generic_file.on_behalf_of = params[:on_behalf_of] if params[:on_behalf_of]
|
270
|
+
end
|
272
271
|
end
|
273
272
|
end
|