Diff
Modified: branches/datasets/app/controllers/application.rb (2841 => 2842)
--- branches/datasets/app/controllers/application.rb 2011-11-24 10:29:15 UTC (rev 2841)
+++ branches/datasets/app/controllers/application.rb 2011-11-24 12:33:22 UTC (rev 2842)
@@ -1191,4 +1191,10 @@
end
end
+
+ #For sending zip files stored in Tempfile objects, ensures they are closed and can be garbage collected
+ def send_and_close(file, filename)
+ send_file file.path, :disposition => 'attachment', :filename => filename
+ file.close
+ end
end
Modified: branches/datasets/app/controllers/data_sets_controller.rb (2841 => 2842)
--- branches/datasets/app/controllers/data_sets_controller.rb 2011-11-24 10:29:15 UTC (rev 2841)
+++ branches/datasets/app/controllers/data_sets_controller.rb 2011-11-24 12:33:22 UTC (rev 2842)
@@ -50,7 +50,7 @@
end
def download
- send_file @data_set.create_zip(current_user), :disposition => 'attachment', :filename => @data_set.archive_file_name
+ send_and_close @data_set.create_zip(current_user), @data_set.archive_file_name
end
def new
Modified: branches/datasets/app/models/data_set.rb (2841 => 2842)
--- branches/datasets/app/models/data_set.rb 2011-11-24 10:29:15 UTC (rev 2841)
+++ branches/datasets/app/models/data_set.rb 2011-11-24 12:33:22 UTC (rev 2842)
@@ -24,8 +24,11 @@
#this association is just to ensure text data is deleted when the data set is. not actually used.
has_many :text_datas, :dependent => :destroy
- # Zips the pack up and returns the path to the zip file
+ # Zips the pack up and returns the file
def create_zip(user)
+ stats = {"input" => {:text => 0, :files => 0, :hidden => 0},
+ "output" => {:text => 0, :files => 0, :hidden => 0}}
+
#Create the zip file
file = new_zipfile(archive_file_name) do |zipfile|
#Add the data
@@ -33,19 +36,25 @@
data = ""
port = data_item.objekt
if data.kind_of?(Blob)
- zipfile.add_file("#{port.port_type}s/#{port.name} - #{data.local_name}", data.content_blob.data)
+ if Authorization.is_authorized?("download", nil, data, user)
+ zipfile.add_file("#{port.port_type}s/#{port.name} - #{data.local_name}", data.content_blob.data)
+ stats[port.port_type][:files] += 1
+ else
+ stats[port.port_type][:hidden] += 1
+ end
elsif data.kind_of?(TextData)
zipfile.add_file("#{port.port_type}s/#{port.name} - text.txt", data.data)
+ stats[port.port_type][:text] += 1
else
raise "Unsupported data type"
end
end
#Add metadata
- zipfile.add_file("_metadata.txt", self.metadata)
+ zipfile.add_file("_metadata.txt", self.metadata(stats))
end
- file.path
+ file
end
def archive_file_name(no_timestamp=false)
@@ -56,7 +65,7 @@
return filename
end
- def metadata
+ def metadata(stats)
"********** Snapshot of the data set: #{self.title} **********\r\n\r\n" +
"Downloaded from #{Conf.sitename}\r\n" +
@@ -70,6 +79,18 @@
"Workflow location: #{workflow_url(workflow)}\r\n" +
"Created by: #{self.contributor.label}\r\n" +
"Created at: #{self.created_at.strftime("%H:%M:%S on %A, %d %B %Y")}\r\n" +
- "Last updated at: #{self.updated_at.strftime("%H:%M:%S on %A, %d %B %Y")}\r\n"
+ "Last updated at: #{self.updated_at.strftime("%H:%M:%S on %A, %d %B %Y")}\r\n\r\n" +
+
+ "Summary of contents:\r\n" +
+ " Inputs:\r\n" +
+ " Text: #{stats["input"][:text]}\r\n" +
+ " Files: #{stats["input"][:text]}" +
+ (stats["input"][:hidden] > 0 ?
+ " (#{stats["input"][:hidden]} files were omitted due to insufficient privileges)\r\n" : "\r\n") +
+ " Outputs:\r\n" +
+ " Text: #{stats["output"][:text]}\r\n" +
+ " Files: #{stats["output"][:text]}" +
+ (stats["output"][:hidden] > 0 ?
+ " (#{stats["output"][:hidden]} files were omitted due to insufficient privileges)\r\n" : "\r\n")
end
end
Modified: branches/datasets/app/views/data_sets/show.rhtml (2841 => 2842)
--- branches/datasets/app/views/data_sets/show.rhtml 2011-11-24 10:29:15 UTC (rev 2841)
+++ branches/datasets/app/views/data_sets/show.rhtml 2011-11-24 12:33:22 UTC (rev 2842)
@@ -7,9 +7,11 @@
</div>
<div style="float: right; margin: 0.5em">
<ul class="sectionIcons">
- <li>
- <%= icon('download', download_workflow_data_set_path(@workflow, @data_set), nil, nil, 'Download data set') %>
- </li>
+ <% if Authorization.is_authorized?("download", nil, @workflow, current_user) %>
+ <li>
+ <%= icon('download', download_workflow_data_set_path(@workflow, @data_set), nil, nil, 'Download data set') %>
+ </li>
+ <% end %>
<% if mine?(@workflow) %>
<li>
<%= icon('edit', edit_workflow_data_set_path(@workflow, @data_set), nil, nil, 'Edit data set') %>
Modified: branches/datasets/lib/zip_in_memory.rb (2841 => 2842)
--- branches/datasets/lib/zip_in_memory.rb 2011-11-24 10:29:15 UTC (rev 2841)
+++ branches/datasets/lib/zip_in_memory.rb 2011-11-24 12:33:22 UTC (rev 2842)
@@ -5,7 +5,6 @@
# An easier way of making zip files without excessive use of the file system.
-# Doesn't require cleanup of temp files.
# Adapted from from:
# http://blog.devinterface.com/2010/02/create-zip-files-on-the-fly/