@@ -17,7 +17,7 | |||||
17 |
|
17 | |||
18 | class AttachmentsController < ApplicationController |
|
18 | class AttachmentsController < ApplicationController | |
19 | layout 'base' |
|
19 | layout 'base' | |
20 |
before_filter :find_project |
|
20 | before_filter :find_project | |
21 |
|
21 | |||
22 | def show |
|
22 | def show | |
23 | if @attachment.is_diff? |
|
23 | if @attachment.is_diff? | |
@@ -32,6 +32,8 class AttachmentsController < ApplicationController | |||||
32 | end |
|
32 | end | |
33 |
|
33 | |||
34 | def download |
|
34 | def download | |
|
35 | @attachment.increment_download if @attachment.container.is_a?(Version) | |||
|
36 | ||||
35 | # images are sent inline |
|
37 | # images are sent inline | |
36 | send_file @attachment.diskfile, :filename => filename_for_content_disposition(@attachment.filename), |
|
38 | send_file @attachment.diskfile, :filename => filename_for_content_disposition(@attachment.filename), | |
37 | :type => @attachment.content_type, |
|
39 | :type => @attachment.content_type, | |
@@ -41,9 +43,11 class AttachmentsController < ApplicationController | |||||
41 | private |
|
43 | private | |
42 | def find_project |
|
44 | def find_project | |
43 | @attachment = Attachment.find(params[:id]) |
|
45 | @attachment = Attachment.find(params[:id]) | |
44 | #render_404 and return false unless File.readable?(@attachment.diskfile) |
|
|||
45 | @project = @attachment.project |
|
46 | @project = @attachment.project | |
46 | #rescue |
|
47 | permission = @attachment.container.is_a?(Version) ? :view_files : "view_#{@attachment.container.class.name.underscore.pluralize}".to_sym | |
47 | # render_404 |
|
48 | allowed = User.current.allowed_to?(permission, @project) | |
|
49 | allowed ? true : (User.current.logged? ? render_403 : require_login) | |||
|
50 | rescue ActiveRecord::RecordNotFound | |||
|
51 | render_404 | |||
48 | end |
|
52 | end | |
49 | end |
|
53 | end |
@@ -65,15 +65,6 class DocumentsController < ApplicationController | |||||
65 | @document.destroy |
|
65 | @document.destroy | |
66 | redirect_to :controller => 'documents', :action => 'index', :project_id => @project |
|
66 | redirect_to :controller => 'documents', :action => 'index', :project_id => @project | |
67 | end |
|
67 | end | |
68 |
|
||||
69 | def download |
|
|||
70 | @attachment = @document.attachments.find(params[:attachment_id]) |
|
|||
71 | @attachment.increment_download |
|
|||
72 | send_file @attachment.diskfile, :filename => filename_for_content_disposition(@attachment.filename), |
|
|||
73 | :type => @attachment.content_type |
|
|||
74 | rescue |
|
|||
75 | render_404 |
|
|||
76 | end |
|
|||
77 |
|
68 | |||
78 | def add_attachment |
|
69 | def add_attachment | |
79 | attachments = attach_files(@document, params[:attachments]) |
|
70 | attachments = attach_files(@document, params[:attachments]) |
@@ -37,15 +37,6 class VersionsController < ApplicationController | |||||
37 | flash[:error] = "Unable to delete version" |
|
37 | flash[:error] = "Unable to delete version" | |
38 | redirect_to :controller => 'projects', :action => 'settings', :tab => 'versions', :id => @project |
|
38 | redirect_to :controller => 'projects', :action => 'settings', :tab => 'versions', :id => @project | |
39 | end |
|
39 | end | |
40 |
|
||||
41 | def download |
|
|||
42 | @attachment = @version.attachments.find(params[:attachment_id]) |
|
|||
43 | @attachment.increment_download |
|
|||
44 | send_file @attachment.diskfile, :filename => filename_for_content_disposition(@attachment.filename), |
|
|||
45 | :type => @attachment.content_type |
|
|||
46 | rescue |
|
|||
47 | render_404 |
|
|||
48 | end |
|
|||
49 |
|
40 | |||
50 | def destroy_file |
|
41 | def destroy_file | |
51 | @version.attachments.find(params[:attachment_id]).destroy |
|
42 | @version.attachments.find(params[:attachment_id]).destroy |
@@ -23,8 +23,8 | |||||
23 | <% for file in version.attachments %> |
|
23 | <% for file in version.attachments %> | |
24 | <tr class="<%= cycle("odd", "even") %>"> |
|
24 | <tr class="<%= cycle("odd", "even") %>"> | |
25 | <td></td> |
|
25 | <td></td> | |
26 |
<td><%= link_to(file.filename, {:controller => ' |
|
26 | <td><%= link_to(h(file.filename), {:controller => 'attachments', :action => 'download', :id => file}, | |
27 | :title => file.description) %></td> |
|
27 | :title => file.description) %></td> | |
28 | <td align="center"><%= format_time(file.created_on) %></td> |
|
28 | <td align="center"><%= format_time(file.created_on) %></td> | |
29 | <td align="center"><%= number_to_human_size(file.filesize) %></td> |
|
29 | <td align="center"><%= number_to_human_size(file.filesize) %></td> | |
30 | <td align="center"><%= file.downloads %></td> |
|
30 | <td align="center"><%= file.downloads %></td> |
@@ -73,3 +73,16 attachments_006: | |||||
73 | filename: archive.zip |
|
73 | filename: archive.zip | |
74 | author_id: 2 |
|
74 | author_id: 2 | |
75 | content_type: application/octet-stream |
|
75 | content_type: application/octet-stream | |
|
76 | attachments_007: | |||
|
77 | created_on: 2006-07-19 21:07:27 +02:00 | |||
|
78 | container_type: Issue | |||
|
79 | container_id: 4 | |||
|
80 | downloads: 0 | |||
|
81 | disk_filename: 060719210727_archive.zip | |||
|
82 | digest: b91e08d0cf966d5c6ff411bd8c4cc3a2 | |||
|
83 | id: 7 | |||
|
84 | filesize: 157 | |||
|
85 | filename: archive.zip | |||
|
86 | author_id: 1 | |||
|
87 | content_type: application/octet-stream | |||
|
88 | No newline at end of file |
@@ -56,4 +56,9 class AttachmentsControllerTest < Test::Unit::TestCase | |||||
56 | assert_response :success |
|
56 | assert_response :success | |
57 | assert_equal 'application/x-ruby', @response.content_type |
|
57 | assert_equal 'application/x-ruby', @response.content_type | |
58 | end |
|
58 | end | |
|
59 | ||||
|
60 | def test_anonymous_on_private_private | |||
|
61 | get :download, :id => 7 | |||
|
62 | assert_redirected_to 'account/login' | |||
|
63 | end | |||
59 | end |
|
64 | end |
General Comments 0
You need to be logged in to leave comments.
Login now