summaryrefslogtreecommitdiffstats
path: root/app/controllers/attachments_controller.rb
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2008-06-08 18:26:39 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2008-06-08 18:26:39 +0000
commitd77c1d2829f985c418442940c623ec6ec5d5457b (patch)
tree306c57c239f36e81c78a2642a911ccf3bed280ef /app/controllers/attachments_controller.rb
parente833cab30e19b5c9d17db405660f081923482f11 (diff)
downloadredmine-d77c1d2829f985c418442940c623ec6ec5d5457b.tar.gz
redmine-d77c1d2829f985c418442940c623ec6ec5d5457b.zip
Unified diff viewer for attached files with .patch or .diff extension (#1403).
git-svn-id: http://redmine.rubyforge.org/svn/trunk@1516 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app/controllers/attachments_controller.rb')
-rw-r--r--app/controllers/attachments_controller.rb13
1 files changed, 10 insertions, 3 deletions
diff --git a/app/controllers/attachments_controller.rb b/app/controllers/attachments_controller.rb
index 4e87e5442..cfc15669f 100644
--- a/app/controllers/attachments_controller.rb
+++ b/app/controllers/attachments_controller.rb
@@ -19,19 +19,26 @@ class AttachmentsController < ApplicationController
layout 'base'
before_filter :find_project, :check_project_privacy
+ def show
+ if @attachment.is_diff?
+ @diff = File.new(@attachment.diskfile, "rb").read
+ render :action => 'diff'
+ else
+ download
+ end
+ end
+
def download
# images are sent inline
send_file @attachment.diskfile, :filename => filename_for_content_disposition(@attachment.filename),
:type => @attachment.content_type,
:disposition => (@attachment.image? ? 'inline' : 'attachment')
- rescue
- # in case the disk file was deleted
- render_404
end
private
def find_project
@attachment = Attachment.find(params[:id])
+ render_404 and return false unless File.readable?(@attachment.diskfile)
@project = @attachment.project
rescue
render_404