]> source.dussan.org Git - redmine.git/commitdiff
Don't force download of PDF (#22483).
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Mon, 9 May 2016 17:22:23 +0000 (17:22 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Mon, 9 May 2016 17:22:23 +0000 (17:22 +0000)
Patch by Gregor Schmidt.

git-svn-id: http://svn.redmine.org/redmine/trunk@15409 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/controllers/attachments_controller.rb
app/controllers/repositories_controller.rb
app/models/attachment.rb

index 14025cb86c83da349f5562ef0df0c27d1bd62b5b..ea45397ef530df8547265cb7163cf4beefc68d27 100644 (file)
@@ -59,7 +59,7 @@ class AttachmentsController < ApplicationController
       # images are sent inline
       send_file @attachment.diskfile, :filename => filename_for_content_disposition(@attachment.filename),
                                       :type => detect_content_type(@attachment),
-                                      :disposition => (@attachment.image? ? 'inline' : 'attachment')
+                                      :disposition => disposition(@attachment)
     end
   end
 
@@ -191,4 +191,12 @@ class AttachmentsController < ApplicationController
     end
     content_type.to_s
   end
+
+  def disposition(attachment)
+    if attachment.is_image? || attachment.is_pdf?
+      'inline'
+    else
+      'attachment'
+    end
+  end
 end
index 9c39ad0758a4e23fac4c1a2dceae96f2c01bf4f2..c963ee00fdcfb0d173854363d477446eb898c0aa 100644 (file)
@@ -173,7 +173,7 @@ class RepositoriesController < ApplicationController
       send_opt = { :filename => filename_for_content_disposition(@path.split('/').last) }
       send_type = Redmine::MimeType.of(@path)
       send_opt[:type] = send_type.to_s if send_type
-      send_opt[:disposition] = (Redmine::MimeType.is_type?('image', @path) ? 'inline' : 'attachment')
+      send_opt[:disposition] = disposition(@path)
       send_data @repository.cat(@path, @rev), send_opt
     else
       if !@entry.size || @entry.size <= Setting.file_max_size_displayed.to_i.kilobyte
@@ -441,4 +441,12 @@ class RepositoriesController < ApplicationController
     )
     graph.burn
   end
+
+  def disposition(path)
+    if Redmine::MimeType.is_type?('image', @path) || Redmine::MimeType.of(@path) == "application/pdf"
+      'inline'
+    else
+      'attachment'
+    end
+  end
 end
index 7d577dc18262acd9c1180adf76739f4333b7003c..4bc674f8d752dba91a95ebd300b6c45b89baa3ac 100644 (file)
@@ -245,6 +245,10 @@ class Attachment < ActiveRecord::Base
     self.filename =~ /\.(patch|diff)$/i
   end
 
+  def is_pdf?
+    Redmine::MimeType.of(filename) == "application/pdf"
+  end
+
   # Returns true if the file is readable
   def readable?
     File.readable?(diskfile)