From: Jean-Philippe Lang Date: Mon, 9 May 2016 17:22:23 +0000 (+0000) Subject: Don't force download of PDF (#22483). X-Git-Tag: 3.3.0~64 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=3e776af8066e478beb5d2bc9bd26e81d2bef2542;p=redmine.git Don't force download of PDF (#22483). Patch by Gregor Schmidt. git-svn-id: http://svn.redmine.org/redmine/trunk@15409 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- diff --git a/app/controllers/attachments_controller.rb b/app/controllers/attachments_controller.rb index 14025cb86..ea45397ef 100644 --- a/app/controllers/attachments_controller.rb +++ b/app/controllers/attachments_controller.rb @@ -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 diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb index 9c39ad075..c963ee00f 100644 --- a/app/controllers/repositories_controller.rb +++ b/app/controllers/repositories_controller.rb @@ -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 diff --git a/app/models/attachment.rb b/app/models/attachment.rb index 7d577dc18..4bc674f8d 100644 --- a/app/models/attachment.rb +++ b/app/models/attachment.rb @@ -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)