diff options
author | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2008-07-22 17:55:19 +0000 |
---|---|---|
committer | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2008-07-22 17:55:19 +0000 |
commit | 9b579de9e234e378fb5081d79bea02d175495db7 (patch) | |
tree | 28d55b59b2ade9201dd0ea518c56e740b039e649 /app | |
parent | 8a7bfc72b20a0a554812db7f8bb7bfdf3e2a21d4 (diff) | |
download | redmine-9b579de9e234e378fb5081d79bea02d175495db7.tar.gz redmine-9b579de9e234e378fb5081d79bea02d175495db7.zip |
Appends the filename to the attachment url so that clients that ignore content-disposition http header get the real filename (#1649).
git-svn-id: http://redmine.rubyforge.org/svn/trunk@1686 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app')
-rw-r--r-- | app/controllers/attachments_controller.rb | 3 | ||||
-rw-r--r-- | app/helpers/application_helper.rb | 11 | ||||
-rw-r--r-- | app/helpers/issues_helper.rb | 4 | ||||
-rw-r--r-- | app/models/attachment.rb | 2 | ||||
-rw-r--r-- | app/views/attachments/_links.rhtml | 2 | ||||
-rw-r--r-- | app/views/attachments/diff.rhtml | 2 | ||||
-rw-r--r-- | app/views/attachments/file.rhtml | 2 | ||||
-rw-r--r-- | app/views/projects/list_files.rhtml | 3 |
8 files changed, 21 insertions, 8 deletions
diff --git a/app/controllers/attachments_controller.rb b/app/controllers/attachments_controller.rb index 07fee1269..1e8f566e6 100644 --- a/app/controllers/attachments_controller.rb +++ b/app/controllers/attachments_controller.rb @@ -43,6 +43,9 @@ class AttachmentsController < ApplicationController private def find_project @attachment = Attachment.find(params[:id]) + # Show 404 if the filename in the url is wrong + raise ActiveRecord::RecordNotFound if params[:filename] && params[:filename] != @attachment.filename + @project = @attachment.project permission = @attachment.container.is_a?(Version) ? :view_files : "view_#{@attachment.container.class.name.underscore.pluralize}".to_sym allowed = User.current.allowed_to?(permission, @project) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 6c69d8e6f..6e39d093f 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -47,6 +47,17 @@ module ApplicationHelper link_to "#{issue.tracker.name} ##{issue.id}", {:controller => "issues", :action => "show", :id => issue}, options end + # Generates a link to an attachment. + # Options: + # * :text - Link text (default to attachment filename) + # * :download - Force download (default: false) + def link_to_attachment(attachment, options={}) + text = options.delete(:text) || attachment.filename + action = options.delete(:download) ? 'download' : 'show' + + link_to(h(text), {:controller => 'attachments', :action => action, :id => attachment, :filename => attachment.filename }, options) + end + def toggle_link(name, id, options={}) onclick = "Element.toggle('#{id}'); " onclick << (options[:focus] ? "Form.Element.focus('#{options[:focus]}'); " : "this.blur(); ") diff --git a/app/helpers/issues_helper.rb b/app/helpers/issues_helper.rb index 403697178..9e419ab43 100644 --- a/app/helpers/issues_helper.rb +++ b/app/helpers/issues_helper.rb @@ -95,9 +95,9 @@ module IssuesHelper label = content_tag('strong', label) old_value = content_tag("i", h(old_value)) if detail.old_value 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) + if detail.property == 'attachment' && !value.blank? && a = Attachment.find_by_id(detail.prop_key) # Link to the attachment if it has not been removed - value = link_to(value, :controller => 'attachments', :action => 'show', :id => detail.prop_key) + value = link_to_attachment(a) else value = content_tag("i", h(value)) if value end diff --git a/app/models/attachment.rb b/app/models/attachment.rb index 7d6a74ebb..8f3f530c7 100644 --- a/app/models/attachment.rb +++ b/app/models/attachment.rb @@ -26,7 +26,7 @@ class Attachment < ActiveRecord::Base validates_length_of :disk_filename, :maximum => 255 acts_as_event :title => :filename, - :url => Proc.new {|o| {:controller => 'attachments', :action => 'download', :id => o.id}} + :url => Proc.new {|o| {:controller => 'attachments', :action => 'download', :id => o.id, :filename => o.filename}} cattr_accessor :storage_path @@storage_path = "#{RAILS_ROOT}/files" diff --git a/app/views/attachments/_links.rhtml b/app/views/attachments/_links.rhtml index 9e3ac747c..9aae909fe 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 => 'show', :id => attachment }, :class => 'icon icon-attachment' -%> +<p><%= link_to_attachment 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 index 4a9f5c9bd..7b64dca17 100644 --- a/app/views/attachments/diff.rhtml +++ b/app/views/attachments/diff.rhtml @@ -3,7 +3,7 @@ <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 } -%> +<p><%= link_to_attachment @attachment, :text => l(:button_download), :download => true -%> <span class="size">(<%= number_to_human_size @attachment.filesize %>)</span></p> </div> diff --git a/app/views/attachments/file.rhtml b/app/views/attachments/file.rhtml index 7988d0aed..468c6b666 100644 --- a/app/views/attachments/file.rhtml +++ b/app/views/attachments/file.rhtml @@ -3,7 +3,7 @@ <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 } -%> +<p><%= link_to_attachment @attachment, :text => l(:button_download), :download => true -%> <span class="size">(<%= number_to_human_size @attachment.filesize %>)</span></p> </div> diff --git a/app/views/projects/list_files.rhtml b/app/views/projects/list_files.rhtml index 43687c50a..79e41f16d 100644 --- a/app/views/projects/list_files.rhtml +++ b/app/views/projects/list_files.rhtml @@ -23,8 +23,7 @@ <% for file in version.attachments %> <tr class="<%= cycle("odd", "even") %>"> <td></td> - <td><%= link_to(h(file.filename), {:controller => 'attachments', :action => 'download', :id => file}, - :title => file.description) %></td> + <td><%= link_to_attachment file, :download => true, :title => file.description %></td> <td align="center"><%= format_time(file.created_on) %></td> <td align="center"><%= number_to_human_size(file.filesize) %></td> <td align="center"><%= file.downloads %></td> |