@@ -1,72 +1,74 | |||
|
1 | 1 | # Redmine - project management software |
|
2 | 2 | # Copyright (C) 2006-2008 Jean-Philippe Lang |
|
3 | 3 | # |
|
4 | 4 | # This program is free software; you can redistribute it and/or |
|
5 | 5 | # modify it under the terms of the GNU General Public License |
|
6 | 6 | # as published by the Free Software Foundation; either version 2 |
|
7 | 7 | # of the License, or (at your option) any later version. |
|
8 | 8 | # |
|
9 | 9 | # This program is distributed in the hope that it will be useful, |
|
10 | 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | 12 | # GNU General Public License for more details. |
|
13 | 13 | # |
|
14 | 14 | # You should have received a copy of the GNU General Public License |
|
15 | 15 | # along with this program; if not, write to the Free Software |
|
16 | 16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
17 | 17 | |
|
18 | 18 | class AttachmentsController < ApplicationController |
|
19 | 19 | before_filter :find_project |
|
20 | 20 | before_filter :read_authorize, :except => :destroy |
|
21 | 21 | before_filter :delete_authorize, :only => :destroy |
|
22 | 22 | |
|
23 | 23 | verify :method => :post, :only => :destroy |
|
24 | 24 | |
|
25 | 25 | def show |
|
26 | 26 | if @attachment.is_diff? |
|
27 | 27 | @diff = File.new(@attachment.diskfile, "rb").read |
|
28 | 28 | render :action => 'diff' |
|
29 | 29 | elsif @attachment.is_text? |
|
30 | 30 | @content = File.new(@attachment.diskfile, "rb").read |
|
31 | 31 | render :action => 'file' |
|
32 | 32 | elsif |
|
33 | 33 | download |
|
34 | 34 | end |
|
35 | 35 | end |
|
36 | 36 | |
|
37 | 37 | def download |
|
38 | @attachment.increment_download if @attachment.container.is_a?(Version) | |
|
38 | if @attachment.container.is_a?(Version) || @attachment.container.is_a?(Project) | |
|
39 | @attachment.increment_download | |
|
40 | end | |
|
39 | 41 | |
|
40 | 42 | # images are sent inline |
|
41 | 43 | send_file @attachment.diskfile, :filename => filename_for_content_disposition(@attachment.filename), |
|
42 | 44 | :type => @attachment.content_type, |
|
43 | 45 | :disposition => (@attachment.image? ? 'inline' : 'attachment') |
|
44 | 46 | |
|
45 | 47 | end |
|
46 | 48 | |
|
47 | 49 | def destroy |
|
48 | 50 | # Make sure association callbacks are called |
|
49 | 51 | @attachment.container.attachments.delete(@attachment) |
|
50 | 52 | redirect_to :back |
|
51 | 53 | rescue ::ActionController::RedirectBackError |
|
52 | 54 | redirect_to :controller => 'projects', :action => 'show', :id => @project |
|
53 | 55 | end |
|
54 | 56 | |
|
55 | 57 | private |
|
56 | 58 | def find_project |
|
57 | 59 | @attachment = Attachment.find(params[:id]) |
|
58 | 60 | # Show 404 if the filename in the url is wrong |
|
59 | 61 | raise ActiveRecord::RecordNotFound if params[:filename] && params[:filename] != @attachment.filename |
|
60 | 62 | @project = @attachment.project |
|
61 | 63 | rescue ActiveRecord::RecordNotFound |
|
62 | 64 | render_404 |
|
63 | 65 | end |
|
64 | 66 | |
|
65 | 67 | def read_authorize |
|
66 | 68 | @attachment.visible? ? true : deny_access |
|
67 | 69 | end |
|
68 | 70 | |
|
69 | 71 | def delete_authorize |
|
70 | 72 | @attachment.deletable? ? true : deny_access |
|
71 | 73 | end |
|
72 | 74 | end |
General Comments 0
You need to be logged in to leave comments.
Login now