sufia 3.4.0 → 3.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +6 -1
  3. data/Gemfile +7 -8
  4. data/README.md +13 -0
  5. data/SUFIA_VERSION +1 -1
  6. data/app/controllers/mailbox_controller.rb +8 -8
  7. data/app/jobs/ingest_local_file_job.rb +17 -13
  8. data/app/views/catalog/_home_text.html.erb +0 -3
  9. data/app/views/dashboard/_index_partials/_thumbnail_display.html.erb +5 -29
  10. data/app/views/mailbox/index.html.erb +9 -21
  11. data/app/views/users/_notify_link.html.erb +2 -17
  12. data/config/routes.rb +5 -3
  13. data/lib/sufia/files_controller_behavior.rb +45 -50
  14. data/lib/sufia/version.rb +1 -1
  15. data/lib/sufia/virus_found_error.rb +4 -0
  16. data/spec/controllers/generic_files_controller_spec.rb +14 -79
  17. data/spec/controllers/mailbox_controller_spec.rb +9 -13
  18. data/spec/features/users_spec.rb +0 -3
  19. data/spec/fixtures/sample_mpeg4.mp4 +0 -0
  20. data/spec/jobs/import_url_job_spec.rb +8 -8
  21. data/spec/jobs/ingest_local_file_job_spec.rb +13 -10
  22. data/spec/models/fits_datastream_spec.rb +72 -21
  23. data/spec/models/generic_file/actions_spec.rb +2 -17
  24. data/spec/models/generic_file/web_form_spec.rb +4 -3
  25. data/spec/models/generic_file_spec.rb +27 -0
  26. data/spec/routing/route_spec.rb +15 -20
  27. data/spec/spec_helper.rb +15 -2
  28. data/sufia-models/app/models/datastreams/fits_datastream.rb +10 -1
  29. data/sufia-models/lib/generators/sufia/models/install_generator.rb +1 -1
  30. data/sufia-models/lib/sufia/models/generic_file.rb +3 -0
  31. data/sufia-models/lib/sufia/models/generic_file/actions.rb +8 -11
  32. data/sufia-models/lib/sufia/models/generic_file/characterization.rb +19 -4
  33. data/sufia-models/lib/sufia/models/generic_file/virus_check.rb +33 -0
  34. data/sufia-models/lib/sufia/models/generic_file/web_form.rb +2 -3
  35. data/sufia-models/lib/sufia/models/jobs/import_url_job.rb +29 -31
  36. data/sufia-models/lib/sufia/models/version.rb +1 -1
  37. data/sufia.gemspec +1 -1
  38. data/tasks/sufia-dev.rake +2 -1
  39. metadata +10 -10
  40. data/app/assets/images/rails.png +0 -0
  41. data/app/assets/images/site_images/temp/guitar.jpg +0 -0
  42. data/app/assets/images/splashscreen.png +0 -0
  43. data/app/assets/images/video-still.png +0 -0
@@ -0,0 +1,4 @@
1
+ module Sufia
2
+ class VirusFoundError < StandardError
3
+ end
4
+ end
@@ -3,7 +3,6 @@ require 'spec_helper'
3
3
  describe GenericFilesController do
4
4
  before do
5
5
  controller.stub(:has_access?).and_return(true)
6
-
7
6
  @user = FactoryGirl.find_or_create(:user)
8
7
  sign_in @user
9
8
  User.any_instance.stub(:groups).and_return([])
@@ -17,10 +16,7 @@ describe GenericFilesController do
17
16
  end
18
17
  after do
19
18
  GenericFile.unstub(:new)
20
- begin
21
- Batch.find("sample:batch_id").delete
22
- rescue
23
- end
19
+ Batch.find("sample:batch_id").delete rescue
24
20
  @mock.delete unless @mock.inner_object.class == ActiveFedora::UnsavedDigitalObject
25
21
  end
26
22
 
@@ -43,6 +39,15 @@ describe GenericFilesController do
43
39
  CharacterizeJob.should_receive(:new).with('test:123').and_return(s2)
44
40
  Sufia.queue.should_receive(:push).with(s2).once
45
41
  xhr :post, :create, :files=>[file], :Filename=>"The world", :batch_id => "sample:batch_id", :permission=>{"group"=>{"public"=>"read"} }, :terms_of_service => '1'
42
+ flash[:error].should be_nil
43
+ end
44
+
45
+ it "displays a flash error when file has a virus" do
46
+ file = fixture_file_upload('/world.png', 'image/png')
47
+ Sufia::GenericFile::Actions.should_receive(:virus_check).with(file.path).and_raise(Sufia::VirusFoundError.new('A virus was found'))
48
+ xhr :post, :create, :files=>[file], :Filename=>"The world", :batch_id => "sample:batch_id", :permission=>{"group"=>{"public"=>"read"} }, :terms_of_service => '1'
49
+ flash[:error].should_not be_blank
50
+ flash[:error].should include('A virus was found')
46
51
  end
47
52
 
48
53
  it "should expand zip files" do
@@ -62,43 +67,6 @@ describe GenericFilesController do
62
67
  xhr :post, :create, :files=>[file], :Filename=>"The world", :batch_id => "sample:batch_id", :permission=>{"group"=>{"public"=>"read"} }, :terms_of_service => '1'
63
68
  end
64
69
 
65
- it "should download and import a file from a given url" do
66
- pending "This is just downloading a 401 error page"
67
- date_today = Date.today
68
- Date.stub(:today).and_return(date_today)
69
- generic_file = GenericFile.new #find(self.pid)
70
- Sufia::GenericFile::Actions.create_metadata(generic_file, @user, '1234')
71
- #generic_file.import_url = "https://dl.dropboxusercontent.com/1/view/kcb4j1dtkw0td3z/ArticleCritique.doc"
72
- generic_file.import_url = "https://dl.dropboxusercontent.com/1/view/m4og1xrgbk3ihw6/Getting%20Started.pdf"
73
- generic_file.save
74
- f = Tempfile.new(generic_file.pid) #self.pid)
75
- f.binmode
76
- # download file from url
77
- uri = URI(generic_file.import_url)
78
- http = Net::HTTP.new(uri.host, uri.port)
79
- http.use_ssl = uri.scheme == "https" # enable SSL/TLS
80
- http.verify_mode = OpenSSL::SSL::VERIFY_NONE
81
-
82
- http.start do
83
- http.request_get(uri.to_s) do |resp|
84
- resp.read_body do |segment|
85
- f.write(segment)
86
- end
87
- end
88
- end
89
- job_user = User.batchuser()
90
- user = User.find_by_user_key(generic_file.depositor)
91
- # check for virus
92
- if Sufia::GenericFile::Actions.virus_check(f) != 0
93
- message = "The file (#{File.basename(uri.path)}) was unable to be imported because it contained a virus."
94
- job_user.send_message(user, message, 'File Import Error')
95
- return
96
- end
97
- f.rewind
98
- # attach downloaded file to generic file stubbed out
99
- Sufia::GenericFile::Actions.create_content(generic_file, f, File.basename(uri.path), 'content', user)
100
- end
101
-
102
70
  it "should create and save a file asset from the given params" do
103
71
  date_today = Date.today
104
72
  Date.stub(:today).and_return(date_today)
@@ -159,19 +127,6 @@ describe GenericFilesController do
159
127
  saved_file.to_solr.keys.should include('depositor_tesim')
160
128
  saved_file.to_solr['depositor_tesim'].should == ['jilluser@example.com']
161
129
  end
162
- it "Should call virus check" do
163
- controller.should_receive(:virus_check).and_return(0)
164
- file = fixture_file_upload('/world.png','image/png')
165
-
166
- s1 = double('one')
167
- ContentDepositEventJob.should_receive(:new).with('test:123', 'jilluser@example.com').and_return(s1)
168
- Sufia.queue.should_receive(:push).with(s1).once
169
-
170
- s2 = double('one')
171
- CharacterizeJob.should_receive(:new).with('test:123').and_return(s2)
172
- Sufia.queue.should_receive(:push).with(s2).once
173
- xhr :post, :create, :files=>[file], :Filename=>"The world", :batch_id => "sample:batch_id", :permission=>{"group"=>{"public"=>"read"} }, :terms_of_service=>"1"
174
- end
175
130
 
176
131
  it "should error out of create and save after on continuos rsolr error" do
177
132
  GenericFile.any_instance.stub(:save).and_raise(RSolr::Error::Http.new({},{}))
@@ -181,7 +136,7 @@ describe GenericFilesController do
181
136
  response.body.should include("Error occurred while creating generic file.")
182
137
  end
183
138
  end
184
-
139
+
185
140
  describe "#create with local_file" do
186
141
  let (:mock_url) {"http://example.com"}
187
142
  before do
@@ -255,27 +210,9 @@ describe GenericFilesController do
255
210
  end
256
211
  end
257
212
  end
258
-
259
- describe "#virus_check" do
260
- it "passing virus check should not create flash error" do
261
- GenericFile.any_instance.stub(:to_solr).and_return({})
262
- file = fixture_file_upload('/world.png','image/png')
263
- Sufia::GenericFile::Actions.should_receive(:virus_check).with(file).and_return(0)
264
- controller.send :virus_check, file
265
- flash[:error].should be_nil
266
- end
267
- it "failing virus check should create flash" do
268
- GenericFile.any_instance.stub(:to_solr).and_return({})
269
- file = fixture_file_upload('/world.png','image/png')
270
- Sufia::GenericFile::Actions.should_receive(:virus_check).with(file).and_return(1)
271
- controller.send :virus_check, file
272
- flash[:error].should_not be_empty
273
- end
274
- end
275
213
 
276
214
  describe "audit" do
277
215
  before do
278
- #GenericFile.any_instance.stub(:to_solr).and_return({})
279
216
  @generic_file = GenericFile.new
280
217
  @generic_file.add_file(File.open(fixture_path + '/world.png'), 'content', 'world.png')
281
218
  @generic_file.apply_depositor_metadata('mjg36')
@@ -303,7 +240,7 @@ describe GenericFilesController do
303
240
  end
304
241
  after do
305
242
  @user.delete
306
- end
243
+ end
307
244
  it "should delete the file" do
308
245
  GenericFile.find(@generic_file.pid).should_not be_nil
309
246
  delete :destroy, :id=>@generic_file.pid
@@ -319,7 +256,6 @@ describe GenericFilesController do
319
256
 
320
257
  describe "update" do
321
258
  before do
322
- #controller.should_receive(:virus_check).and_return(0)
323
259
  @generic_file = GenericFile.new
324
260
  @generic_file.apply_depositor_metadata(@user)
325
261
  @generic_file.save
@@ -374,7 +310,6 @@ describe GenericFilesController do
374
310
  posted_file.content.mimeType.should == "image/jpeg"
375
311
  post :update, :id=>@generic_file.pid, :revision=>'content.0'
376
312
 
377
-
378
313
  restored_file = GenericFile.find(@generic_file.pid)
379
314
  version3 = restored_file.content.latest_version
380
315
  version3.versionID.should_not == version2.versionID
@@ -396,7 +331,7 @@ describe GenericFilesController do
396
331
  version1 = posted_file.content.latest_version
397
332
  posted_file.content.version_committer(version1).should == @user.user_key
398
333
 
399
- # other user uploads new version
334
+ # other user uploads new version
400
335
  # TODO this should be a separate test
401
336
  archivist = FactoryGirl.find_or_create(:archivist)
402
337
  controller.stub(:current_user).and_return(archivist)
@@ -454,7 +389,7 @@ describe GenericFilesController do
454
389
  end
455
390
  it "should spawn a virus check" do
456
391
  # The expectation is in the begin block
457
- controller.should_receive(:virus_check).and_return(0)
392
+ Sufia::GenericFile::Actions.should_receive(:virus_check).and_return(0)
458
393
  s1 = double('one')
459
394
  ContentNewVersionEventJob.should_receive(:new).with(@generic_file.pid, 'jilluser@example.com').and_return(s1)
460
395
  Sufia.queue.should_receive(:push).with(s1).once
@@ -17,32 +17,28 @@ describe MailboxController do
17
17
  end
18
18
  describe "#index" do
19
19
  it "should show message" do
20
- User.any_instance.should_receive(:mark_as_read)
21
20
  get :index
22
21
  response.should be_success
23
22
  assigns[:messages].first.last_message.body.should == 'Test Message'
24
23
  assigns[:messages].first.last_message.subject.should == 'Test Subject'
24
+ @user.mailbox.inbox(:unread => true).count.should == 0
25
25
  end
26
26
  end
27
27
  describe "#delete" do
28
28
  it "should delete message" do
29
29
  rec = @another_user.send_message(@user, 'message 2', 'subject 2')
30
- @user.mailbox.inbox.count.should == 2
31
- get :index
32
- assigns[:messages].first.last_message.body.should == 'message 2'
33
- get :delete, :uid=> rec.conversation.id
34
- response.should redirect_to(@routes.url_helpers.mailbox_path)
35
- @user.mailbox.inbox.count.should ==1
30
+ expect {
31
+ delete :destroy, :id=> rec.conversation.id
32
+ response.should redirect_to(@routes.url_helpers.notifications_path)
33
+ }.to change {@user.mailbox.inbox.count}.by(-1)
36
34
  end
37
35
  it "should not delete message" do
38
36
  @curator = FactoryGirl.find_or_create(:curator)
39
37
  rec = @another_user.send_message(@curator, 'message 3', 'subject 3')
40
- @curator.mailbox.inbox.count.should == 1
41
- get :delete, :uid=> rec.conversation.id
42
- response.should redirect_to(@routes.url_helpers.mailbox_path)
43
- @curator.mailbox.inbox.count.should ==1
44
- rec.delete
45
- @curator.delete
38
+ expect {
39
+ delete :destroy, :id=> rec.conversation.id
40
+ response.should redirect_to(@routes.url_helpers.notifications_path)
41
+ }.to_not change { @curator.mailbox.inbox.count}
46
42
  end
47
43
  end
48
44
  describe "#delete_all" do
@@ -3,9 +3,6 @@ require 'spec_helper'
3
3
  describe "User Profile" do
4
4
 
5
5
  before do
6
- # FactoryGirl.create(:user)
7
- # FactoryGirl.create(:archivist)
8
- # FactoryGirl.create(:curator)
9
6
  sign_in :curator
10
7
  end
11
8
 
@@ -15,7 +15,7 @@ describe ImportUrlJob do
15
15
  generic_file.destroy
16
16
  end
17
17
 
18
- subject { ImportUrlJob.new(generic_file.id) }
18
+ subject(:job) { ImportUrlJob.new(generic_file.id) }
19
19
 
20
20
  it "should have no content at the outset" do
21
21
  generic_file.content.size.should be_nil
@@ -23,23 +23,23 @@ describe ImportUrlJob do
23
23
 
24
24
  it "should create a content datastream" do
25
25
  http_res = double('response')
26
+ http_res.stub(:start).and_yield
26
27
  http_res.stub(:read_body).and_yield(File.open(File.expand_path('../../fixtures/world.png', __FILE__)).read)
27
28
  Net::HTTP.any_instance.stub(:request_get).and_yield(http_res)
28
29
  Net::HTTP.any_instance.should_receive(:request_get).with(URI(generic_file.import_url).request_uri)
29
- subject.run
30
+ job.run
30
31
  generic_file.reload.content.size.should == 4218
31
32
  end
32
33
 
33
34
  describe "virus checking" do
34
35
  it "should run virus check" do
35
- Sufia::GenericFile::Actions.should_receive(:virus_check).and_return(0)
36
- Sufia::GenericFile::Actions.should_receive(:create_content).once
37
- subject.run
36
+ expect(Sufia::GenericFile::Actions).to receive(:virus_check).twice.and_return(0)
37
+ job.run
38
38
  end
39
39
  it "should abort if virus check fails" do
40
- Sufia::GenericFile::Actions.should_receive(:virus_check).and_return(1)
41
- User.any_instance.should_receive(:send_message).with(user, 'The file (world.png) was unable to be imported because it contained a virus.', 'File Import Error')
42
- subject.run
40
+ Sufia::GenericFile::Actions.stub(:virus_check).and_raise(Sufia::VirusFoundError.new('A virus was found'))
41
+ job.run
42
+ expect(user.mailbox.inbox.first.subject).to eq("File Import Error")
43
43
  end
44
44
  end
45
45
  end
@@ -3,33 +3,36 @@ require 'spec_helper'
3
3
  describe IngestLocalFileJob do
4
4
  let(:user) { FactoryGirl.find_or_create(:user) }
5
5
 
6
- let (:generic_file) do
7
- GenericFile.new.tap { |f| f.apply_depositor_metadata(user); f.save }
8
- end
6
+ let (:generic_file) do
7
+ GenericFile.new.tap { |f| f.apply_depositor_metadata(user); f.save }
8
+ end
9
+
10
+ subject(:job) { IngestLocalFileJob.new(generic_file.id, @mock_upload_directory, "world.png", user.user_key) }
9
11
 
10
12
  before do
11
13
  @mock_upload_directory = 'spec/mock_upload_directory'
12
14
  Dir.mkdir @mock_upload_directory unless File.exists? @mock_upload_directory
13
15
  FileUtils.copy(File.expand_path('../../fixtures/world.png', __FILE__), @mock_upload_directory)
14
16
  end
17
+
15
18
  after do
16
19
  generic_file.destroy
17
20
  end
18
- subject { IngestLocalFileJob.new(generic_file.id, @mock_upload_directory, "world.png", user.user_key) }
19
21
 
20
22
  it "should have attached a file" do
21
- subject.run
23
+ job.run
22
24
  generic_file.reload.content.size.should == 4218
23
25
  end
24
-
26
+
25
27
  describe "virus checking" do
26
28
  it "should run virus check" do
27
- Sufia::GenericFile::Actions.should_receive(:virus_check).and_return(0)
28
- subject.run
29
+ expect(Sufia::GenericFile::Actions).to receive(:virus_check).twice.and_return(0)
30
+ job.run
29
31
  end
30
32
  it "should abort if virus check fails" do
31
- Sufia::GenericFile::Actions.should_receive(:virus_check).and_return(1)
32
- expect { subject.run }.to raise_error(StandardError, /Virus checking did not pass/)
33
+ Sufia::GenericFile::Actions.stub(:virus_check).and_raise(Sufia::VirusFoundError.new('A virus was found'))
34
+ job.run
35
+ expect(user.mailbox.inbox.first.subject).to eq("Local file ingest error")
33
36
  end
34
37
  end
35
38
  end
@@ -1,28 +1,79 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe FitsDatastream, :unless => $in_travis do
4
- before(:all) do
5
- @file = GenericFile.new
6
- @file.add_file(File.open(fixture_path + '/world.png'), 'content', 'world.png')
7
- @file.characterize
4
+ describe "image" do
5
+ before(:all) do
6
+ @file = GenericFile.new
7
+ @file.add_file(File.open(fixture_path + '/world.png'), 'content', 'world.png')
8
+ @file.characterize
9
+ end
10
+ it "should have a format label" do
11
+ @file.format_label.should == ["Portable Network Graphics"]
12
+ end
13
+ it "should have a mime type" do
14
+ @file.mime_type.should == "image/png"
15
+ end
16
+ it "should have a file size" do
17
+ @file.file_size.should == ["4218"]
18
+ end
19
+ it "should have a file size" do
20
+ @file.file_size.should == ["4218"]
21
+ end
22
+ it "should have a last modified timestamp" do
23
+ @file.last_modified.should_not be_empty
24
+ end
25
+ it "should have a filename" do
26
+ @file.filename.should_not be_empty
27
+ end
28
+ it "should have a checksum" do
29
+ @file.original_checksum.should == ["28da6259ae5707c68708192a40b3e85c"]
30
+ end
31
+ it "should have a height" do
32
+ @file.height.should == ["50"]
33
+ end
34
+ it "should have a width" do
35
+ @file.width.should == ["50"]
36
+ end
8
37
  end
9
- it "should have a format label" do
10
- @file.format_label.should == ["Portable Network Graphics"]
11
- end
12
- it "should have a mime type" do
13
- @file.mime_type.should == "image/png"
14
- end
15
- it "should have a file size" do
16
- @file.file_size.should == ["4218"]
17
- end
18
- it "should have a last modified timestamp" do
19
- @file.last_modified.should_not be_empty
20
- end
21
- it "should have a filename" do
22
- @file.filename.should_not be_empty
23
- end
24
- it "should have a checksum" do
25
- @file.original_checksum.should == ["28da6259ae5707c68708192a40b3e85c"]
38
+ describe "video" do
39
+ before(:all) do
40
+ @file = GenericFile.new
41
+ @file.add_file(File.open(fixture_path + '/sample_mpeg4.mp4'), 'content', 'sample_mpeg4.mp4')
42
+ @file.characterize
43
+ end
44
+ it "should have a format label" do
45
+ @file.format_label.should == ["ISO Media, MPEG v4 system, version 2"]
46
+ end
47
+ it "should have a mime type" do
48
+ @file.mime_type.should == "video/mp4"
49
+ end
50
+ it "should have a file size" do
51
+ @file.file_size.should == ["245779"]
52
+ end
53
+ it "should have a last modified timestamp" do
54
+ @file.last_modified.should_not be_empty
55
+ end
56
+ it "should have a filename" do
57
+ @file.filename.should_not be_empty
58
+ end
59
+ it "should have a checksum" do
60
+ @file.original_checksum.should == ["dc77a8de8c091c19d86df74280f6feb7"]
61
+ end
62
+ it "should have a width" do
63
+ @file.width.should == ["190"]
64
+ end
65
+ it "should have a height" do
66
+ @file.height.should == ["240"]
67
+ end
68
+ it "should have a sample_rate" do
69
+ @file.sample_rate.should == ["32000"]
70
+ end
71
+ it "should have a duration" do
72
+ @file.duration.should == ["4.97 s"]
73
+ end
74
+ it "should have a frame_rate" do
75
+ @file.frame_rate.should == ["30"]
76
+ end
26
77
  end
27
78
  end
28
79
 
@@ -1,25 +1,10 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe GenericFile do
4
-
5
4
  describe "#virus_check" do
6
- before do
7
- unless defined? ClamAV
8
- class ClamAV
9
- def self.instance
10
- new
11
- end
12
- end
13
- @stubbed_clamav = true
14
- end
15
- end
16
- after do
17
- Object.send(:remove_const, :ClamAV) if @stubbed_clamav
18
- end
19
5
  it "should return the results of running ClamAV scanfile method" do
20
- # subject.stub(:to_solr).and_return({})
21
- ClamAV.any_instance.should_receive(:scanfile).and_return(1)
22
- Sufia::GenericFile::Actions.virus_check(File.new(fixture_path + '/world.png')).should == 1
6
+ ClamAV.instance.should_receive(:scanfile).and_return(1)
7
+ expect { Sufia::GenericFile::Actions.virus_check(File.new(fixture_path + '/world.png')) }.to raise_error(Sufia::VirusFoundError)
23
8
  end
24
9
  end
25
10
  end