Skip to content

Commit

Permalink
Merge pull request #1433 from projecthydra/redirect_after_upload
Browse files Browse the repository at this point in the history
Redirect to upload_set#edit after upload
  • Loading branch information
awead committed Dec 10, 2015
2 parents 6d2308d + de45511 commit e619ace
Show file tree
Hide file tree
Showing 11 changed files with 59 additions and 71 deletions.
18 changes: 0 additions & 18 deletions app/actors/sufia/file_set_actor.rb

This file was deleted.

17 changes: 14 additions & 3 deletions app/controllers/concerns/sufia/file_sets_controller_behavior.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ module FileSetsControllerBehavior
end

def new
@upload_set_id = ActiveFedora::Noid::Service.new.mint
@upload_set_id = SecureRandom.uuid
end

# routed to /files/:id/stats
Expand Down Expand Up @@ -98,12 +98,23 @@ def file_set_params
end

def find_parent_by_id
return if parent_id.empty?
return default_work unless parent_id.present?
super
end

# If the user is creating a bunch of files, and not in a work context,
# create a work for each file.
def default_work
# Ensure the upload set exists, before trying to associate a work with it.
upload_set = UploadSet.find_or_create(params[:upload_set_id])
GenericWork.create!(title: [params[:file_set][:files].first.original_filename],
upload_set: upload_set) do |w|
w.apply_depositor_metadata(current_user)
end
end

def actor
@actor ||= ::Sufia::FileSetActor.new(@file_set, current_user)
@actor ||= CurationConcerns::FileSetActor.new(@file_set, current_user)
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
</div>
<% end %>
<div class="well">
<%= render partial: 'curation_concerns/file_sets/upload/form_fields' %>
<%= render 'curation_concerns/file_sets/upload/form_fields' %>
</div>
<% end %>
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
<!-- TODO: make the upload_set_id available on the presenter -->
<div class="alert alert-info hide" id="redirect-loc" type="text/x-jquery-tmpl">
<%# Script redirects here once the uploads are complete %>
<%# TODO: change this once multifile upload issues have been resolved %>
<%= sufia.dashboard_files_path %>
<%= CurationConcerns::FileSetsController.upload_complete_path(@upload_set_id) %>
</div>

<!-- The template to display files available for upload -->
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<label>
<%= check_box_tag 'terms_of_service', 1, nil, {data: {activate: 'activate-submit'}} %><strong> I have read and do agree to <%= link_to t('sufia.deposit_agreement'), '/agreement/', target: "_blank" %>.</strong>
</label>
<%= check_box_tag 'terms_of_service', 1, nil, { data: { activate: 'activate-submit' } } %><strong> I have read and do agree to <%= link_to t('sufia.deposit_agreement'), '/agreement/', target: "_blank" %>.</strong>
</label>
2 changes: 1 addition & 1 deletion config/locales/sufia.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ en:
creator_html: 'The person or group responsible for the collection. Usually this is the author of the collected content. Personal names should be entered with the last name first, e.g. "Smith, John." <em>This is a required field</em>.'

aria_label:
file_set:
upload_set:
default: "Usage information for %{title}"
based_near: "Usage information for location"
description: "Usage information for abstract or summary"
Expand Down
23 changes: 0 additions & 23 deletions spec/actors/file_set_actor_spec.rb

This file was deleted.

4 changes: 3 additions & 1 deletion spec/controllers/file_sets_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,15 @@
end

context "when a work id is not passed" do
routes { Sufia::Engine.routes }
it "creates the FileSet" do
skip "Creating a FileSet without a parent work is not yet supported"
xhr :post, :create, file_set: { files: [file], Filename: 'The world' },
upload_set_id: upload_set_id,
terms_of_service: '1'
expect(response).to be_success
expect(reloaded_file_set.generic_works).not_to be_empty
expect(reloaded_file_set.generic_works.first.upload_set_id).to eq upload_set_id
expect(reloaded_file_set.generic_works.first.title).to eq ['world.png']
end
end
end
Expand Down
14 changes: 7 additions & 7 deletions spec/controllers/upload_sets_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
'open')
post :update, id: upload_set, title: { '1' => 'foo' },
visibility: 'open',
work: { tag: [""] }
upload_set: { tag: [""] }
expect(response).to redirect_to Sufia::Engine.routes.url_helpers.dashboard_files_path
expect(flash[:notice]).to include("Your files are being processed")
end
Expand All @@ -33,7 +33,7 @@
end

it "redirects to my shares page" do
post :update, id: upload_set, work: { permissions_attributes: [{ type: "group", name: "public", access: "read" }] }
post :update, id: upload_set, upload_set: { permissions_attributes: [{ type: "group", name: "public", access: "read" }] }
expect(response).to redirect_to Sufia::Engine.routes.url_helpers.dashboard_shares_path
end
end
Expand All @@ -43,26 +43,26 @@
let!(:work) { create(:work, upload_set: upload_set, user: user) }

it "sets the groups" do
post :update, id: upload_set, "work" => { "permissions_attributes" => [{ "type" => "group", "name" => "public", "access" => "read" }] }
post :update, id: upload_set, upload_set: { "permissions_attributes" => [{ "type" => "group", "name" => "public", "access" => "read" }] }
expect(response).to redirect_to Sufia::Engine.routes.url_helpers.dashboard_files_path
work.reload
expect(work.read_groups).to include "public"
end

it "sets public read access" do
post :update, id: upload_set, visibility: "open", work: { tag: [""] }
post :update, id: upload_set, visibility: "open", upload_set: { tag: [""] }
expect(work.reload.read_groups).to eq ['public']
end

it "sets metadata like title" do
post :update, id: upload_set, work: { tag: ["footag", "bartag"] }, title: { work.id => ["New Title"] }
post :update, id: upload_set, upload_set: { tag: ["footag", "bartag"] }, title: { work.id => ["New Title"] }
work.reload
expect(work.title).to eq ["New Title"]
expect(work.tag).to include("footag", "bartag")
end

it "does not set any tags" do
post :update, id: upload_set, work: { tag: [""] }
post :update, id: upload_set, upload_set: { tag: [""] }
expect(work.reload.tag).to be_empty
end
end
Expand All @@ -76,7 +76,7 @@
end

it "does not modify the object" do
post :update, id: upload_set, work: { "read_groups_string" => "group1, group2", "read_users_string" => "", "tag" => [""] }, "title" => { work.id => "Title Wont Change" }
post :update, id: upload_set, upload_set: { "read_groups_string" => "group1, group2", "read_users_string" => "", "tag" => [""] }, "title" => { work.id => "Title Wont Change" }
work.reload
expect(work.title).to eq ["Original Title"]
expect(work.read_groups).to eq []
Expand Down
38 changes: 26 additions & 12 deletions spec/features/ingest_upload_files_spec.rb
Original file line number Diff line number Diff line change
@@ -1,25 +1,39 @@
require 'spec_helper'

describe "Uploading files via web form", type: :feature do
describe "Uploading files via web form", :js do
include ActiveJob::TestHelper
before do
Capybara.default_max_wait_time = 60
sign_in :user
click_link "Upload"
end

it "has an ingest screen" do
it "puts them in the repository" do
expect(page).to have_content "Select files"
expect(page).to have_content "Start upload"
expect(page).to have_content "Cancel upload"
expect(page).to have_xpath '//input[@type="file"]'
end

context "the terms of service", :js do
it "is required to be checked" do
attach_file("file_set[files][]", File.dirname(__FILE__) + "/../../spec/fixtures/image.jp2", visible: false)
attach_file("file_set[files][]", File.dirname(__FILE__) + "/../../spec/fixtures/jp2_fits.xml", visible: false)
expect(page).to have_css("button#main_upload_start[disabled]")
find('#main_upload_start_span').hover
expect(page).to have_content "Please accept Deposit Agreement before you can upload."
end
attach_file("file_set[files][]", File.dirname(__FILE__) + "/../../spec/fixtures/image.jp2", visible: false)
attach_file("file_set[files][]", File.dirname(__FILE__) + "/../../spec/fixtures/jp2_fits.xml", visible: false)
expect(page).to have_css("button#main_upload_start[disabled]")
find('#main_upload_start_span').hover
expect(page).to have_content "Please accept Deposit Agreement before you can upload."

check 'terms_of_service'

click_button "Start upload"

# This will take awhile because it's waiting for all files to upload and
# a redirect to the upload_set edit page.
expect(page).to have_content "Individual Titles"

expect(page).to have_css("input[type='text'][value='image.jp2']")
expect(page).to have_css("input[type='text'][value='jp2_fits.xml']")

fill_in 'upload_set_creator', with: 'Gaius Julius Caesar IV'

click_button "Save"

expect(page).to have_content "Your files are being processed by Repository in the background."
end
end
4 changes: 4 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,10 @@ def main_app

config.use_transactional_fixtures = false

config.before :suite do
DatabaseCleaner.clean_with(:truncation)
end

config.before :each do |example|
unless example.metadata[:type] == :view || example.metadata[:no_clean]
ActiveFedora::Cleaner.clean!
Expand Down

0 comments on commit e619ace

Please sign in to comment.