comparison app/controllers/attachments_controller.rb @ 909:cbb26bc654de redmine-1.3

Update to Redmine 1.3-stable branch (Redmine SVN rev 8964)
author Chris Cannam
date Fri, 24 Feb 2012 19:09:32 +0000
parents cbce1fd3b1b7
children 5e80956cc792 433d4f72a19b
comparison
equal deleted inserted replaced
908:c6c2cbd0afee 909:cbb26bc654de
18 class AttachmentsController < ApplicationController 18 class AttachmentsController < ApplicationController
19 before_filter :find_project 19 before_filter :find_project
20 before_filter :file_readable, :read_authorize, :except => :destroy 20 before_filter :file_readable, :read_authorize, :except => :destroy
21 before_filter :delete_authorize, :only => :destroy 21 before_filter :delete_authorize, :only => :destroy
22 22
23 verify :method => :post, :only => :destroy 23 accept_api_auth :show, :download
24 24
25 def show 25 def show
26 if @attachment.is_diff? 26 respond_to do |format|
27 @diff = File.new(@attachment.diskfile, "rb").read 27 format.html {
28 render :action => 'diff' 28 if @attachment.is_diff?
29 elsif @attachment.is_text? && @attachment.filesize <= Setting.file_max_size_displayed.to_i.kilobyte 29 @diff = File.new(@attachment.diskfile, "rb").read
30 @content = File.new(@attachment.diskfile, "rb").read 30 @diff_type = params[:type] || User.current.pref[:diff_type] || 'inline'
31 render :action => 'file' 31 @diff_type = 'inline' unless %w(inline sbs).include?(@diff_type)
32 else 32 # Save diff type as user preference
33 download 33 if User.current.logged? && @diff_type != User.current.pref[:diff_type]
34 User.current.pref[:diff_type] = @diff_type
35 User.current.preference.save
36 end
37 render :action => 'diff'
38 elsif @attachment.is_text? && @attachment.filesize <= Setting.file_max_size_displayed.to_i.kilobyte
39 @content = File.new(@attachment.diskfile, "rb").read
40 render :action => 'file'
41 else
42 download
43 end
44 }
45 format.api
34 end 46 end
35 end 47 end
36 48
37 def download 49 def download
38 if @attachment.container.is_a?(Version) || @attachment.container.is_a?(Project) 50 if @attachment.container.is_a?(Version) || @attachment.container.is_a?(Project)
44 :type => detect_content_type(@attachment), 56 :type => detect_content_type(@attachment),
45 :disposition => (@attachment.image? ? 'inline' : 'attachment') 57 :disposition => (@attachment.image? ? 'inline' : 'attachment')
46 58
47 end 59 end
48 60
61 verify :method => :delete, :only => :destroy
49 def destroy 62 def destroy
50 # Make sure association callbacks are called 63 # Make sure association callbacks are called
51 @attachment.container.attachments.delete(@attachment) 64 @attachment.container.attachments.delete(@attachment)
52 redirect_to :back 65 redirect_to :back
53 rescue ::ActionController::RedirectBackError 66 rescue ::ActionController::RedirectBackError