[ARVADOS] created: 12540bb0c62e2a498a70f64198055f1d48deeb17

git at public.curoverse.com git at public.curoverse.com
Tue Mar 17 19:35:11 EDT 2015


        at  12540bb0c62e2a498a70f64198055f1d48deeb17 (commit)


commit 12540bb0c62e2a498a70f64198055f1d48deeb17
Author: Radhika Chippada <radhika at curoverse.com>
Date:   Tue Mar 17 19:34:21 2015 -0400

    5375: add some of the mime types not supported by mime_types gem to mime_types.rb initializer.

diff --git a/apps/workbench/app/helpers/collections_helper.rb b/apps/workbench/app/helpers/collections_helper.rb
index 23a440a..f310265 100644
--- a/apps/workbench/app/helpers/collections_helper.rb
+++ b/apps/workbench/app/helpers/collections_helper.rb
@@ -53,4 +53,23 @@ module CollectionsHelper
     f0 += '/' if not f0.empty?
     file_path = "#{f0}#{file[1]}"
   end
+
+
+  ##
+  # Check if collection preview is allowed for the given filename with extension
+  #
+  def preview_allowed_for file_name
+    file_type = MIME::Types.type_for(file_name).first
+
+    if file_type.nil?
+      false
+    elsif (file_type.raw_media_type == "text") || (file_type.raw_media_type == "image")
+      true
+    elsif (file_type.raw_media_type == "application") &&
+          (Rails.configuration.filename_suffixes_with_view_icon.include? ((file_name.split('.')[-1]).downcase))
+      true
+    else
+      false
+    end
+  end
 end
diff --git a/apps/workbench/app/views/collections/_show_files.html.erb b/apps/workbench/app/views/collections/_show_files.html.erb
index 02ac2ee..8dcef33 100644
--- a/apps/workbench/app/views/collections/_show_files.html.erb
+++ b/apps/workbench/app/views/collections/_show_files.html.erb
@@ -73,10 +73,9 @@ function unselect_all_files() {
          <div class="collection_files_row filterable <%=preview_selectable%>" href="<%=@object.uuid%>/<%=file_path%>">
           <div class="collection_files_buttons pull-right">
             <%= raw(human_readable_bytes_html(size)) %>
-            <% disable_search = (Rails.configuration.filename_suffixes_with_view_icon.include? file_path.split('.')[-1]) ? false : true %>
             <%= link_to(raw('<i class="fa fa-search"></i>'),
                         link_params.merge(disposition: 'inline'),
-                        {title: "View #{file_path}", class: "btn btn-info btn-sm", disabled: disable_search}) %>
+                        {title: "View #{file_path}", class: "btn btn-info btn-sm", disabled: !preview_allowed_for(file_path)}) %>
             <%= link_to(raw('<i class="fa fa-download"></i>'),
                         link_params.merge(disposition: 'attachment'),
                         {title: "Download #{file_path}", class: "btn btn-info btn-sm"}) %>
diff --git a/apps/workbench/config/application.default.yml b/apps/workbench/config/application.default.yml
index 8be89b8..716978f 100644
--- a/apps/workbench/config/application.default.yml
+++ b/apps/workbench/config/application.default.yml
@@ -188,8 +188,11 @@ common:
   # generic issue email from
   email_from: arvados at example.com
 
-  # filename suffixes for which view icon would be shown in collection show page
-  filename_suffixes_with_view_icon: [txt, gif, jpeg, jpg, png, html, htm, pdf]
+  # Filename suffixes of applications for which the
+  # view icon would be shown in collection show page.
+  # It is sufficient to list only applications here.
+  # No need to list text and image types. 
+  filename_suffixes_with_view_icon: [fa, fasta, go, json, pdf, py, r, sam, sh, xml, xsl]
 
   # the maximum number of bytes to load in the log viewer
   log_viewer_max_bytes: 1000000
diff --git a/apps/workbench/config/initializers/mime_types.rb b/apps/workbench/config/initializers/mime_types.rb
index 72aca7e..ef95f43 100644
--- a/apps/workbench/config/initializers/mime_types.rb
+++ b/apps/workbench/config/initializers/mime_types.rb
@@ -3,3 +3,19 @@
 # Add new mime types for use in respond_to blocks:
 # Mime::Type.register "text/richtext", :rtf
 # Mime::Type.register_alias "text/html", :iphone
+
+# add new mime types to register
+Mime::Type.register "application/fa", :fa
+Mime::Type.register "application/fasta", :fasta
+Mime::Type.register "application/go", :go
+Mime::Type.register "application/r", :r
+Mime::Type.register "application/sam", :sam
+
+# register MIME type with MIME::Type gem 
+require 'mime/types'
+include MIME
+MIME::Types.add(MIME::Type.from_array("application/fa", %(fa)))
+MIME::Types.add(MIME::Type.from_array("application/fasta", %(fasta)))
+MIME::Types.add(MIME::Type.from_array("application/go", %(go)))
+MIME::Types.add(MIME::Type.from_array("application/r", %(r)))
+MIME::Types.add(MIME::Type.from_array("application/sam", %(sam)))
diff --git a/apps/workbench/test/unit/collection_test.rb b/apps/workbench/test/unit/collection_test.rb
index e71f966..4185909 100644
--- a/apps/workbench/test/unit/collection_test.rb
+++ b/apps/workbench/test/unit/collection_test.rb
@@ -1,6 +1,8 @@
 require 'test_helper'
 
 class CollectionTest < ActiveSupport::TestCase
+  include CollectionsHelper
+
   test 'recognize empty blob locator' do
     ['d41d8cd98f00b204e9800998ecf8427e+0',
      'd41d8cd98f00b204e9800998ecf8427e',
@@ -71,4 +73,34 @@ class CollectionTest < ActiveSupport::TestCase
              .attribute_editable?("name"),
            "project viewer allowed to edit collection name")
   end
+
+  [
+    ["filename.csv", true],
+    ["filename.fa", true],
+    ["filename.fasta", true],
+    ["filename.go", true],
+    ["filename.htm", true],
+    ["filename.html", true],
+    ["filename.json", true],
+    ["filename.md", true],
+    ["filename.pdf", true],
+    ["filename.py", true],
+    ["filename.R", true],
+    ["filename.sam", true],
+    ["filename.sh", true],
+    ["filename.txt", true],
+    ["filename.tiff", true],
+    ["filename.tsv", true],
+    ["filename.vcf", true],
+    ["filename.xml", true],
+    ["filename.xsl", true],
+    ["filename.yml", true],
+
+    ["filename.bam", false],
+    ["filename", false],
+  ].each do |file_name, preview_allowed|
+    test "verify '#{file_name}' is allowed for preview #{preview_allowed}" do
+      assert_equal preview_allowed, preview_allowed_for(file_name)
+    end
+  end
 end

-----------------------------------------------------------------------


hooks/post-receive
-- 




More information about the arvados-commits mailing list