@@ -1,93 +1,95 | |||||
1 | # Redmine - project management software |
|
1 | # Redmine - project management software | |
2 | # Copyright (C) 2006-2011 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 | 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 | accept_api_auth :show, :download |
|
23 | accept_api_auth :show, :download | |
24 |
|
24 | |||
25 | def show |
|
25 | def show | |
26 | respond_to do |format| |
|
26 | respond_to do |format| | |
27 | format.html { |
|
27 | format.html { | |
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 | @diff_type = params[:type] || User.current.pref[:diff_type] || 'inline' | |||
|
31 | @diff_type = 'inline' unless %w(inline sbs).include?(@diff_type) | |||
30 | render :action => 'diff' |
|
32 | render :action => 'diff' | |
31 | elsif @attachment.is_text? && @attachment.filesize <= Setting.file_max_size_displayed.to_i.kilobyte |
|
33 | elsif @attachment.is_text? && @attachment.filesize <= Setting.file_max_size_displayed.to_i.kilobyte | |
32 | @content = File.new(@attachment.diskfile, "rb").read |
|
34 | @content = File.new(@attachment.diskfile, "rb").read | |
33 | render :action => 'file' |
|
35 | render :action => 'file' | |
34 | else |
|
36 | else | |
35 | download |
|
37 | download | |
36 | end |
|
38 | end | |
37 | } |
|
39 | } | |
38 | format.api |
|
40 | format.api | |
39 | end |
|
41 | end | |
40 | end |
|
42 | end | |
41 |
|
43 | |||
42 | def download |
|
44 | def download | |
43 | if @attachment.container.is_a?(Version) || @attachment.container.is_a?(Project) |
|
45 | if @attachment.container.is_a?(Version) || @attachment.container.is_a?(Project) | |
44 | @attachment.increment_download |
|
46 | @attachment.increment_download | |
45 | end |
|
47 | end | |
46 |
|
48 | |||
47 | # images are sent inline |
|
49 | # images are sent inline | |
48 | send_file @attachment.diskfile, :filename => filename_for_content_disposition(@attachment.filename), |
|
50 | send_file @attachment.diskfile, :filename => filename_for_content_disposition(@attachment.filename), | |
49 | :type => detect_content_type(@attachment), |
|
51 | :type => detect_content_type(@attachment), | |
50 | :disposition => (@attachment.image? ? 'inline' : 'attachment') |
|
52 | :disposition => (@attachment.image? ? 'inline' : 'attachment') | |
51 |
|
53 | |||
52 | end |
|
54 | end | |
53 |
|
55 | |||
54 | verify :method => :post, :only => :destroy |
|
56 | verify :method => :post, :only => :destroy | |
55 | def destroy |
|
57 | def destroy | |
56 | # Make sure association callbacks are called |
|
58 | # Make sure association callbacks are called | |
57 | @attachment.container.attachments.delete(@attachment) |
|
59 | @attachment.container.attachments.delete(@attachment) | |
58 | redirect_to :back |
|
60 | redirect_to :back | |
59 | rescue ::ActionController::RedirectBackError |
|
61 | rescue ::ActionController::RedirectBackError | |
60 | redirect_to :controller => 'projects', :action => 'show', :id => @project |
|
62 | redirect_to :controller => 'projects', :action => 'show', :id => @project | |
61 | end |
|
63 | end | |
62 |
|
64 | |||
63 | private |
|
65 | private | |
64 | def find_project |
|
66 | def find_project | |
65 | @attachment = Attachment.find(params[:id]) |
|
67 | @attachment = Attachment.find(params[:id]) | |
66 | # Show 404 if the filename in the url is wrong |
|
68 | # Show 404 if the filename in the url is wrong | |
67 | raise ActiveRecord::RecordNotFound if params[:filename] && params[:filename] != @attachment.filename |
|
69 | raise ActiveRecord::RecordNotFound if params[:filename] && params[:filename] != @attachment.filename | |
68 | @project = @attachment.project |
|
70 | @project = @attachment.project | |
69 | rescue ActiveRecord::RecordNotFound |
|
71 | rescue ActiveRecord::RecordNotFound | |
70 | render_404 |
|
72 | render_404 | |
71 | end |
|
73 | end | |
72 |
|
74 | |||
73 | # Checks that the file exists and is readable |
|
75 | # Checks that the file exists and is readable | |
74 | def file_readable |
|
76 | def file_readable | |
75 | @attachment.readable? ? true : render_404 |
|
77 | @attachment.readable? ? true : render_404 | |
76 | end |
|
78 | end | |
77 |
|
79 | |||
78 | def read_authorize |
|
80 | def read_authorize | |
79 | @attachment.visible? ? true : deny_access |
|
81 | @attachment.visible? ? true : deny_access | |
80 | end |
|
82 | end | |
81 |
|
83 | |||
82 | def delete_authorize |
|
84 | def delete_authorize | |
83 | @attachment.deletable? ? true : deny_access |
|
85 | @attachment.deletable? ? true : deny_access | |
84 | end |
|
86 | end | |
85 |
|
87 | |||
86 | def detect_content_type(attachment) |
|
88 | def detect_content_type(attachment) | |
87 | content_type = attachment.content_type |
|
89 | content_type = attachment.content_type | |
88 | if content_type.blank? |
|
90 | if content_type.blank? | |
89 | content_type = Redmine::MimeType.of(attachment.filename) |
|
91 | content_type = Redmine::MimeType.of(attachment.filename) | |
90 | end |
|
92 | end | |
91 | content_type.to_s |
|
93 | content_type.to_s | |
92 | end |
|
94 | end | |
93 | end |
|
95 | end |
@@ -1,17 +1,24 | |||||
1 | <h2><%=h @attachment.filename %></h2> |
|
1 | <h2><%=h @attachment.filename %></h2> | |
2 |
|
2 | |||
3 | <div class="attachments"> |
|
3 | <div class="attachments"> | |
4 | <p><%= h("#{@attachment.description} - ") unless @attachment.description.blank? %> |
|
4 | <p><%= h("#{@attachment.description} - ") unless @attachment.description.blank? %> | |
5 | <span class="author"><%= link_to_user(@attachment.author) %>, <%= format_time(@attachment.created_on) %></span></p> |
|
5 | <span class="author"><%= link_to_user(@attachment.author) %>, <%= format_time(@attachment.created_on) %></span></p> | |
6 | <p><%= link_to_attachment @attachment, :text => l(:button_download), :download => true -%> |
|
6 | <p><%= link_to_attachment @attachment, :text => l(:button_download), :download => true -%> | |
7 | <span class="size">(<%= number_to_human_size @attachment.filesize %>)</span></p> |
|
7 | <span class="size">(<%= number_to_human_size @attachment.filesize %>)</span></p> | |
8 |
|
||||
9 | </div> |
|
8 | </div> | |
10 | |
|
9 | <p> | |
|
10 | <% form_tag({}, :method => 'get') do %> | |||
|
11 | <label><%= l(:label_view_diff) %></label> | |||
|
12 | <%= select_tag 'type', | |||
|
13 | options_for_select( | |||
|
14 | [[l(:label_diff_inline), "inline"], [l(:label_diff_side_by_side), "sbs"]], @diff_type), | |||
|
15 | :onchange => "if (this.value != '') {this.form.submit()}" %> | |||
|
16 | <% end %> | |||
|
17 | </p> | |||
11 | <%= render :partial => 'common/diff', :locals => {:diff => @diff, :diff_type => @diff_type} %> |
|
18 | <%= render :partial => 'common/diff', :locals => {:diff => @diff, :diff_type => @diff_type} %> | |
12 |
|
19 | |||
13 | <% html_title @attachment.filename %> |
|
20 | <% html_title @attachment.filename %> | |
14 |
|
21 | |||
15 | <% content_for :header_tags do -%> |
|
22 | <% content_for :header_tags do -%> | |
16 | <%= stylesheet_link_tag "scm" -%> |
|
23 | <%= stylesheet_link_tag "scm" -%> | |
17 | <% end -%> |
|
24 | <% end -%> |
General Comments 0
You need to be logged in to leave comments.
Login now