Skip to content

Commit

Permalink
Merge pull request #175 from psu-stewardship/upload_path
Browse files Browse the repository at this point in the history
Adding one location to define/ override where the upload redirects to af...
  • Loading branch information
jcoyne committed Aug 8, 2013
2 parents 9a4b75f + e4d6f3d commit 04d44f9
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 10 deletions.
4 changes: 2 additions & 2 deletions app/views/generic_files/upload/_alerts.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<div class="alert alert-info hide" id="success">
You have successfully uploaded some of your files. Either continue to upload or edit use the links below to abandon the rest of your added files.
<p>
<%= link_to 'Add Descriptions', sufia.batch_edit_path(@batch_noid), :class=>'btn' %>
<%= link_to 'Add Descriptions', GenericFilesController.upload_complete_path(@batch_noid), :class=>'btn' %>
</p>
</div>

Expand All @@ -12,7 +12,7 @@

<div class="alert hide" id="partial_fail">
One or more files did not upload successfully. To continue using the files uploaded use one of the links below.<br />
<%= link_to 'Add Descriptions', sufia.batch_edit_path(@batch_noid), :class=>'btn' %>
<%= link_to 'Add Descriptions', GenericFilesController.upload_complete_path(@batch_noid), :class=>'btn' %>
</div>

<div class="alert hide" id="errmsg"> </div>
Expand Down
2 changes: 1 addition & 1 deletion app/views/generic_files/upload/_script_templates.html.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<div class="alert alert-info hide" id="redirect-loc" type="text/x-jquery-tmpl">
<%-# Script redirects here once the uploads are complete %>
<%=sufia.batch_edit_path(@batch_noid)%>
<%=GenericFilesController.upload_complete_path(@batch_noid)%>
</div>

<!-- The template to display files available for upload -->
Expand Down
4 changes: 2 additions & 2 deletions lib/sufia/files_controller/local_ingest_behavior.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module FilesController::LocalIngestBehavior
def perform_local_ingest
if Sufia.config.enable_local_ingest && current_user.respond_to?(:directory)
if ingest_local_file
redirect_to sufia.batch_edit_path(params[:batch_id])
redirect_to GenericFilesController.upload_complete_path( params[:batch_id])
else
flash[:alert] = "Error importing files from user directory."
render :new
Expand Down Expand Up @@ -46,7 +46,7 @@ def ingest_one(filename, unarranged)
basename = File.basename(filename)
@generic_file.label = basename
@generic_file.relative_path = filename if filename != basename
Sufia::GenericFile::Actions.create_metadata(@generic_file, current_user, params[:batch_id] )
create_metadata(@generic_file)
Sufia.queue.push(IngestLocalFileJob.new(@generic_file.id, current_user.directory, filename, current_user.user_key))
end

Expand Down
7 changes: 7 additions & 0 deletions lib/sufia/files_controller/upload_complete_behavior.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module Sufia
module FilesController::UploadCompleteBehavior
def upload_complete_path(batch_id)
Sufia::Engine.routes.url_helpers.batch_edit_path(batch_id)
end
end # /FilesController::UploadCompleteBehavior
end # /Sufia
22 changes: 17 additions & 5 deletions lib/sufia/files_controller_behavior.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,19 @@
module Sufia
module FilesController
autoload :LocalIngestBehavior, 'sufia/files_controller/local_ingest_behavior'
autoload :UploadCompleteBehavior, 'sufia/files_controller/upload_complete_behavior'
end
module FilesControllerBehavior
extend ActiveSupport::Concern
extend Sufia::FilesController::UploadCompleteBehavior

included do
include Hydra::Controller::ControllerBehavior
include Blacklight::Configurable # comply with BL 3.7
include Sufia::Noid # for normalize_identifier method
include Sufia::FilesController::LocalIngestBehavior
include Sufia::FilesController::LocalIngestBehavior
extend Sufia::FilesController::UploadCompleteBehavior

layout "sufia-one-column"

# This is needed as of BL 3.7
Expand All @@ -48,6 +52,7 @@ module FilesControllerBehavior
prepend_before_filter :normalize_identifier, :except => [:index, :create, :new]
load_resource :only=>[:audit]
load_and_authorize_resource :except=>[:index, :audit]

end

# routed to /files/new
Expand Down Expand Up @@ -84,17 +89,19 @@ def create
end
end



def create_from_url(params)
params[:dropbox_urls].each do |db_file|
next if db_file.blank?
# do not remove ::
@generic_file = ::GenericFile.new
@generic_file.import_url = db_file
@generic_file.label = File.basename(db_file)
Sufia::GenericFile::Actions.create_metadata(@generic_file, current_user, params[:batch_id])
create_metadata(@generic_file)
Sufia.queue.push(ImportUrlJob.new(@generic_file.pid))
end
redirect_to sufia.batch_edit_path(params[:batch_id])
redirect_to self.class.upload_complete_path( params[:batch_id])
end

def create_from_upload(params)
Expand Down Expand Up @@ -189,7 +196,7 @@ def process_file(file)
if virus_check(file) == 0
@generic_file = ::GenericFile.new
update_metadata_from_upload_screen
Sufia::GenericFile::Actions.create_metadata(@generic_file, current_user, params[:batch_id])
create_metadata(@generic_file)
Sufia::GenericFile::Actions.create_content(@generic_file, file, file.original_filename, datastream_id, current_user)
respond_to do |format|
format.html {
Expand Down Expand Up @@ -243,7 +250,12 @@ def virus_check( file)
stat = Sufia::GenericFile::Actions.virus_check(file)
flash[:error] = "Virus checking did not pass for #{File.basename(file.path)} status = #{stat}" unless stat == 0
stat
end
end


def create_metadata(file)
Sufia::GenericFile::Actions.create_metadata(file, current_user, params[:batch_id])
end

end
end
18 changes: 18 additions & 0 deletions spec/controllers/generic_files_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
JSON.parse(response.body).first['error'].should match(/no file for upload/i)
end



it "should spawn a content deposit event job" do
file = fixture_file_upload('/world.png','image/png')
s1 = double('one')
Expand Down Expand Up @@ -181,6 +183,7 @@
end

describe "#create with local_file" do
let (:mock_url) {"http://example.com"}
before do
Sufia.config.enable_local_ingest = true
GenericFile.delete_all
Expand Down Expand Up @@ -218,6 +221,21 @@
files.first.label.should == 'world.png'
files.last.label.should == 'image.jp2'
end
it "should ingest redirect to another location" do
if $in_travis
# This is in place because we stub fits for travis, and the stub sets the mime to application/pdf.
# In order to avoid an invalid derivative creation, just stub out the derivatives.
GenericFile.any_instance.stub(:create_derivatives)
end
GenericFilesController.should_receive(:upload_complete_path).and_return(mock_url)
lambda { post :create, local_file: ["world.png"], batch_id: "xw42n7934"}.should change(GenericFile, :count).by(1)
response.should redirect_to mock_url
# These files should have been moved out of the upload directory
File.exist?("#{@mock_upload_directory}/world.png").should be_false
# And into the storage directory
files = GenericFile.find(Solrizer.solr_name("is_part_of",:symbol) => 'info:fedora/sufia:xw42n7934')
files.first.label.should == 'world.png'
end
it "should ingest directories from the filesystem" do
#TODO this test is very slow because it kicks off CharacterizeJob.
if $in_travis
Expand Down
26 changes: 26 additions & 0 deletions spec/lib/sufia/upload_complete_behavior_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
require "spec_helper"
class UploadThing
extend Sufia::FilesController::UploadCompleteBehavior
end

class UploadThingRedefine
extend Sufia::FilesController::UploadCompleteBehavior
def self.upload_complete_path(id)
return "example.com"
end

end

describe Sufia::FilesController::UploadCompleteBehavior do
let (:test_id) {"123abc"}
context "Not overridden" do
it "respond with the batch edit path" do
UploadThing.upload_complete_path(test_id).should == Sufia::Engine.routes.url_helpers.batch_edit_path(test_id)
end
end
context "overriden path" do
it "respond with the batch edit path" do
UploadThingRedefine.upload_complete_path(test_id).should == "example.com"
end
end
end

0 comments on commit 04d44f9

Please sign in to comment.