This repository has been archived by the owner on Oct 16, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
submissions_controller.rb
108 lines (94 loc) · 2.69 KB
/
submissions_controller.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# == Schema Information
#
# Table name: submissions
#
# id :integer not null, primary key
# user_id :integer
# title :string not null
# journal :string
# doi :string
# created_at :datetime not null
# updated_at :datetime not null
# documents :string
# status :string
# handle :string
# uuid :string
# pub_date :datetime
# funders :string
#
class SubmissionsController < ApplicationController
before_action :require_user
before_action :authenticate_user!
before_action :set_s3_direct_post, only: [:new, :create]
load_and_authorize_resource
def index
@submissions = if current_user.admin?
filtered_submissions
else
current_user.submissions.order(created_at: :desc)
end
end
def new
@submission = Submission.new
@submission.user = current_user
end
def create
@submission = Submission.new(submission_params)
@submission.user = current_user
if @submission.save
SwordSubmitJob.perform_later(@submission, callback_uri)
flash.notice = 'Your Submission is now in progress'
redirect_to submissions_path
else
render 'new'
end
end
def package
@submission = Submission.find_by_id(params[:id])
@submission.to_sword_package(callback_uri)
send_file(@submission.sword_path)
end
def resubmit
@submission = Submission.find_by_id(params[:id])
SwordSubmitJob.perform_later(@submission, callback_uri)
flash.notice = 'Submission has been resubmitted to the job queue'
redirect_to submissions_path
end
def show
end
def destroy
@submission.destroy
flash.notice = 'Submission has been deleted'
redirect_to submissions_path
end
private
def require_user
return if current_user
if ENV['FAKE_AUTH_ENABLED'] == 'true'
redirect_to user_developer_omniauth_authorize_path
else
redirect_to user_mit_oauth2_omniauth_authorize_path
end
end
def filtered_submissions
if params[:filter]
Submission.where(status: params[:filter])
else
Submission.all.order(created_at: :desc)
end
end
def set_s3_direct_post
@s3_direct_post = S3_BUCKET.presigned_post(
key: "uploads/#{SecureRandom.uuid}/${filename}",
success_action_status: '201',
acl: 'public-read')
end
def callback_uri
"#{root_url}callbacks/status/#{@submission.uuid}"
end
def submission_params
params.require(:submission).permit(:title, :agreed_to_license, :pub_date,
:journal, :doi, :documents_cache,
documents: [], funders: [])
end
end