]> source.dussan.org Git - redmine.git/commitdiff
Merged r3258 and r3281 from trunk.
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Sat, 9 Jan 2010 10:02:16 +0000 (10:02 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Sat, 9 Jan 2010 10:02:16 +0000 (10:02 +0000)
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/branches/0.9-stable@3286 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/controllers/attachments_controller.rb
app/models/attachment.rb
lib/redmine/mime_type.rb
lib/tasks/migrate_from_trac.rake
test/functional/attachments_controller_test.rb
test/unit/attachment_test.rb

index 92d60ee0f5f1a07b0fcbe266abac779dbadacebf..5b2acc8ab7685e74848266fcb4f1506c1f556137 100644 (file)
@@ -41,7 +41,7 @@ class AttachmentsController < ApplicationController
     
     # images are sent inline
     send_file @attachment.diskfile, :filename => filename_for_content_disposition(@attachment.filename),
-                                    :type => @attachment.content_type
+                                    :type => detect_content_type(@attachment)
                                     :disposition => (@attachment.image? ? 'inline' : 'attachment')
    
   end
@@ -76,4 +76,12 @@ private
   def delete_authorize
     @attachment.deletable? ? true : deny_access
   end
+  
+  def detect_content_type(attachment)
+    content_type = attachment.content_type
+    if content_type.blank?
+      content_type = Redmine::MimeType.of(attachment.filename)
+    end
+    content_type.to_s
+  end
 end
index fe1d6afaa5fb9072b503792ad3cb4d0ff5241c27..e44b162adab2132b1918a68f9d307ef964d84a01 100644 (file)
@@ -58,6 +58,9 @@ class Attachment < ActiveRecord::Base
         self.filename = sanitize_filename(@temp_file.original_filename)
         self.disk_filename = Attachment.disk_filename(filename)
         self.content_type = @temp_file.content_type.to_s.chomp
+        if content_type.blank?
+          self.content_type = Redmine::MimeType.of(filename)
+        end
         self.filesize = @temp_file.size
       end
     end
index 69b0760b882d8cad56df46a5b329ccec6e17e5a4..c85ebdcb9e0e160cd400a5ced126f19024ffa78e 100644 (file)
@@ -1,5 +1,5 @@
-# redMine - project management software
-# Copyright (C) 2006-2007  Jean-Philippe Lang
+# Redmine - project management software
+# Copyright (C) 2006-2009  Jean-Philippe Lang
 #
 # This program is free software; you can redistribute it and/or
 # modify it under the terms of the GNU General Public License
@@ -36,6 +36,7 @@ module Redmine
       'text/x-sh' => 'sh',
       'text/xml' => 'xml,xsd,mxml',
       'text/yaml' => 'yml,yaml',
+      'text/csv' => 'csv',
       'image/gif' => 'gif',
       'image/jpeg' => 'jpg,jpeg,jpe',
       'image/png' => 'png',
@@ -43,6 +44,20 @@ module Redmine
       'image/x-ms-bmp' => 'bmp',
       'image/x-xpixmap' => 'xpm',
       'application/pdf' => 'pdf',
+      'application/rtf' => 'rtf',
+      'application/msword' => 'doc',
+      'application/vnd.ms-excel' => 'xls',
+      'application/vnd.ms-powerpoint' => 'ppt,pps',
+      'application/vnd.openxmlformats-officedocument.wordprocessingml.document' => 'docx',
+      'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' => 'xlsx',
+      'application/vnd.openxmlformats-officedocument.presentationml.presentation' => 'pptx',
+      'application/vnd.openxmlformats-officedocument.presentationml.slideshow' => 'ppsx',
+      'application/vnd.oasis.opendocument.spreadsheet' => 'ods',
+      'application/vnd.oasis.opendocument.text' => 'odt',
+      'application/vnd.oasis.opendocument.presentation' => 'odp',
+      'application/x-7z-compressed' => '7z',
+      'application/x-rar-compressed' => 'rar',
+      'application/x-tar' => 'tar',
       'application/zip' => 'zip',
       'application/x-gzip' => 'gz',
     }.freeze
index e267a340f2ef29644a9b2f2d87d255b05c0354aa..8c6838ae28eeebac3ff334c507a0aef78c36cc6a 100644 (file)
@@ -128,7 +128,7 @@ namespace :redmine do
         end
 
         def content_type
-          Redmine::MimeType.of(filename) || ''
+          ''
         end
 
         def exist?
index bf57349fe2426d72dee2c48b52fa845968e116cf..b64d9c51d48a361fc7887373fb481366c3727d2d 100644 (file)
@@ -84,6 +84,14 @@ class AttachmentsControllerTest < ActionController::TestCase
     assert_equal 'application/x-ruby', @response.content_type
   end
   
+  def test_download_should_assign_content_type_if_blank
+    Attachment.find(4).update_attribute(:content_type, '')
+    
+    get :download, :id => 4
+    assert_response :success
+    assert_equal 'text/x-ruby', @response.content_type
+  end
+  
   def test_download_missing_file
     get :download, :id => 2
     assert_response 404
index 7b289d5c8c035e8f3c2dcdc919fd95adfeda859d..8c25adb41f8c9ee88a9159041df327574ff3206e 100644 (file)
@@ -38,6 +38,14 @@ class AttachmentTest < ActiveSupport::TestCase
     assert File.exist?(a.diskfile)
   end
   
+  def test_create_should_auto_assign_content_type
+    a = Attachment.new(:container => Issue.find(1),
+                       :file => uploaded_test_file("testfile.txt", ""),
+                       :author => User.find(1))
+    assert a.save
+    assert_equal 'text/plain', a.content_type
+  end
+  
   def test_diskfilename
     assert Attachment.disk_filename("test_file.txt") =~ /^\d{12}_test_file.txt$/
     assert_equal 'test_file.txt', Attachment.disk_filename("test_file.txt")[13..-1]