Mercurial > hg > soundsoftware-site
comparison app/controllers/attachments_controller.rb @ 514:7eba09d624db live
Merge
author | Chris Cannam |
---|---|
date | Thu, 14 Jul 2011 10:50:53 +0100 |
parents | 350acce374a2 |
children | 251b380117ce 5e80956cc792 |
comparison
equal
deleted
inserted
replaced
512:b9aebdd7dd40 | 514:7eba09d624db |
---|---|
1 # Redmine - project management software | 1 # Redmine - project management software |
2 # Copyright (C) 2006-2008 Jean-Philippe Lang | 2 # Copyright (C) 2006-2011 Jean-Philippe Lang |
3 # | 3 # |
4 # This program is free software; you can redistribute it and/or | 4 # This program is free software; you can redistribute it and/or |
5 # modify it under the terms of the GNU General Public License | 5 # modify it under the terms of the GNU General Public License |
6 # as published by the Free Software Foundation; either version 2 | 6 # as published by the Free Software Foundation; either version 2 |
7 # of the License, or (at your option) any later version. | 7 # of the License, or (at your option) any later version. |
8 # | 8 # |
9 # This program is distributed in the hope that it will be useful, | 9 # This program is distributed in the hope that it will be useful, |
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 # GNU General Public License for more details. | 12 # GNU General Public License for more details. |
13 # | 13 # |
14 # You should have received a copy of the GNU General Public License | 14 # You should have received a copy of the GNU General Public License |
15 # along with this program; if not, write to the Free Software | 15 # along with this program; if not, write to the Free Software |
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
17 | 17 |
18 class AttachmentsController < ApplicationController | 18 class AttachmentsController < ApplicationController |
19 | 19 |
20 before_filter :find_project | 20 before_filter :find_project |
21 before_filter :file_readable, :read_authorize, :except => :destroy | 21 before_filter :file_readable, :read_authorize, :except => :destroy |
22 before_filter :delete_authorize, :only => :destroy | 22 before_filter :delete_authorize, :only => :destroy |
23 before_filter :active_authorize, :only => :toggle_active | 23 before_filter :active_authorize, :only => :toggle_active |
24 | 24 |
25 verify :method => :post, :only => :destroy | 25 verify :method => :post, :only => :destroy |
26 | 26 |
27 def show | 27 def show |
28 if @attachment.is_diff? | 28 if @attachment.is_diff? |
29 @diff = File.new(@attachment.diskfile, "rb").read | 29 @diff = File.new(@attachment.diskfile, "rb").read |
30 render :action => 'diff' | 30 render :action => 'diff' |
31 elsif @attachment.is_text? && @attachment.filesize <= Setting.file_max_size_displayed.to_i.kilobyte | 31 elsif @attachment.is_text? && @attachment.filesize <= Setting.file_max_size_displayed.to_i.kilobyte |
33 render :action => 'file' | 33 render :action => 'file' |
34 else | 34 else |
35 download | 35 download |
36 end | 36 end |
37 end | 37 end |
38 | 38 |
39 def download | 39 def download |
40 if @attachment.container.is_a?(Version) || @attachment.container.is_a?(Project) | 40 if @attachment.container.is_a?(Version) || @attachment.container.is_a?(Project) |
41 @attachment.increment_download | 41 @attachment.increment_download |
42 end | 42 end |
43 | 43 |
44 # images are sent inline | 44 # images are sent inline |
45 send_file @attachment.diskfile, :filename => filename_for_content_disposition(@attachment.filename), | 45 send_file @attachment.diskfile, :filename => filename_for_content_disposition(@attachment.filename), |
46 :type => detect_content_type(@attachment), | 46 :type => detect_content_type(@attachment), |
47 :disposition => (@attachment.image? ? 'inline' : 'attachment') | 47 :disposition => (@attachment.image? ? 'inline' : 'attachment') |
48 | 48 |
49 end | 49 end |
50 | 50 |
51 def destroy | 51 def destroy |
52 # Make sure association callbacks are called | 52 # Make sure association callbacks are called |
53 @attachment.container.attachments.delete(@attachment) | 53 @attachment.container.attachments.delete(@attachment) |
54 redirect_to :back | 54 redirect_to :back |
55 rescue ::ActionController::RedirectBackError | 55 rescue ::ActionController::RedirectBackError |
56 redirect_to :controller => 'projects', :action => 'show', :id => @project | 56 redirect_to :controller => 'projects', :action => 'show', :id => @project |
57 end | 57 end |
58 | 58 |
59 def toggle_active | 59 def toggle_active |
60 @attachment.active = !@attachment.active? | 60 @attachment.active = !@attachment.active? |
61 @attachment.save! | 61 @attachment.save! |
62 render :layout => false | 62 render :layout => false |
63 end | 63 end |
69 raise ActiveRecord::RecordNotFound if params[:filename] && params[:filename] != @attachment.filename | 69 raise ActiveRecord::RecordNotFound if params[:filename] && params[:filename] != @attachment.filename |
70 @project = @attachment.project | 70 @project = @attachment.project |
71 rescue ActiveRecord::RecordNotFound | 71 rescue ActiveRecord::RecordNotFound |
72 render_404 | 72 render_404 |
73 end | 73 end |
74 | 74 |
75 # Checks that the file exists and is readable | 75 # Checks that the file exists and is readable |
76 def file_readable | 76 def file_readable |
77 @attachment.readable? ? true : render_404 | 77 @attachment.readable? ? true : render_404 |
78 end | 78 end |
79 | 79 |
80 def read_authorize | 80 def read_authorize |
81 @attachment.visible? ? true : deny_access | 81 @attachment.visible? ? true : deny_access |
82 end | 82 end |
83 | 83 |
84 def delete_authorize | 84 def delete_authorize |
85 @attachment.deletable? ? true : deny_access | 85 @attachment.deletable? ? true : deny_access |
86 end | 86 end |
87 | 87 |
88 def active_authorize | 88 def active_authorize |
89 true | 89 true |
90 end | 90 end |
91 | 91 |
92 def detect_content_type(attachment) | 92 def detect_content_type(attachment) |