-
Notifications
You must be signed in to change notification settings - Fork 78
/
batch_uploads_controller_behavior.rb
51 lines (44 loc) · 1.57 KB
/
batch_uploads_controller_behavior.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
module Sufia
module BatchUploadsControllerBehavior
extend ActiveSupport::Concern
include Hydra::Controller::ControllerBehavior
include CurationConcerns::CurationConcernController
included do
layout "sufia-one-column"
self.curation_concern_type = form_class.model_class
end
def create
authenticate_user!
create_update_job
flash[:notice] = t('sufia.generic_works.new.after_create_html', application_name: view_context.application_name)
redirect_after_update
end
protected
# Gives the class of the form.
# This overrides CurationConcerns
def form_class
::Sufia::Forms::BatchUploadForm
end
def redirect_after_update
if uploading_on_behalf_of?
redirect_to sufia.dashboard_shares_path
else
redirect_to sufia.dashboard_works_path
end
end
def create_update_job
log = BatchCreateOperation.create!(user: current_user,
operation_type: "Batch Create")
BatchCreateJob.perform_later(current_user,
form_class.model_class.model_name.name,
params[:title],
params[:resource_type],
params[:uploaded_files],
attributes_for_actor,
log)
end
def uploading_on_behalf_of?
params.fetch(hash_key_for_curation_concern).key?(:on_behalf_of)
end
end
end