git-svn-id: http://redmine.rubyforge.org/svn/trunk@1516 e93f8b46-1217-0410-a6f0-8f06a7374b81tags/0.8.0-RC1
@@ -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 |
@@ -22,4 +22,8 @@ module AttachmentsHelper | |||
render :partial => 'attachments/links', :locals => {:attachments => attachments, :options => options} | |||
end | |||
end | |||
def to_utf8(str) | |||
str | |||
end | |||
end |
@@ -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 |
@@ -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 |
@@ -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] %> |
@@ -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> | |||
| |||
<%= render :partial => 'common/diff', :locals => {:diff => @diff, :diff_type => @diff_type} %> | |||
<% content_for :header_tags do -%> | |||
<%= stylesheet_link_tag "scm" -%> | |||
<% end -%> |
@@ -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' |