Skip to content

Commit

Permalink
Merge branch 'main' into issue-1021-edit-two
Browse files Browse the repository at this point in the history
  • Loading branch information
hectorcorrea committed Mar 31, 2023
2 parents ae7a5fa + 6608b74 commit 87e60ed
Show file tree
Hide file tree
Showing 17 changed files with 141 additions and 11 deletions.
4 changes: 4 additions & 0 deletions app/assets/stylesheets/application.scss
Original file line number Diff line number Diff line change
Expand Up @@ -254,4 +254,8 @@ th {
.bi-arrow-down-up::before {
color: grey;
cursor: move;
}

.file-upload {
margin-bottom: 1em;
}
25 changes: 24 additions & 1 deletion app/controllers/works_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,23 @@ def datacite_validate
end
end

def readme_select
@work = Work.find(params[:id])
@wizard = true
end

def readme_uploaded
@work = Work.find(params[:id])
@wizard = true
if readme_file_param
extension = File.extname(readme_file_param.original_filename)
content_type = readme_file_param.content_type
@work.pre_curation_uploads.attach(io: readme_file_param.to_io, filename: "README#{extension}", content_type: content_type)
@work.save!
end
redirect_to work_attachment_select_url(@work)
end

private

def work_params
Expand All @@ -299,6 +316,12 @@ def pre_curation_uploads_param
patch_params[:pre_curation_uploads_added]
end

def readme_file_param
return if patch_params.nil?

patch_params[:readme_file]
end

def rescue_aasm_error
yield
rescue AASM::InvalidTransition => error
Expand Down Expand Up @@ -364,7 +387,7 @@ def process_updates
@work.log_changes(resource_compare, current_user.id)

if @wizard_mode
redirect_to work_attachment_select_url(@work)
redirect_to work_readme_select_url(@work)
else
redirect_to work_url(@work), notice: "Work was successfully updated."
end
Expand Down
10 changes: 7 additions & 3 deletions app/views/works/_wizard_progress.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,21 @@
<span class="wizard-step-bar<%= wizard_step == 1 ? '-active' : '' %>">&nbsp;</span>
</div>
<div class="wizard-step">
<span class="wizard-step-info">Upload</span><br>
<span class="wizard-step-info">Readme</span><br>
<span class="wizard-step-bar<%= wizard_step == 2 ? '-active' : '' %>">&nbsp;</span>
</div>
<div class="wizard-step">
<span class="wizard-step-info">Review</span><br>
<span class="wizard-step-info">Upload</span><br>
<span class="wizard-step-bar<%= wizard_step == 3 ? '-active' : '' %>">&nbsp;</span>
</div>
<div class="wizard-step">
<span class="wizard-step-info">Completed</span><br>
<span class="wizard-step-info">Review</span><br>
<span class="wizard-step-bar<%= wizard_step == 4 ? '-active' : '' %>">&nbsp;</span>
</div>
<div class="wizard-step">
<span class="wizard-step-info">Completed</span><br>
<span class="wizard-step-bar<%= wizard_step == 5 ? '-active' : '' %>">&nbsp;</span>
</div>
</div>
</div>
</div>
Expand Down
4 changes: 2 additions & 2 deletions app/views/works/attachment_select.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<div class="wizard-area">
<h1>New Submission (<%= @work.title %>)</h1>
<%= render "wizard_progress", wizard_step: 2 %>
<%= render "wizard_progress", wizard_step: 3 %>
<p>Begin the process to upload your submission. Please select the most appropriate description.</p>

<p>My submission is...</p>
Expand All @@ -14,7 +14,7 @@
<%= @work.files_location_other? ? "checked" : "" %>>more than 100MB and located somewhere else.</input><br/>

<div class="actions">
<%= link_to "Go Back", edit_work_path(@work, wizard: true), class: "btn btn-secondary" %>
<%= link_to "Go Back", work_readme_select_path(@work, wizard: true), class: "btn btn-secondary" %>
<%= submit_tag "Continue", class: "btn btn-primary wizard-next-button" %>
</div>
<% end %>
Expand Down
2 changes: 1 addition & 1 deletion app/views/works/file_cluster.html.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<div class="wizard-area">
<h1>New Submission (<%= @work.title %>)</h1>
<%= render "wizard_progress", wizard_step: 2 %>
<%= render "wizard_progress", wizard_step: 3 %>
<p>Please indicate how we may access your submission in the Princeton Research Cluster:</p>

<%= form_tag(action: "review", id: @work) do %>
Expand Down
2 changes: 1 addition & 1 deletion app/views/works/file_other.html.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<div class="wizard-area">
<h1>New Submission (<%= @work.title %>)</h1>
<%= render "wizard_progress", wizard_step: 2 %>
<%= render "wizard_progress", wizard_step: 3 %>
<p>Please indicate where and how we may access your submission:</p>

<%= form_tag(action: "review", id: @work) do %>
Expand Down
2 changes: 1 addition & 1 deletion app/views/works/file_upload.html.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<div class="wizard-area">
<h1><%= t('works.form.file_upload.heading', work_title: @work.title) %></h1>
<%= render "wizard_progress", wizard_step: 2 %>
<%= render "wizard_progress", wizard_step: 3 %>
<%= form_with(model: @work, scope: :patch, url: work_file_uploaded_path(id: @work.id)) do |f| %>
<div id="file-error" class="error_box"></div>
<%= f.file_field(:pre_curation_uploads, multiple: true) %>
Expand Down
21 changes: 21 additions & 0 deletions app/views/works/readme_select.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<div class="wizard-area">
<h1><%= t('works.form.file_upload.heading', work_title: @work.title) %></h1>
<%= render "wizard_progress", wizard_step: 2 %>
<%= form_with(model: @work, scope: :patch, url: work_readme_uploaded_path(id: @work.id)) do |f| %>
<p><%= t('works.form.readme_upload.title') %></p>
<p>If you have not created a README, a <%= link_to("template may be found here", "https://cornell.app.box.com/v/ReadmeTemplate", target: "blank") %>. See this page <%= link_to("for more guidance on how to create a README","https://data.research.cornell.edu/content/readme", target: "blank") %>. </p>


<p><%= t('works.form.readme_upload.actions') %></p>
<div id="file-error" class="error_box"></div>
<div class="file-upload">
<%= f.file_field(:readme_file, multiple: false) %>
</div>

<div class="actions">
<%= link_to t('works.form.readme_upload.go_back'), edit_work_path(@work, wizard: true), class: "btn btn-secondary" %>
<%= f.submit(t('works.form.readme_upload.continue'), class: "btn btn-primary wizard-next-button", id: 'readme-upload') %>
</div>
<% end %>
</div>

2 changes: 1 addition & 1 deletion app/views/works/review.html.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<div class="wizard-area">
<h1>New Submission (<%= @work.title %>)</h1>
<%= render "wizard_progress", wizard_step: 3 %>
<%= render "wizard_progress", wizard_step: 4 %>
<%= render "license_text" %>
<p>Data curators will review the submission for accuracy and completeness to make
it more discoverable and reusable. Recommendations will be available in the "unfinished submissions"
Expand Down
6 changes: 6 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@ en:
heading: "Uncurated Files"
post_curation_uploads:
heading: "Curated Files"
readme_upload:
heading: "New Submission (%{work_title})"
title: "Please upload the README file for this submission."
actions: 'We will ask you about your data files on the next screen'
go_back: 'Go Back'
continue: 'Continue'
uneditable:
approved: "This work has been approved. Edits are no longer available."
privs: "You do not have permission to edit this work."
2 changes: 2 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@

get "works/:id/file-list", to: "works#file_list", as: :work_file_list
post "works/new-submission", to: "works#new_submission", as: :work_new_submission
get "works/:id/readme-select", to: "works#readme_select", as: :work_readme_select
patch "works/:id/readme-uploaded", to: "works#readme_uploaded", as: :work_readme_uploaded
get "works/:id/attachment-select", to: "works#attachment_select", as: :work_attachment_select
post "works/:id/attachment-select", to: "works#attachment_selected", as: :work_attachment_selected
patch "works/:id/file-upload", to: "works#file_uploaded", as: :work_file_uploaded
Expand Down
45 changes: 44 additions & 1 deletion spec/controllers/works_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@
sign_in user
post :update, params: params
expect(response.status).to be 302
expect(response.location).to eq "http://test.host/works/#{work.id}/attachment-select"
expect(response.location).to eq "http://test.host/works/#{work.id}/readme-select"
expect(ActiveStorage::PurgeJob).not_to have_received(:new)
end
end
Expand Down Expand Up @@ -610,6 +610,49 @@
end
end

describe "#readme_select" do
it "renders view to upload the readme" do
sign_in user
get :readme_select, params: { id: work.id }
expect(response).to render_template(:readme_select)
end
end

describe "#readme_uploaded" do
let(:bucket_url) do
"https://example-bucket.s3.amazonaws.com/"
end

let(:fake_s3_service) { stub_s3 }
let(:params) do
{
"_method" => "patch",
"authenticity_token" => "MbUfIQVvYoCefkOfSpzyS0EOuSuOYQG21nw8zgg2GVrvcebBYI6jy1-_3LSzbTg9uKgehxWauYS8r1yxcN1Lwg",
"patch" => {
"readme_file" => uploaded_file
},
"commit" => "Continue",
"controller" => "works",
"action" => "file_uploaded",
"id" => work.id
}
end

before do
fake_s3_service
stub_request(:put, /#{bucket_url}/).to_return(status: 200)
sign_in user
post :readme_uploaded, params: params
end

it "redirects to file-upload" do
expect(response.status).to be 302
work.reload
expect(work.pre_curation_uploads[0].key).to eq("#{work.doi}/#{work.id}/README.csv")
expect(response.location).to eq "http://test.host/works/#{work.id}/attachment-select"
end
end

it "renders view to select the kind of attachment to use" do
sign_in user
get :attachment_select, params: { id: work.id }
Expand Down
8 changes: 8 additions & 0 deletions spec/routing/works_routing_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@
expect(get: "/works/1/download?file=abc123").to route_to("work_downloader#download", id: "1", file: "abc123")
end

it "routes to #attachment_select" do
expect(get: "/works/1/readme-select").to route_to("works#readme_select", id: "1")
end

it "routes to #attachment_select" do
expect(patch: "/works/1/readme-uploaded").to route_to("works#readme_uploaded", id: "1")
end

context "when the Work has an ARK" do
let(:ark) { "ark:/88435/dsp01zc77st047" }

Expand Down
1 change: 1 addition & 0 deletions spec/system/authz_submitter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
click_on "Curator Controlled"
expect(page).to have_content "Research Data"
click_on "Save Work"
click_on "Continue"
page.find(:xpath, "//input[@value='file_other']").choose
click_on "Continue"
click_on "Continue"
Expand Down
1 change: 1 addition & 0 deletions spec/system/authz_super_admin_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
click_on "Curator Controlled"
expect(page).to have_content "Research Data"
click_on "Save Work"
click_on "Continue"
page.find(:xpath, "//input[@value='file_other']").choose
click_on "Continue"
click_on "Continue"
Expand Down
1 change: 1 addition & 0 deletions spec/system/external_ids_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
click_on "Save Work"
click_on "Continue"
click_on "Continue"
click_on "Continue"
click_on "Complete"

expect(page).to have_content "awaiting_approval"
Expand Down
16 changes: 16 additions & 0 deletions spec/system/work_create_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,11 @@
let(:ark) { "http://arks.princeton.edu/ark:/88435/dsp01d791sj97j" }
let(:collection) { "Research Data" }

let(:bucket_url) { "https://example-bucket.s3.amazonaws.com/" }

before do
stub_s3
stub_request(:put, /#{bucket_url}/).to_return(status: 200)
stub_datacite(host: "api.datacite.org", body: datacite_register_body(prefix: "10.34770"))
end
context "happy path" do
Expand Down Expand Up @@ -80,6 +83,18 @@
click_on "Additional Metadata"
fill_in "related_identifier_1", with: "https://related.example.com"
click_on "Save Work"
click_on "Back"
expect(page).to have_content(description)
click_on "Save Work"
expect(page).to have_content("Please upload the README")
path = Rails.root.join("spec", "fixtures", "files", "orcid.csv")
attach_file(path) do
page.find("#patch_readme_file").click
end
click_on "Continue"
click_on "Back"
expect(page).to have_content("Please upload the README")
click_on "Continue"
page.find(:xpath, "//input[@value='file_other']").choose
click_on "Continue"
click_on "Continue"
Expand All @@ -95,6 +110,7 @@
expect(roles).to include("ContactPerson") # Individual roles included
expect(roles).not_to include("HostingInstitution") # Organizational roles excluded
click_on "Save Work"
click_on "Continue"
expect(page).to have_content("under 100MB")
expect(page).to have_content("more than 100MB")
click_on "Continue"
Expand Down

0 comments on commit 87e60ed

Please sign in to comment.