sufia 3.4.0 → 3.5.0

Sign up to get free protection for your applications and to get access to all the features.
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
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b325d0460fd902145ca8b8c197ea822e271d7182
4
- data.tar.gz: 6cb9cb9a2b1c4838a16ee2cc5dd4526fb918fc7d
3
+ metadata.gz: 77cd255a8ab67cb2bcbd0bbfe17a9920d853251b
4
+ data.tar.gz: 528e7ca2aeb61cf7bcf5b10e370fcbfd8a51a1fc
5
5
  SHA512:
6
- metadata.gz: 02ba6513e673044b55e11a6dbaa68cb83cde5b3e3381c9c75dc86dd2bd21cdb0b709f35904befcb4a8a3fa6485d3081d4028b0480489fdceb3b5ae55a1d19ec0
7
- data.tar.gz: b7be173445501e70cf190ba23e2965ed3fac991ac5ca4f07a0e339692ce1ef58c7de4edf549788a95d461f32a5fa2a68afbe134518a77c8839a6ff4042dd3669
6
+ metadata.gz: acc4acc8293673da4aba37329ab6321be93241c9dfd2fd712a4bf5a3cf7218bfe25d5d6d8a99b1a45eb91934903dc31caacce9d7aa8311ebdfa9965075c5df4e
7
+ data.tar.gz: 656b6f49ed4a1a4a603cae1b40a3c9320ac42a3aa4e806ba228439442ba87168fa8e0ed2b60e7957014b9297d1221ca9e97ad77605379402f2ffa472af2f816b
@@ -1,7 +1,12 @@
1
1
  language: ruby
2
+ before_install:
3
+ - sudo apt-get install libclamav-dev clamav-data
2
4
  rvm:
3
5
  - "1.9.3"
4
6
  - "2.0.0"
7
+ env:
8
+ global:
9
+ - NOKOGIRI_USE_SYSTEM_LIBRARIES=true
5
10
  notifications:
6
11
  email:
7
12
  recipients:
@@ -16,4 +21,4 @@ notifications:
16
21
  template:
17
22
  - "%{repository}//%{branch}@%{commit} by %{author}: %{message} - %{build_url}"
18
23
  services:
19
- - redis-server
24
+ - redis-server
data/Gemfile CHANGED
@@ -8,18 +8,17 @@ gem 'kaminari', github: 'harai/kaminari', branch: 'route_prefix_prototype'
8
8
  gem 'sufia-models', path: './sufia-models'
9
9
 
10
10
  group :development, :test do
11
+ gem 'devise'
12
+ # gem 'byebug'
13
+ gem 'clamav'
11
14
  gem 'sqlite3'
12
- gem 'selenium-webdriver'
13
- gem 'rspec-rails', '~> 2.14'
14
- gem 'launchy'
15
- gem 'database_cleaner'
16
- gem 'capybara', '~>2.1.0'
17
- gem 'bcrypt-ruby'
15
+ gem 'rspec-rails'
16
+ gem 'launchy' unless ENV['TRAVIS']
17
+ gem 'capybara'
18
18
  gem "jettywrapper"
19
- gem "factory_girl_rails", "~> 4.2.1"
19
+ gem "factory_girl_rails"
20
20
  gem "devise"
21
21
  gem 'jquery-rails'
22
- gem 'sass-rails'
23
22
  gem 'turbolinks'
24
23
  gem "bootstrap-sass"
25
24
  gem "simplecov", :require => false
data/README.md CHANGED
@@ -146,3 +146,16 @@ rake fixtures
146
146
  rake clean spec
147
147
  bundle exec cucumber features
148
148
  ```
149
+ ### Change validation behavior
150
+
151
+ To change what happens to files that fail validation add an after_validation hook
152
+ ```
153
+ after_validation :dump_infected_files
154
+
155
+ def dump_infected_files
156
+ if Array(errors.get(:content)).any? { |msg| msg =~ /A virus was found/ }
157
+ content.content = errors.get(:content)
158
+ save
159
+ end
160
+ end
161
+ ```
@@ -1 +1 @@
1
- 3.4.0
1
+ 3.5.0
@@ -4,7 +4,7 @@ class MailboxController < ApplicationController
4
4
  def index
5
5
  if user_signed_in?
6
6
  @messages = current_user.mailbox.inbox
7
- current_user.mark_as_read @messages
7
+ @messages.each{|m| m.mark_as_read(current_user)}
8
8
  else
9
9
  @messages =[]
10
10
  end
@@ -15,20 +15,20 @@ class MailboxController < ApplicationController
15
15
  delete_message(msg)
16
16
  end
17
17
  empty_trash(current_user)
18
- redirect_to sufia.mailbox_path
18
+ redirect_to sufia.notifications_path
19
19
  end
20
20
 
21
- def delete
22
- if (current_user)
23
- msg = Conversation.find(params[:uid])
21
+ def destroy
22
+ if current_user
23
+ msg = Conversation.find(params[:id])
24
24
  if (msg.participants[0] == current_user) || (msg.participants[1] == current_user)
25
25
  delete_message(msg)
26
26
  empty_trash(msg.participants[0])
27
27
  end
28
- else
28
+ else
29
29
  flash[:alert] = "You do not have privileges to delete the notification..."
30
- end
31
- redirect_to sufia.mailbox_path
30
+ end
31
+ redirect_to sufia.notifications_path
32
32
  end
33
33
 
34
34
  private
@@ -1,34 +1,38 @@
1
1
  class IngestLocalFileJob
2
+ attr_accessor :directory, :filename, :user_key, :generic_file_id
3
+
2
4
  def queue_name
3
5
  :ingest
4
6
  end
5
7
 
6
- attr_accessor :directory, :filename, :user_key, :generic_file_id
7
-
8
8
  def initialize(generic_file_id, directory, filename, user_key)
9
9
  self.generic_file_id = generic_file_id
10
10
  self.directory = directory
11
- self.filename = filename
11
+ self.filename = filename
12
12
  self.user_key = user_key
13
13
  end
14
14
 
15
15
  def run
16
- filedata = File.new( File.join(directory, filename) )
17
- generic_file = GenericFile.find(generic_file_id)
18
16
  user = User.find_by_user_key(user_key)
19
17
  raise "Unable to find user for #{user_key}" unless user
20
-
21
- # virus check
22
- virus_stat = Sufia::GenericFile::Actions.virus_check(filedata)
23
- raise "Virus checking did not pass for #{File.basename(filedata.path)} status = #{virus_stat}" unless virus_stat == 0
24
-
18
+ generic_file = GenericFile.find(generic_file_id)
19
+ path = File.join(directory, filename)
20
+
25
21
  generic_file.label = File.basename(filename)
26
- generic_file.add_file(File.open(File.join(directory, filename)), 'content', generic_file.label)
22
+ generic_file.add_file(File.open(path), 'content', generic_file.label)
27
23
  generic_file.record_version_committer(user)
28
24
  generic_file.save!
29
25
 
30
- #Sufia.queue.push(UnzipJob.new(generic_file.pid)) if generic_file.content.mimeType == 'application/zip'
26
+ FileUtils.rm(path)
31
27
  Sufia.queue.push(ContentDepositEventJob.new(generic_file.pid, user_key))
32
- FileUtils.rm([File.join(directory, filename)])
28
+ # add message to user for downloaded file
29
+ message = "The file (#{File.basename(filename)}) was successfully deposited."
30
+ job_user.send_message(user, message, 'Local file ingest')
31
+ rescue => error
32
+ job_user.send_message(user, error.message, 'Local file ingest error')
33
+ end
34
+
35
+ def job_user
36
+ User.batchuser
33
37
  end
34
38
  end
@@ -1,6 +1,3 @@
1
- <!--<h1>Getting Started</h1>
2
- <img src="/assets/splashscreen.png" width="450" height="259" alt="just a place holder" />
3
- <br/><br/> -->
4
1
  <h2 class="heading1">What is <%=t('sufia.product_name') %>?</h2>
5
2
  <p>
6
3
  <%=t('sufia.product_name') %> is a secure repository service enabling the <%=t('sufia.institution_name') %> community to share its research and scholarly work with a worldwide audience.
@@ -1,31 +1,7 @@
1
- <%#
2
- Copyright © 2012 The Pennsylvania State University
3
-
4
- Licensed under the Apache License, Version 2.0 (the "License");
5
- you may not use this file except in compliance with the License.
6
- You may obtain a copy of the License at
7
-
8
- http://www.apache.org/licenses/LICENSE-2.0
9
-
10
- Unless required by applicable law or agreed to in writing, software
11
- distributed under the License is distributed on an "AS IS" BASIS,
12
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- See the License for the specific language governing permissions and
14
- limitations under the License.
15
- %>
16
-
17
- <%- height = 42 if height.blank? -%>
18
- <%- width = 36 if width.blank? -%>
19
- <% if (document.mime_type) %>
20
- <% if document.image? %>
21
- <%= link_to image_tag(sufia.download_path(document["id"], {:datastream_id => 'thumbnail'}), {:width=>width}), sufia.generic_file_path(document.noid) %>
22
- <% elsif document.pdf? %>
23
- <%= link_to image_tag(sufia.download_path(document["id"], {:datastream_id => 'thumbnail'}), {:width=>width}),sufia.generic_file_path(document.noid) %>
24
- <% elsif document.video? %>
25
- <%= link_to image_tag(sufia.download_path(document["id"], {:datastream_id => 'thumbnail'}), {:width=>width}),sufia.generic_file_path(document.noid) %>
26
- <% else %>
27
- <%= link_to image_tag("/assets/default.png", {:width=>width}), sufia.generic_file_path(document) %>
28
- <% end %>
1
+ <% width = 36 if width.blank? %>
2
+ <% if document.image? || document.pdf? || document.video? %>
3
+ <% path = sufia.download_path(document["id"], {datastream_id: 'thumbnail'}) %>
29
4
  <% else %>
30
- <%= link_to image_tag("/assets/default.png", {:width=>width}), sufia.generic_file_path(document) %>
5
+ <% path = "/assets/default.png" %>
31
6
  <% end %>
7
+ <%= link_to image_tag(path, {width: width}), sufia.generic_file_path(document) %>
@@ -1,21 +1,7 @@
1
- <%#
2
- Copyright © 2012 The Pennsylvania State University
3
-
4
- Licensed under the Apache License, Version 2.0 (the "License");
5
- you may not use this file except in compliance with the License.
6
- You may obtain a copy of the License at
7
-
8
- http://www.apache.org/licenses/LICENSE-2.0
9
-
10
- Unless required by applicable law or agreed to in writing, software
11
- distributed under the License is distributed on an "AS IS" BASIS,
12
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- See the License for the specific language governing permissions and
14
- limitations under the License.
15
- %>
16
-
17
1
  <h1>User Notifications</h1>
18
- <a href="<%= sufia.mailbox_delete_all_path %>" class="btn " title="click delete all User Notifications"><i class="icon-trash">&nbsp;</i>Delete All</a>
2
+ <%= link_to raw('<i class="icon-trash icon-large">&nbsp;</i>Delete All'),
3
+ sufia.delete_all_notifications_path, method: :delete, class: 'btn',
4
+ title: 'Delete all user notifications' %>
19
5
  <div id="Data">
20
6
  <table class="table table-striped">
21
7
  <thead>
@@ -27,10 +13,12 @@ limitations under the License.
27
13
  <tbody>
28
14
  <% @messages.each do |msg| %>
29
15
  <tr class="<%= cycle("","zebra") %>">
30
- <td ><%= msg.last_message.subject.html_safe %></td>
31
- <td ><%= msg.last_message.body.html_safe %></td>
32
- <td> <%= link_to raw('<i class="icon-trash icon-large"></i>'), sufia.mailbox_delete_path(msg.id), :class=> 'itemicon itemtrash', :title => 'Delete File', :method => :delete %>&nbsp;&nbsp;&nbsp;</td>
33
-
16
+ <td><%= msg.last_message.subject.html_safe %></td>
17
+ <td><%= msg.last_message.body.html_safe %></td>
18
+ <td><%= link_to raw('<i class="icon-trash icon-large"></i>'),
19
+ sufia.notification_path(msg.id), :class=> 'itemicon itemtrash',
20
+ :title => 'Delete File', :method => :delete %>
21
+ </td>
34
22
  </tr>
35
23
  <% end %>
36
24
  </tbody>
@@ -1,21 +1,6 @@
1
- <%#
2
- Copyright © 2012 The Pennsylvania State University
3
-
4
- Licensed under the Apache License, Version 2.0 (the "License");
5
- you may not use this file except in compliance with the License.
6
- You may obtain a copy of the License at
7
-
8
- http://www.apache.org/licenses/LICENSE-2.0
9
-
10
- Unless required by applicable law or agreed to in writing, software
11
- distributed under the License is distributed on an "AS IS" BASIS,
12
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- See the License for the specific language governing permissions and
14
- limitations under the License.
15
- %>
16
- <a id="notify_link" href="<%= sufia.mailbox_path %>" class="icon-btn btn btn-small" title="click for User Notifications">
1
+ <%= link_to sufia.notifications_path, id: "notify_link", class: "icon-btn btn btn-small", title: "User Notifications" do %>
17
2
  <%= render :partial => 'users/notify_number' %>
18
- </a>
3
+ <% end %>
19
4
  <div class='hide'>
20
5
  <%= link_to "notify", sufia.user_notify_path, :remote => true, :id => 'notify_update_link' %>
21
6
  </div>
@@ -27,9 +27,11 @@ Sufia::Engine.routes.draw do
27
27
  resources :downloads, :only => "show"
28
28
 
29
29
  # Messages
30
- get 'notifications' => 'mailbox#index', :as => :mailbox
31
- match 'notifications/delete_all' => 'mailbox#delete_all', as: :mailbox_delete_all, via: [:get, :post]
32
- match 'notifications/:uid/delete' => 'mailbox#delete', as: :mailbox_delete, via: [:get, :post]
30
+ resources :notifications, only: [:destroy, :index], controller: :mailbox do
31
+ collection do
32
+ delete 'delete_all'
33
+ end
34
+ end
33
35
 
34
36
  # User profile & follows
35
37
  resources :users, only: [:index, :show, :edit, :update], as: :profiles
@@ -79,7 +79,7 @@ module Sufia
79
79
  def create_from_url(params)
80
80
  params[:dropbox_urls].each do |db_file|
81
81
  next if db_file.blank?
82
- # do not remove ::
82
+ # do not remove ::
83
83
  @generic_file = ::GenericFile.new
84
84
  @generic_file.import_url = db_file
85
85
  @generic_file.label = File.basename(db_file)
@@ -90,27 +90,25 @@ module Sufia
90
90
  end
91
91
 
92
92
  def create_from_upload(params)
93
- begin
94
- # check error condition No files
95
- return json_error("Error! No file to save") if !params.has_key?(:files)
96
-
97
- file = params[:files].detect {|f| f.respond_to?(:original_filename) }
98
- if !file
99
- json_error "Error! No file for upload", 'unknown file', :status => :unprocessable_entity
100
- elsif (empty_file?(file))
101
- json_error "Error! Zero Length File!", file.original_filename
102
- elsif (!terms_accepted?)
103
- json_error "You must accept the terms of service!", file.original_filename
104
- else
105
- process_file(file)
106
- end
107
- rescue => error
108
- logger.error "GenericFilesController::create rescued #{error.class}\n\t#{error.to_s}\n #{error.backtrace.join("\n")}\n\n"
109
- json_error "Error occurred while creating generic file."
110
- ensure
111
- # remove the tempfile (only if it is a temp file)
112
- file.tempfile.delete if file.respond_to?(:tempfile)
93
+ # check error condition No files
94
+ return json_error("Error! No file to save") if !params.has_key?(:files)
95
+
96
+ file = params[:files].detect {|f| f.respond_to?(:original_filename) }
97
+ if !file
98
+ json_error "Error! No file for upload", 'unknown file', :status => :unprocessable_entity
99
+ elsif (empty_file?(file))
100
+ json_error "Error! Zero Length File!", file.original_filename
101
+ elsif (!terms_accepted?)
102
+ json_error "You must accept the terms of service!", file.original_filename
103
+ else
104
+ process_file(file)
113
105
  end
106
+ rescue => error
107
+ logger.error "GenericFilesController::create rescued #{error.class}\n\t#{error.to_s}\n #{error.backtrace.join("\n")}\n\n"
108
+ json_error "Error occurred while creating generic file."
109
+ ensure
110
+ # remove the tempfile (only if it is a temp file)
111
+ file.tempfile.delete if file.respond_to?(:tempfile)
114
112
  end
115
113
 
116
114
  # routed to /files/:id/citation
@@ -145,10 +143,8 @@ module Sufia
145
143
 
146
144
  if params.has_key?(:filedata)
147
145
  file = params[:filedata]
148
- return unless virus_check(file) == 0
149
146
  @generic_file.add_file(file, datastream_id, file.original_filename)
150
147
  version_event = true
151
- Sufia.queue.push(ContentNewVersionEventJob.new(@generic_file.pid, current_user.user_key))
152
148
  end
153
149
 
154
150
  # only update metadata if there is a generic_file object which is not the case for version updates
@@ -157,12 +153,20 @@ module Sufia
157
153
  #always save the file so the new version or metadata gets recorded
158
154
  if @generic_file.save
159
155
  # do not trigger an update event if a version event has already been triggered
160
- Sufia.queue.push(ContentUpdateEventJob.new(@generic_file.pid, current_user.user_key)) unless version_event
156
+ if version_event
157
+ Sufia.queue.push(ContentNewVersionEventJob.new(@generic_file.pid, current_user.user_key)) if params.has_key?(:filedata)
158
+ else
159
+ Sufia.queue.push(ContentUpdateEventJob.new(@generic_file.pid, current_user.user_key))
160
+ end
161
161
  @generic_file.record_version_committer(current_user)
162
162
  redirect_to sufia.edit_generic_file_path(:tab => params[:redirect_tab]), :notice => render_to_string(:partial=>'generic_files/asset_updated_flash', :locals => { :generic_file => @generic_file })
163
163
  else
164
164
  render action: 'edit'
165
165
  end
166
+ rescue => error
167
+ flash[:error] = error.message
168
+ logger.error "GenericFilesController::update rescued #{error.class}\n\t#{error.message}\n #{error.backtrace.join("\n")}\n\n"
169
+ render action: 'edit'
166
170
  end
167
171
 
168
172
  protected
@@ -179,27 +183,26 @@ module Sufia
179
183
  end
180
184
 
181
185
  def process_file(file)
182
- if virus_check(file) == 0
183
- @generic_file = ::GenericFile.new
184
- update_metadata_from_upload_screen
185
- create_metadata(@generic_file)
186
- Sufia::GenericFile::Actions.create_content(@generic_file, file, file.original_filename, datastream_id, current_user)
187
- respond_to do |format|
188
- format.html {
189
- render :json => [@generic_file.to_jq_upload],
190
- :content_type => 'text/html',
191
- :layout => false
192
- }
193
- format.json {
194
- render :json => [@generic_file.to_jq_upload]
195
- }
196
- end
197
- else
198
- render :json => [{:error => "Error creating generic file."}]
186
+ @generic_file = ::GenericFile.new
187
+ update_metadata_from_upload_screen
188
+ create_metadata(@generic_file)
189
+ Sufia::GenericFile::Actions.create_content(@generic_file, file, file.original_filename, datastream_id, current_user)
190
+ respond_to do |format|
191
+ format.html {
192
+ render :json => [@generic_file.to_jq_upload],
193
+ :content_type => 'text/html',
194
+ :layout => false
195
+ }
196
+ format.json {
197
+ render :json => [@generic_file.to_jq_upload]
198
+ }
199
199
  end
200
+ rescue ActiveFedora::RecordInvalid => af
201
+ flash[:error] = af.message
202
+ json_error "Error creating generic file: #{af.message}"
200
203
  end
201
204
 
202
- # override this method if you want to change how the terms are accepted on upload.
205
+ # override this method if you want to change how the terms are accepted on upload.
203
206
  def terms_accepted?
204
207
  params[:terms_of_service] == '1'
205
208
  end
@@ -231,14 +234,6 @@ module Sufia
231
234
  @generic_file.date_modified = DateTime.now
232
235
  end
233
236
 
234
-
235
- def virus_check( file)
236
- stat = Sufia::GenericFile::Actions.virus_check(file)
237
- flash[:error] = "Virus checking did not pass for #{File.basename(file.path)} status = #{stat}" unless stat == 0
238
- stat
239
- end
240
-
241
-
242
237
  def create_metadata(file)
243
238
  Sufia::GenericFile::Actions.create_metadata(file, current_user, params[:batch_id])
244
239
  end
@@ -1,3 +1,3 @@
1
1
  module Sufia
2
- VERSION = "3.4.0"
2
+ VERSION = "3.5.0"
3
3
  end