##// END OF EJS Templates
Unified diff viewer for attached files with .patch or .diff extension (#1403)....
Jean-Philippe Lang -
r1502:d77c1d2829f9
parent child
Show More
@@ -0,0 +1,15
1 <h2><%=h @attachment.filename %></h2>
2
3 <div class="attachments">
4 <p><%= h("#{@attachment.description} - ") unless @attachment.description.blank? %>
5 <span class="author"><%= @attachment.author %>, <%= format_time(@attachment.created_on) %></span></p>
6 <p><%= link_to l(:button_download), {:controller => 'attachments', :action => 'download', :id => @attachment } -%>
7 <span class="size">(<%= number_to_human_size @attachment.filesize %>)</span></p>
8
9 </div>
10 &nbsp;
11 <%= render :partial => 'common/diff', :locals => {:diff => @diff, :diff_type => @diff_type} %>
12
13 <% content_for :header_tags do -%>
14 <%= stylesheet_link_tag "scm" -%>
15 <% end -%>
@@ -19,19 +19,26 class AttachmentsController < ApplicationController
19 layout 'base'
19 layout 'base'
20 before_filter :find_project, :check_project_privacy
20 before_filter :find_project, :check_project_privacy
21
21
22 def show
23 if @attachment.is_diff?
24 @diff = File.new(@attachment.diskfile, "rb").read
25 render :action => 'diff'
26 else
27 download
28 end
29 end
30
22 def download
31 def download
23 # images are sent inline
32 # images are sent inline
24 send_file @attachment.diskfile, :filename => filename_for_content_disposition(@attachment.filename),
33 send_file @attachment.diskfile, :filename => filename_for_content_disposition(@attachment.filename),
25 :type => @attachment.content_type,
34 :type => @attachment.content_type,
26 :disposition => (@attachment.image? ? 'inline' : 'attachment')
35 :disposition => (@attachment.image? ? 'inline' : 'attachment')
27 rescue
28 # in case the disk file was deleted
29 render_404
30 end
36 end
31
37
32 private
38 private
33 def find_project
39 def find_project
34 @attachment = Attachment.find(params[:id])
40 @attachment = Attachment.find(params[:id])
41 render_404 and return false unless File.readable?(@attachment.diskfile)
35 @project = @attachment.project
42 @project = @attachment.project
36 rescue
43 rescue
37 render_404
44 render_404
@@ -22,4 +22,8 module AttachmentsHelper
22 render :partial => 'attachments/links', :locals => {:attachments => attachments, :options => options}
22 render :partial => 'attachments/links', :locals => {:attachments => attachments, :options => options}
23 end
23 end
24 end
24 end
25
26 def to_utf8(str)
27 str
28 end
25 end
29 end
@@ -91,7 +91,7 module IssuesHelper
91 old_value = content_tag("strike", old_value) if detail.old_value and (!detail.value or detail.value.empty?)
91 old_value = content_tag("strike", old_value) if detail.old_value and (!detail.value or detail.value.empty?)
92 if detail.property == 'attachment' && !value.blank? && Attachment.find_by_id(detail.prop_key)
92 if detail.property == 'attachment' && !value.blank? && Attachment.find_by_id(detail.prop_key)
93 # Link to the attachment if it has not been removed
93 # Link to the attachment if it has not been removed
94 value = link_to(value, :controller => 'attachments', :action => 'download', :id => detail.prop_key)
94 value = link_to(value, :controller => 'attachments', :action => 'show', :id => detail.prop_key)
95 else
95 else
96 value = content_tag("i", h(value)) if value
96 value = content_tag("i", h(value)) if value
97 end
97 end
@@ -88,6 +88,10 class Attachment < ActiveRecord::Base
88 self.filename =~ /\.(jpe?g|gif|png)$/i
88 self.filename =~ /\.(jpe?g|gif|png)$/i
89 end
89 end
90
90
91 def is_diff?
92 self.filename =~ /\.(patch|diff)$/i
93 end
94
91 private
95 private
92 def sanitize_filename(value)
96 def sanitize_filename(value)
93 # get only the filename, not the whole path
97 # get only the filename, not the whole path
@@ -1,6 +1,6
1 <div class="attachments">
1 <div class="attachments">
2 <% for attachment in attachments %>
2 <% for attachment in attachments %>
3 <p><%= link_to attachment.filename, {:controller => 'attachments', :action => 'download', :id => attachment }, :class => 'icon icon-attachment' -%>
3 <p><%= link_to attachment.filename, {:controller => 'attachments', :action => 'show', :id => attachment }, :class => 'icon icon-attachment' -%>
4 <%= h(" - #{attachment.description}") unless attachment.description.blank? %>
4 <%= h(" - #{attachment.description}") unless attachment.description.blank? %>
5 <span class="size">(<%= number_to_human_size attachment.filesize %>)</span>
5 <span class="size">(<%= number_to_human_size attachment.filesize %>)</span>
6 <% if options[:delete_url] %>
6 <% if options[:delete_url] %>
@@ -31,6 +31,8 ActionController::Routing::Routes.draw do |map|
31 omap.repositories_entry 'repositories/annotate/:id/*path', :action => 'annotate'
31 omap.repositories_entry 'repositories/annotate/:id/*path', :action => 'annotate'
32 end
32 end
33
33
34 map.connect 'attachments/:id', :controller => 'attachments', :action => 'show'
35
34 # Allow downloading Web Service WSDL as a file with an extension
36 # Allow downloading Web Service WSDL as a file with an extension
35 # instead of a file named 'wsdl'
37 # instead of a file named 'wsdl'
36 map.connect ':controller/service.wsdl', :action => 'wsdl'
38 map.connect ':controller/service.wsdl', :action => 'wsdl'
General Comments 0
You need to be logged in to leave comments. Login now