sufia 6.3.0 → 6.4.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/.gitignore +1 -2
- data/.rubocop.yml +10 -0
- data/Gemfile +16 -7
- data/History.md +43 -0
- data/README.md +26 -19
- data/SUFIA_VERSION +1 -1
- data/app/assets/javascripts/notifications_check.js.erb +46 -0
- data/app/assets/javascripts/sufia.js +1 -2
- data/app/assets/javascripts/sufia/uploader.js +3 -3
- data/app/assets/stylesheets/sufia/_collections.scss +5 -0
- data/app/assets/stylesheets/sufia/_dashboard.scss +6 -1
- data/app/assets/stylesheets/sufia/_file-listing.scss +44 -6
- data/app/assets/stylesheets/sufia/_file-show.scss +4 -0
- data/app/assets/stylesheets/sufia/_settings.scss +3 -0
- data/app/controllers/api/items_controller.rb +7 -3
- data/app/controllers/concerns/sufia/admin/depositor_stats.rb +1 -1
- data/app/controllers/concerns/sufia/admin/stats_behavior.rb +6 -76
- data/app/controllers/concerns/sufia/batch_controller_behavior.rb +10 -2
- data/app/controllers/concerns/sufia/contact_form_controller_behavior.rb +1 -0
- data/app/controllers/concerns/sufia/files_controller_behavior.rb +11 -1
- data/app/controllers/concerns/sufia/homepage_controller.rb +1 -1
- data/app/controllers/concerns/sufia/my_controller_behavior.rb +2 -0
- data/app/controllers/concerns/sufia/users_controller_behavior.rb +2 -2
- data/app/helpers/generic_file_helper.rb +8 -5
- data/app/jobs/content_delete_event_job.rb +16 -11
- data/app/jobs/content_deposit_event_job.rb +4 -16
- data/app/jobs/content_depositor_change_event_job.rb +32 -20
- data/app/jobs/content_event_job.rb +39 -0
- data/app/jobs/content_new_version_event_job.rb +4 -16
- data/app/jobs/content_restored_version_event_job.rb +6 -19
- data/app/jobs/content_update_event_job.rb +4 -16
- data/app/jobs/event_job.rb +48 -4
- data/app/jobs/user_edit_profile_event_job.rb +4 -17
- data/app/jobs/user_follow_event_job.rb +10 -12
- data/app/jobs/user_unfollow_event_job.rb +10 -15
- data/app/models/concerns/sufia/solr_document_behavior.rb +11 -1
- data/app/models/system_stats.rb +108 -0
- data/app/presenters/sufia/admin_stats_presenter.rb +49 -0
- data/app/views/_controls.html.erb +1 -1
- data/app/views/_footer.html.erb +1 -1
- data/app/views/_logo.html.erb +1 -3
- data/app/views/admin/stats/_date_form.html.erb +8 -0
- data/app/views/admin/stats/_deposits.html.erb +2 -10
- data/app/views/admin/stats/_files.html.erb +6 -14
- data/app/views/admin/stats/_new_users.html.erb +7 -14
- data/app/views/admin/stats/_stats_by_date.html.erb +8 -0
- data/app/views/admin/stats/_top_data.html.erb +24 -0
- data/app/views/admin/stats/index.html.erb +5 -31
- data/app/views/collections/_form_for_select_collection.html.erb +5 -4
- data/app/views/collections/_show_actions.html.erb +7 -2
- data/app/views/collections/_show_document_list_row.html.erb +1 -9
- data/app/views/generic_files/_browse_everything.html.erb +3 -0
- data/app/views/generic_files/_descriptions.html.erb +1 -1
- data/app/views/generic_files/_generic_file.html.erb +1 -1
- data/app/views/generic_files/_local_file_import.html.erb +3 -0
- data/app/views/generic_files/_show_actions.html.erb +4 -0
- data/app/views/generic_files/upload/_form.html.erb +3 -0
- data/app/views/generic_files/upload/_to_collection.html.erb +5 -0
- data/app/views/homepage/_recent_document.html.erb +1 -7
- data/app/views/my/_index_partials/_default_group.html.erb +1 -1
- data/app/views/my/_index_partials/_list_collections.html.erb +3 -10
- data/app/views/my/_index_partials/_list_files.html.erb +13 -22
- data/app/views/my/_sort_and_per_page.html.erb +3 -3
- data/app/views/records/edit_fields/_rights.html.erb +2 -1
- data/app/views/static/terms.html.erb +1 -1
- data/config/locales/sufia.en.yml +13 -0
- data/lib/generators/sufia/templates/catalog_controller.rb +2 -2
- data/lib/sufia/version.rb +1 -1
- data/spec/actors/generic_file/actor_spec.rb +35 -0
- data/spec/controllers/admin_stats_controller_spec.rb +53 -23
- data/spec/controllers/api/items_controller_spec.rb +47 -41
- data/spec/controllers/batch_controller_spec.rb +1 -0
- data/spec/controllers/generic_files_controller_spec.rb +35 -1
- data/spec/controllers/my/files_controller_spec.rb +5 -0
- data/spec/factories/generic_files.rb +3 -0
- data/spec/features/collection_spec.rb +91 -0
- data/spec/features/contact_form_spec.rb +1 -0
- data/spec/forms/collection_edit_form_spec.rb +3 -3
- data/spec/forms/generic_file_edit_form_spec.rb +1 -1
- data/spec/jobs/create_derivatives_job_spec.rb +6 -0
- data/spec/models/file_content_datastream_spec.rb +1 -1
- data/spec/models/file_download_stat_spec.rb +4 -4
- data/spec/models/file_usage_spec.rb +2 -2
- data/spec/models/file_view_stat_spec.rb +4 -4
- data/spec/models/generic_file_spec.rb +15 -3
- data/spec/models/geo_names_resource_spec.rb +10 -0
- data/spec/models/solr_document_spec.rb +28 -0
- data/spec/models/system_stats_spec.rb +184 -0
- data/spec/models/user_spec.rb +1 -1
- data/spec/models/user_usage_stats_spec.rb +1 -1
- data/spec/services/generic_file_csv_service_spec.rb +66 -0
- data/spec/services/generic_file_indexing_service_spec.rb +35 -0
- data/spec/services/lock_manager_spec.rb +12 -0
- data/spec/spec_helper.rb +2 -1
- data/spec/views/admin/stats/index.html.erb_spec.rb +11 -10
- data/spec/views/catalog/sort_and_per_page.html.erb_spec.rb +1 -1
- data/spec/views/collections/_form_for_select_collection.html.erb_spec.rb +51 -0
- data/spec/views/generic_file/_browse_everything.html.erb_spec.rb +4 -0
- data/spec/views/generic_file/edit.html.erb_spec.rb +31 -24
- data/spec/views/generic_file/new.html.erb_spec.rb +70 -0
- data/spec/views/generic_file/show.html.erb_spec.rb +23 -0
- data/sufia.gemspec +3 -2
- data/tasks/sufia-dev.rake +2 -0
- metadata +42 -9
- data/lib/sufia/role_mapper.rb +0 -7
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
|
|
6
6
|
$basic-black: #000;
|
|
7
7
|
$blue-dark: #036;
|
|
8
|
+
$blue-default: #337AB7;
|
|
8
9
|
$blue-medium: #1C5798;
|
|
9
10
|
$blue-medium-bright: #2674CA;
|
|
10
11
|
$teal: #2CAEB7;
|
|
@@ -79,3 +80,5 @@ $view-select-text-hover: $blue-medium-bright;
|
|
|
79
80
|
// File Show Page
|
|
80
81
|
$file-show-term-color: $gray-dark;
|
|
81
82
|
$heading-border-color: $gray-light;
|
|
83
|
+
$link-color: $blue-default;
|
|
84
|
+
$link-color-hover: $gray-dark;
|
|
@@ -57,12 +57,16 @@ module API
|
|
|
57
57
|
end
|
|
58
58
|
|
|
59
59
|
def validate_item
|
|
60
|
-
return render plain: 'no item parameter', status: :bad_request if
|
|
61
|
-
Sufia::Arkivo::SchemaValidator.new(
|
|
60
|
+
return render plain: 'no item parameter', status: :bad_request if post_data.blank?
|
|
61
|
+
Sufia::Arkivo::SchemaValidator.new(post_data).call
|
|
62
62
|
rescue Sufia::Arkivo::InvalidItem => exception
|
|
63
63
|
return render plain: "invalid item parameter: #{exception.message}", status: :bad_request
|
|
64
64
|
else
|
|
65
|
-
@item = JSON.parse(
|
|
65
|
+
@item = JSON.parse(post_data)
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def post_data
|
|
69
|
+
request.raw_post
|
|
66
70
|
end
|
|
67
71
|
|
|
68
72
|
def authorize_token
|
|
@@ -19,7 +19,7 @@ module Sufia::Admin::DepositorStats
|
|
|
19
19
|
start_datetime = DateTime.parse(deposit_stats[:start_date]) unless deposit_stats[:start_date].blank?
|
|
20
20
|
end_datetime = DateTime.parse(deposit_stats[:end_date]).end_of_day unless deposit_stats[:end_date].blank?
|
|
21
21
|
|
|
22
|
-
query = GenericFile.build_date_query(start_datetime, end_datetime) unless start_datetime.blank?
|
|
22
|
+
query = ::GenericFile.build_date_query(start_datetime, end_datetime) unless start_datetime.blank?
|
|
23
23
|
sb = DepositSearchBuilder.new([:include_depositor_facet], self)
|
|
24
24
|
facet_results = repository.search(sb.merge(q: query).query)
|
|
25
25
|
facets = facet_results["facet_counts"]["facet_fields"]["depositor_ssim"]
|
|
@@ -8,87 +8,17 @@ module Sufia
|
|
|
8
8
|
end
|
|
9
9
|
|
|
10
10
|
def index
|
|
11
|
-
|
|
12
|
-
@users_count = ::User.count
|
|
11
|
+
stats_filters = params.fetch(:stats_filters, {})
|
|
13
12
|
|
|
14
|
-
#
|
|
15
|
-
@
|
|
16
|
-
@recent_users = recent_users
|
|
13
|
+
# initialize the presenter
|
|
14
|
+
@presenter = AdminStatsPresenter.new(stats_filters, params.fetch(:limit, "5").to_i)
|
|
17
15
|
|
|
18
|
-
#
|
|
19
|
-
@
|
|
16
|
+
# get deposit stats
|
|
17
|
+
@presenter.deposit_stats = stats_filters
|
|
18
|
+
@presenter.depositors = depositors(stats_filters)
|
|
20
19
|
|
|
21
|
-
# Count of documents by permissions
|
|
22
|
-
@files_count = document_by_permission
|
|
23
|
-
|
|
24
|
-
# Query Solr for top file formats
|
|
25
|
-
@top_formats = top_formats
|
|
26
|
-
|
|
27
|
-
@deposit_stats = params.fetch(:deposit_stats, {})
|
|
28
|
-
@depositors = depositors(@deposit_stats)
|
|
29
20
|
render 'index'
|
|
30
21
|
end
|
|
31
|
-
|
|
32
|
-
private
|
|
33
|
-
|
|
34
|
-
def top_depositors_count
|
|
35
|
-
count = params[:dep_count].to_i
|
|
36
|
-
count.in?(5..20) ? count : 5
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
def document_by_permission
|
|
40
|
-
return document_by_date_by_permission if @users_stats[:file_start_date]
|
|
41
|
-
|
|
42
|
-
files_count = {}
|
|
43
|
-
files_count[:total] = ::GenericFile.count
|
|
44
|
-
files_count[:public] = ::GenericFile.where_public.count
|
|
45
|
-
files_count[:registered] = ::GenericFile.where_registered.count
|
|
46
|
-
files_count[:private] = files_count[:total] - (files_count[:registered] + files_count[:public])
|
|
47
|
-
files_count
|
|
48
|
-
end
|
|
49
|
-
|
|
50
|
-
def document_by_date_by_permission
|
|
51
|
-
start_date = DateTime.parse(@users_stats[:file_start_date])
|
|
52
|
-
end_date = DateTime.parse(@users_stats[:file_end_date]).end_of_day unless @users_stats[:file_end_date].blank?
|
|
53
|
-
files_count = {}
|
|
54
|
-
files_count[:total] = ::GenericFile.find_by_date_created(start_date, end_date).count
|
|
55
|
-
files_count[:public] = ::GenericFile.find_by_date_created(start_date, end_date).merge(::GenericFile.where_public).count
|
|
56
|
-
files_count[:registered] = ::GenericFile.find_by_date_created(start_date, end_date).merge(::GenericFile.where_registered).count
|
|
57
|
-
files_count[:private] = files_count[:total] - (files_count[:registered] + files_count[:public])
|
|
58
|
-
files_count
|
|
59
|
-
end
|
|
60
|
-
|
|
61
|
-
def top_depositors
|
|
62
|
-
depositor_key = Solrizer.solr_name('depositor', :stored_searchable, type: :string)
|
|
63
|
-
top_data(depositor_key, top_depositors_count)
|
|
64
|
-
end
|
|
65
|
-
|
|
66
|
-
def top_formats
|
|
67
|
-
format_key = Solrizer.solr_name('file_format', Solrizer::Descriptor.new(:string, :indexed, :multivalued))
|
|
68
|
-
top_data(format_key, 5)
|
|
69
|
-
end
|
|
70
|
-
|
|
71
|
-
def top_data(key, limit)
|
|
72
|
-
query_url = "#{ActiveFedora.solr_config[:url]}/terms?terms.fl=#{key}&terms.sort=count&terms.limit=#{limit}&wt=json&omitHeader=true"
|
|
73
|
-
# Parse JSON response (looks like {"terms":{"depositor_tesim":["mjg36",3]}} for depositor)
|
|
74
|
-
json = open(query_url).read
|
|
75
|
-
begin
|
|
76
|
-
tuples = JSON.parse(json)['terms'][key]
|
|
77
|
-
rescue
|
|
78
|
-
[]
|
|
79
|
-
end
|
|
80
|
-
# Change to hash where keys = logins and values = counts
|
|
81
|
-
Hash[*tuples]
|
|
82
|
-
end
|
|
83
|
-
|
|
84
|
-
def recent_users
|
|
85
|
-
# no dates return the top 5
|
|
86
|
-
return ::User.order('created_at DESC').limit(5) if @users_stats[:start_date].blank?
|
|
87
|
-
|
|
88
|
-
start_date = DateTime.parse @users_stats[:start_date]
|
|
89
|
-
end_date = DateTime.parse(@users_stats[:end_date]).end_of_day unless @users_stats[:end_date].blank?
|
|
90
|
-
::User.recent_users start_date, end_date
|
|
91
|
-
end
|
|
92
22
|
end
|
|
93
23
|
end
|
|
94
24
|
end
|
|
@@ -22,8 +22,7 @@ module Sufia
|
|
|
22
22
|
@batch = Batch.find_or_create(params[:id])
|
|
23
23
|
@batch.status = ["processing"]
|
|
24
24
|
@batch.save
|
|
25
|
-
|
|
26
|
-
Sufia.queue.push(BatchUpdateJob.new(current_user.user_key, params[:id], params[:title], file_attributes, params[:visibility]))
|
|
25
|
+
Sufia.queue.push(batch_update_job)
|
|
27
26
|
flash[:notice] = 'Your files are being processed by ' + t('sufia.product_name') + ' in the background. The metadata and access controls you specified are being applied. Files will be marked <span class="label label-danger" title="Private">Private</span> until this process is complete (shouldn\'t take too long, hang in there!). You may need to refresh your dashboard to see these updates.'
|
|
28
27
|
if uploading_on_behalf_of? @batch
|
|
29
28
|
redirect_to sufia.dashboard_shares_path
|
|
@@ -49,5 +48,14 @@ module Sufia
|
|
|
49
48
|
return false if file.nil? || file.on_behalf_of.blank?
|
|
50
49
|
current_user.user_key != file.on_behalf_of
|
|
51
50
|
end
|
|
51
|
+
|
|
52
|
+
def batch_update_job
|
|
53
|
+
@batch_update_job ||= BatchUpdateJob.new(
|
|
54
|
+
current_user.user_key,
|
|
55
|
+
params[:id],
|
|
56
|
+
params[:title],
|
|
57
|
+
edit_form_class.model_attributes(params[:generic_file]),
|
|
58
|
+
params[:visibility])
|
|
59
|
+
end
|
|
52
60
|
end
|
|
53
61
|
end
|
|
@@ -11,6 +11,7 @@ module Sufia
|
|
|
11
11
|
if @contact_form.respond_to?(:deliver_now) ? @contact_form.deliver_now : @contact_form.deliver
|
|
12
12
|
flash.now[:notice] = 'Thank you for your message!'
|
|
13
13
|
after_deliver
|
|
14
|
+
@contact_form = ContactForm.new
|
|
14
15
|
render :new
|
|
15
16
|
else
|
|
16
17
|
flash.now[:error] = 'Sorry, this message was not sent successfully. '
|
|
@@ -9,6 +9,8 @@ module Sufia
|
|
|
9
9
|
extend ActiveSupport::Concern
|
|
10
10
|
extend Sufia::FilesController::UploadCompleteBehavior
|
|
11
11
|
include Sufia::Breadcrumbs
|
|
12
|
+
include Hydra::Catalog
|
|
13
|
+
include Hydra::Collections::SelectsCollections
|
|
12
14
|
|
|
13
15
|
included do
|
|
14
16
|
include Hydra::Controller::ControllerBehavior
|
|
@@ -38,6 +40,9 @@ module Sufia
|
|
|
38
40
|
before_action :authenticate_user!, except: [:show, :citation, :stats]
|
|
39
41
|
before_action :has_access?, except: [:show]
|
|
40
42
|
before_action :build_breadcrumbs, only: [:show, :edit, :stats]
|
|
43
|
+
before_action only: [:new] do
|
|
44
|
+
find_collections_with_edit_access(true, -1, t("sufia.upload.collection.select_default_option"))
|
|
45
|
+
end
|
|
41
46
|
load_resource only: [:audit]
|
|
42
47
|
load_and_authorize_resource except: [:index, :audit, :show]
|
|
43
48
|
|
|
@@ -59,6 +64,7 @@ module Sufia
|
|
|
59
64
|
|
|
60
65
|
# routed to /files/new
|
|
61
66
|
def new
|
|
67
|
+
set_variables_for_new_form
|
|
62
68
|
@batch_id = ActiveFedora::Noid::Service.new.mint
|
|
63
69
|
end
|
|
64
70
|
|
|
@@ -152,6 +158,10 @@ module Sufia
|
|
|
152
158
|
|
|
153
159
|
protected
|
|
154
160
|
|
|
161
|
+
def set_variables_for_new_form
|
|
162
|
+
@collection_id = params[:collection] if @user_collections.collect(&:id).include? params[:collection]
|
|
163
|
+
end
|
|
164
|
+
|
|
155
165
|
def set_variables_for_edit_form
|
|
156
166
|
@form = edit_form
|
|
157
167
|
@groups = current_user.groups
|
|
@@ -227,7 +237,7 @@ module Sufia
|
|
|
227
237
|
|
|
228
238
|
update_metadata_from_upload_screen
|
|
229
239
|
actor.create_metadata(params[:batch_id])
|
|
230
|
-
if actor.create_content(file, file.original_filename, file_path, file.content_type)
|
|
240
|
+
if actor.create_content(file, file.original_filename, file_path, file.content_type, params[:collection])
|
|
231
241
|
respond_to do |format|
|
|
232
242
|
format.html do
|
|
233
243
|
render 'jq_upload', formats: 'json', content_type: 'text/html'
|
|
@@ -4,7 +4,7 @@ module Sufia::HomepageController
|
|
|
4
4
|
included do
|
|
5
5
|
# Adds Hydra behaviors into the application controller
|
|
6
6
|
include Hydra::Controller::ControllerBehavior
|
|
7
|
-
include Blacklight::
|
|
7
|
+
include Blacklight::SearchContext
|
|
8
8
|
include Sufia::Controller
|
|
9
9
|
include Blacklight::SearchHelper
|
|
10
10
|
include Hydra::Controller::SearchBuilder
|
|
@@ -52,6 +52,8 @@ module Sufia
|
|
|
52
52
|
@batch_size_on_other_page = batch_size - count_on_page
|
|
53
53
|
@batch_part_on_other_page = (@batch_size_on_other_page) > 0
|
|
54
54
|
|
|
55
|
+
@add_files_to_collection = params.fetch(:add_files_to_collection, '')
|
|
56
|
+
|
|
55
57
|
respond_to do |format|
|
|
56
58
|
format.html {}
|
|
57
59
|
format.rss { render layout: false }
|
|
@@ -2,9 +2,9 @@ module Sufia::UsersControllerBehavior
|
|
|
2
2
|
extend ActiveSupport::Concern
|
|
3
3
|
|
|
4
4
|
included do
|
|
5
|
-
include Blacklight::
|
|
5
|
+
include Blacklight::SearchContext
|
|
6
6
|
layout "sufia-one-column"
|
|
7
|
-
|
|
7
|
+
prepend_before_action :find_user, except: [:index, :search, :notifications_number]
|
|
8
8
|
before_action :authenticate_user!, only: [:edit, :update, :follow, :unfollow, :toggle_trophy]
|
|
9
9
|
before_action :user_not_current_user, only: [:follow, :unfollow]
|
|
10
10
|
authorize_resource only: [:edit, :update, :toggle_trophy]
|
|
@@ -13,7 +13,7 @@ module GenericFileHelper
|
|
|
13
13
|
if title.nil?
|
|
14
14
|
link_to download_image_tag, sufia.download_path(@generic_file), target: "_blank", title: "Download the document", id: "file_download", data: { label: @generic_file.id }
|
|
15
15
|
else
|
|
16
|
-
label = download_image_tag(title)
|
|
16
|
+
label = download_image_tag(title)
|
|
17
17
|
link_to label, sufia.download_path(@generic_file), target: "_blank", title: title, id: "file_download", data: { label: @generic_file.id }
|
|
18
18
|
end
|
|
19
19
|
end
|
|
@@ -34,10 +34,13 @@ module GenericFileHelper
|
|
|
34
34
|
private
|
|
35
35
|
|
|
36
36
|
def download_image_tag(title = nil)
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
37
|
+
content_tag :figure do
|
|
38
|
+
if title.nil?
|
|
39
|
+
concat image_tag "default.png", alt: "No preview available", class: "img-responsive"
|
|
40
|
+
else
|
|
41
|
+
concat image_tag sufia.download_path(@generic_file, file: 'thumbnail'), class: "img-responsive", alt: "#{title} of #{@generic_file.title.first}"
|
|
42
|
+
end
|
|
43
|
+
concat content_tag :figcaption, "Download the full sized image"
|
|
41
44
|
end
|
|
42
45
|
end
|
|
43
46
|
|
|
@@ -1,15 +1,20 @@
|
|
|
1
|
+
# A specific job to log a file deletion to a user's activity stream
|
|
2
|
+
#
|
|
3
|
+
# @attr_reader deleted_file_id The id of the file that has been deleted by the user
|
|
1
4
|
class ContentDeleteEventJob < EventJob
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
attr_reader :deleted_file_id
|
|
6
|
+
|
|
7
|
+
def initialize(deleted_file_id, depositor_id)
|
|
8
|
+
super(depositor_id)
|
|
9
|
+
@deleted_file_id = deleted_file_id
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def action
|
|
13
|
+
@action ||= "User #{link_to_profile depositor_id} has deleted file '#{deleted_file_id}'"
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
# override to log the event to the users profile stream instead of the user's stream
|
|
17
|
+
def log_user_event
|
|
9
18
|
depositor.log_profile_event(event)
|
|
10
|
-
# Fan out the event to all followers
|
|
11
|
-
depositor.followers.each do |follower|
|
|
12
|
-
follower.log_event(event)
|
|
13
|
-
end
|
|
14
19
|
end
|
|
15
20
|
end
|
|
@@ -1,18 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
timestamp = Time.now.to_i
|
|
6
|
-
depositor = User.find_by_user_key(depositor_id)
|
|
7
|
-
# Create the event
|
|
8
|
-
event = depositor.create_event(action, timestamp)
|
|
9
|
-
# Log the event to the depositor's profile stream
|
|
10
|
-
depositor.log_profile_event(event)
|
|
11
|
-
# Log the event to the GF's stream
|
|
12
|
-
gf.log_event(event)
|
|
13
|
-
# Fan out the event to all followers who have access
|
|
14
|
-
depositor.followers.select { |user| user.can? :read, gf }.each do |follower|
|
|
15
|
-
follower.log_event(event)
|
|
16
|
-
end
|
|
1
|
+
# A specific job to log a file deposit to a user's activity stream
|
|
2
|
+
class ContentDepositEventJob < ContentEventJob
|
|
3
|
+
def action
|
|
4
|
+
"User #{link_to_profile depositor_id} has deposited #{link_to generic_file.title.first, Sufia::Engine.routes.url_helpers.generic_file_path(generic_file)}"
|
|
17
5
|
end
|
|
18
6
|
end
|
|
@@ -1,4 +1,11 @@
|
|
|
1
|
-
|
|
1
|
+
# A specific job to log a file deposit change to a user's activity stream
|
|
2
|
+
#
|
|
3
|
+
# This is a bit wierd becuase the job performs the depositor transfer along with logging the job
|
|
4
|
+
#
|
|
5
|
+
# @attr [String] id identifier of the file to be transfered
|
|
6
|
+
# @attr [String] login the user key of the user the file is being transfered to.
|
|
7
|
+
# @attr [Boolean] reset (false) should the access controls be reset. This means revoking edit access from the depositor
|
|
8
|
+
class ContentDepositorChangeEventJob < ContentEventJob
|
|
2
9
|
def queue_name
|
|
3
10
|
:proxy_deposit
|
|
4
11
|
end
|
|
@@ -9,34 +16,39 @@ class ContentDepositorChangeEventJob < EventJob
|
|
|
9
16
|
# @param [String] login the user key of the user the file is being transfered to.
|
|
10
17
|
# @param [Boolean] reset (false) should the access controls be reset. This means revoking edit access from the depositor
|
|
11
18
|
def initialize(id, login, reset = false)
|
|
19
|
+
super(id, login)
|
|
12
20
|
self.id = id
|
|
13
21
|
self.login = login
|
|
14
22
|
self.reset = reset
|
|
15
23
|
end
|
|
16
24
|
|
|
17
25
|
def run
|
|
18
|
-
|
|
19
|
-
file = ::GenericFile.find(id)
|
|
20
|
-
file.proxy_depositor = file.depositor
|
|
21
|
-
file.clear_permissions! if reset
|
|
22
|
-
file.apply_depositor_metadata(login)
|
|
23
|
-
file.save!
|
|
26
|
+
super
|
|
24
27
|
|
|
25
|
-
action = "User #{link_to_profile file.proxy_depositor} has transferred #{link_to file.title.first, Sufia::Engine.routes.url_helpers.generic_file_path(file)} to user #{link_to_profile login}"
|
|
26
|
-
timestamp = Time.now.to_i
|
|
27
|
-
depositor = ::User.find_by_user_key(file.depositor)
|
|
28
|
-
proxy_depositor = ::User.find_by_user_key(file.proxy_depositor)
|
|
29
|
-
# Create the event
|
|
30
|
-
event = proxy_depositor.create_event(action, timestamp)
|
|
31
|
-
# Log the event to the GF's stream
|
|
32
|
-
file.log_event(event)
|
|
33
28
|
# log the event to the proxy depositor's profile
|
|
29
|
+
proxy_depositor = ::User.find_by_user_key(generic_file.proxy_depositor)
|
|
34
30
|
proxy_depositor.log_profile_event(event)
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def action
|
|
34
|
+
"User #{link_to_profile generic_file.proxy_depositor} has transferred #{link_to generic_file.title.first, Sufia::Engine.routes.url_helpers.generic_file_path(generic_file)} to user #{link_to_profile login}"
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
# overriding default to load from fedora and change the depositor
|
|
38
|
+
def generic_file
|
|
39
|
+
# TODO: This should be in its own job, not this event job
|
|
40
|
+
@generic_file ||= begin
|
|
41
|
+
file = ::GenericFile.find(id)
|
|
42
|
+
file.proxy_depositor = file.depositor
|
|
43
|
+
file.clear_permissions! if reset
|
|
44
|
+
file.apply_depositor_metadata(login)
|
|
45
|
+
file.save!
|
|
46
|
+
file
|
|
40
47
|
end
|
|
41
48
|
end
|
|
49
|
+
|
|
50
|
+
# overriding default to log the event to the depositor instead of their profile
|
|
51
|
+
def log_user_event
|
|
52
|
+
depositor.log_event(event)
|
|
53
|
+
end
|
|
42
54
|
end
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# A generic job for sending events about a generic files to a user and their followers.
|
|
2
|
+
#
|
|
3
|
+
# @attr [String] generic_file_id the id of the file the event is specified for
|
|
4
|
+
#
|
|
5
|
+
class ContentEventJob < EventJob
|
|
6
|
+
attr_accessor :generic_file_id
|
|
7
|
+
|
|
8
|
+
def initialize(generic_file_id, depositor_id)
|
|
9
|
+
super(depositor_id)
|
|
10
|
+
@generic_file_id = generic_file_id
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def run
|
|
14
|
+
super
|
|
15
|
+
|
|
16
|
+
log_generic_file_event
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def generic_file
|
|
20
|
+
@generic_file ||= GenericFile.load_instance_from_solr(generic_file_id)
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
# Log the event to the GF's stream
|
|
24
|
+
def log_generic_file_event
|
|
25
|
+
generic_file.log_event(event) unless generic_file.nil?
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
# override to check file permissions before logging to followers
|
|
29
|
+
def log_to_followers
|
|
30
|
+
depositor.followers.select { |user| user.can?(:read, generic_file) }.each do |follower|
|
|
31
|
+
follower.log_event(event)
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
# log the event to the users profile stream
|
|
36
|
+
def log_user_event
|
|
37
|
+
depositor.log_profile_event(event)
|
|
38
|
+
end
|
|
39
|
+
end
|