summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/controllers/attachments_controller.rb13
-rw-r--r--app/helpers/attachments_helper.rb4
-rw-r--r--app/helpers/issues_helper.rb2
-rw-r--r--app/models/attachment.rb4
-rw-r--r--app/views/attachments/_links.rhtml2
-rw-r--r--app/views/attachments/diff.rhtml15
-rw-r--r--config/routes.rb2
7 files changed, 37 insertions, 5 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
diff --git a/app/helpers/attachments_helper.rb b/app/helpers/attachments_helper.rb
index 989cd3e66..ebf417bab 100644
--- a/app/helpers/attachments_helper.rb
+++ b/app/helpers/attachments_helper.rb
@@ -22,4 +22,8 @@ module AttachmentsHelper
render :partial => 'attachments/links', :locals => {:attachments => attachments, :options => options}
end
end
+
+ def to_utf8(str)
+ str
+ end
end
diff --git a/app/helpers/issues_helper.rb b/app/helpers/issues_helper.rb
index 6013f1ec8..915a80b2a 100644
--- a/app/helpers/issues_helper.rb
+++ b/app/helpers/issues_helper.rb
@@ -91,7 +91,7 @@ module IssuesHelper
old_value = content_tag("strike", old_value) if detail.old_value and (!detail.value or detail.value.empty?)
if detail.property == 'attachment' && !value.blank? && Attachment.find_by_id(detail.prop_key)
# Link to the attachment if it has not been removed
- value = link_to(value, :controller => 'attachments', :action => 'download', :id => detail.prop_key)
+ value = link_to(value, :controller => 'attachments', :action => 'show', :id => detail.prop_key)
else
value = content_tag("i", h(value)) if value
end
diff --git a/app/models/attachment.rb b/app/models/attachment.rb
index 45bbd5428..95de4837a 100644
--- a/app/models/attachment.rb
+++ b/app/models/attachment.rb
@@ -88,6 +88,10 @@ class Attachment < ActiveRecord::Base
self.filename =~ /\.(jpe?g|gif|png)$/i
end
+ def is_diff?
+ self.filename =~ /\.(patch|diff)$/i
+ end
+
private
def sanitize_filename(value)
# get only the filename, not the whole path
diff --git a/app/views/attachments/_links.rhtml b/app/views/attachments/_links.rhtml
index 4d485548b..9e3ac747c 100644
--- a/app/views/attachments/_links.rhtml
+++ b/app/views/attachments/_links.rhtml
@@ -1,6 +1,6 @@
<div class="attachments">
<% for attachment in attachments %>
-<p><%= link_to attachment.filename, {:controller => 'attachments', :action => 'download', :id => attachment }, :class => 'icon icon-attachment' -%>
+<p><%= link_to attachment.filename, {:controller => 'attachments', :action => 'show', :id => attachment }, :class => 'icon icon-attachment' -%>
<%= h(" - #{attachment.description}") unless attachment.description.blank? %>
<span class="size">(<%= number_to_human_size attachment.filesize %>)</span>
<% if options[:delete_url] %>
diff --git a/app/views/attachments/diff.rhtml b/app/views/attachments/diff.rhtml
new file mode 100644
index 000000000..4a9f5c9bd
--- /dev/null
+++ b/app/views/attachments/diff.rhtml
@@ -0,0 +1,15 @@
+<h2><%=h @attachment.filename %></h2>
+
+<div class="attachments">
+<p><%= h("#{@attachment.description} - ") unless @attachment.description.blank? %>
+ <span class="author"><%= @attachment.author %>, <%= format_time(@attachment.created_on) %></span></p>
+<p><%= link_to l(:button_download), {:controller => 'attachments', :action => 'download', :id => @attachment } -%>
+ <span class="size">(<%= number_to_human_size @attachment.filesize %>)</span></p>
+
+</div>
+&nbsp;
+<%= render :partial => 'common/diff', :locals => {:diff => @diff, :diff_type => @diff_type} %>
+
+<% content_for :header_tags do -%>
+ <%= stylesheet_link_tag "scm" -%>
+<% end -%>
diff --git a/config/routes.rb b/config/routes.rb
index 0edb71a06..3cb18d1bd 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -31,6 +31,8 @@ ActionController::Routing::Routes.draw do |map|
omap.repositories_entry 'repositories/annotate/:id/*path', :action => 'annotate'
end
+ map.connect 'attachments/:id', :controller => 'attachments', :action => 'show'
+
# Allow downloading Web Service WSDL as a file with an extension
# instead of a file named 'wsdl'
map.connect ':controller/service.wsdl', :action => 'wsdl'