diff --git a/app/assets/stylesheets/application.scss b/app/assets/stylesheets/application.scss index 6204953d2..ebf66abb9 100644 --- a/app/assets/stylesheets/application.scss +++ b/app/assets/stylesheets/application.scss @@ -254,4 +254,8 @@ th { .bi-arrow-down-up::before { color: grey; cursor: move; +} + +.file-upload { + margin-bottom: 1em; } \ No newline at end of file diff --git a/app/controllers/works_controller.rb b/app/controllers/works_controller.rb index 4f0dbd4fe..511379110 100644 --- a/app/controllers/works_controller.rb +++ b/app/controllers/works_controller.rb @@ -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 @@ -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 @@ -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 diff --git a/app/views/works/_wizard_progress.html.erb b/app/views/works/_wizard_progress.html.erb index e3d551604..dfa3dbc96 100644 --- a/app/views/works/_wizard_progress.html.erb +++ b/app/views/works/_wizard_progress.html.erb @@ -6,17 +6,21 @@  
- Upload
+ Readme
 
- Review
+ Upload
 
- Completed
+ Review
 
+
+ Completed
+   +
diff --git a/app/views/works/attachment_select.erb b/app/views/works/attachment_select.erb index 81f9f6513..97602b5c9 100644 --- a/app/views/works/attachment_select.erb +++ b/app/views/works/attachment_select.erb @@ -1,6 +1,6 @@

New Submission (<%= @work.title %>)

- <%= render "wizard_progress", wizard_step: 2 %> + <%= render "wizard_progress", wizard_step: 3 %>

Begin the process to upload your submission. Please select the most appropriate description.

My submission is...

@@ -14,7 +14,7 @@ <%= @work.files_location_other? ? "checked" : "" %>>more than 100MB and located somewhere else.
- <%= 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" %>
<% end %> diff --git a/app/views/works/file_cluster.html.erb b/app/views/works/file_cluster.html.erb index 0716797f6..807dafe8e 100644 --- a/app/views/works/file_cluster.html.erb +++ b/app/views/works/file_cluster.html.erb @@ -1,6 +1,6 @@

New Submission (<%= @work.title %>)

- <%= render "wizard_progress", wizard_step: 2 %> + <%= render "wizard_progress", wizard_step: 3 %>

Please indicate how we may access your submission in the Princeton Research Cluster:

<%= form_tag(action: "review", id: @work) do %> diff --git a/app/views/works/file_other.html.erb b/app/views/works/file_other.html.erb index 511ecf7a4..88607cfb8 100644 --- a/app/views/works/file_other.html.erb +++ b/app/views/works/file_other.html.erb @@ -1,6 +1,6 @@

New Submission (<%= @work.title %>)

- <%= render "wizard_progress", wizard_step: 2 %> + <%= render "wizard_progress", wizard_step: 3 %>

Please indicate where and how we may access your submission:

<%= form_tag(action: "review", id: @work) do %> diff --git a/app/views/works/file_upload.html.erb b/app/views/works/file_upload.html.erb index 5117cd48e..b7cc4c43a 100644 --- a/app/views/works/file_upload.html.erb +++ b/app/views/works/file_upload.html.erb @@ -1,6 +1,6 @@

<%= t('works.form.file_upload.heading', work_title: @work.title) %>

- <%= 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| %>
<%= f.file_field(:pre_curation_uploads, multiple: true) %> diff --git a/app/views/works/readme_select.html.erb b/app/views/works/readme_select.html.erb new file mode 100644 index 000000000..bd5ac9e57 --- /dev/null +++ b/app/views/works/readme_select.html.erb @@ -0,0 +1,21 @@ +
+

<%= t('works.form.file_upload.heading', work_title: @work.title) %>

+ <%= render "wizard_progress", wizard_step: 2 %> + <%= form_with(model: @work, scope: :patch, url: work_readme_uploaded_path(id: @work.id)) do |f| %> +

<%= t('works.form.readme_upload.title') %>

+

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") %>.

+ + +

<%= t('works.form.readme_upload.actions') %>

+
+
+ <%= f.file_field(:readme_file, multiple: false) %> +
+ +
+ <%= 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') %> +
+ <% end %> +
+ diff --git a/app/views/works/review.html.erb b/app/views/works/review.html.erb index 6f943113d..796eda01b 100644 --- a/app/views/works/review.html.erb +++ b/app/views/works/review.html.erb @@ -1,6 +1,6 @@

New Submission (<%= @work.title %>)

- <%= render "wizard_progress", wizard_step: 3 %> + <%= render "wizard_progress", wizard_step: 4 %> <%= render "license_text" %>

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" diff --git a/config/locales/en.yml b/config/locales/en.yml index 4bea25e70..d50ac735e 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -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." diff --git a/config/routes.rb b/config/routes.rb index 8f47f6ef9..610baf4d9 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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 diff --git a/spec/controllers/works_controller_spec.rb b/spec/controllers/works_controller_spec.rb index 263e31b72..30e14d437 100644 --- a/spec/controllers/works_controller_spec.rb +++ b/spec/controllers/works_controller_spec.rb @@ -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 @@ -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 } diff --git a/spec/routing/works_routing_spec.rb b/spec/routing/works_routing_spec.rb index a60c408f2..acd607278 100644 --- a/spec/routing/works_routing_spec.rb +++ b/spec/routing/works_routing_spec.rb @@ -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" } diff --git a/spec/system/authz_submitter_spec.rb b/spec/system/authz_submitter_spec.rb index fb4e57eb0..a27d393d9 100644 --- a/spec/system/authz_submitter_spec.rb +++ b/spec/system/authz_submitter_spec.rb @@ -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" diff --git a/spec/system/authz_super_admin_spec.rb b/spec/system/authz_super_admin_spec.rb index ccee61635..bbb712382 100644 --- a/spec/system/authz_super_admin_spec.rb +++ b/spec/system/authz_super_admin_spec.rb @@ -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" diff --git a/spec/system/external_ids_spec.rb b/spec/system/external_ids_spec.rb index 9d5ccb340..761f402fc 100644 --- a/spec/system/external_ids_spec.rb +++ b/spec/system/external_ids_spec.rb @@ -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" diff --git a/spec/system/work_create_spec.rb b/spec/system/work_create_spec.rb index b29377b51..45a7b23ea 100644 --- a/spec/system/work_create_spec.rb +++ b/spec/system/work_create_spec.rb @@ -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 @@ -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" @@ -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"