##// END OF EJS Templates
Resourcified attachments....
Jean-Philippe Lang -
r7828:885605b439de
parent child
Show More
@@ -53,7 +53,7 class AttachmentsController < ApplicationController
53
53
54 end
54 end
55
55
56 verify :method => :post, :only => :destroy
56 verify :method => :delete, :only => :destroy
57 def destroy
57 def destroy
58 # Make sure association callbacks are called
58 # Make sure association callbacks are called
59 @attachment.container.attachments.delete(@attachment)
59 @attachment.container.attachments.delete(@attachment)
@@ -4,9 +4,9
4 <%= h(" - #{attachment.description}") unless attachment.description.blank? %>
4 <%= h(" - #{attachment.description}") unless attachment.description.blank? %>
5 <span class="size">(<%= number_to_human_size attachment.filesize %>)</span>
5 <span class="size">(<%= number_to_human_size attachment.filesize %>)</span>
6 <% if options[:deletable] %>
6 <% if options[:deletable] %>
7 <%= link_to image_tag('delete.png'), {:controller => 'attachments', :action => 'destroy', :id => attachment},
7 <%= link_to image_tag('delete.png'), attachment_path(attachment),
8 :confirm => l(:text_are_you_sure),
8 :confirm => l(:text_are_you_sure),
9 :method => :post,
9 :method => :delete,
10 :class => 'delete',
10 :class => 'delete',
11 :title => l(:button_delete) %>
11 :title => l(:button_delete) %>
12 <% end %>
12 <% end %>
@@ -33,8 +33,8
33 <td class="downloads"><%= file.downloads %></td>
33 <td class="downloads"><%= file.downloads %></td>
34 <td class="digest"><%= file.digest %></td>
34 <td class="digest"><%= file.digest %></td>
35 <td align="center">
35 <td align="center">
36 <%= link_to(image_tag('delete.png'), {:controller => 'attachments', :action => 'destroy', :id => file},
36 <%= link_to(image_tag('delete.png'), attachment_path(file),
37 :confirm => l(:text_are_you_sure), :method => :post) if delete_allowed %>
37 :confirm => l(:text_are_you_sure), :method => :delete) if delete_allowed %>
38 </td>
38 </td>
39 </tr>
39 </tr>
40 <% end
40 <% end
@@ -216,8 +216,8 ActionController::Routing::Routes.draw do |map|
216 repositories.connect 'projects/:id/repository/:action', :conditions => {:method => :post}
216 repositories.connect 'projects/:id/repository/:action', :conditions => {:method => :post}
217 end
217 end
218
218
219 map.connect 'attachments/:id', :controller => 'attachments', :action => 'show', :id => /\d+/
219 map.resources :attachments, :only => [:show, :destroy]
220 map.connect 'attachments/:id.:format', :controller => 'attachments', :action => 'show', :id => /\d+/
220 # additional routes for having the file name at the end of url
221 map.connect 'attachments/:id/:filename', :controller => 'attachments', :action => 'show', :id => /\d+/, :filename => /.*/
221 map.connect 'attachments/:id/:filename', :controller => 'attachments', :action => 'show', :id => /\d+/, :filename => /.*/
222 map.connect 'attachments/download/:id/:filename', :controller => 'attachments', :action => 'download', :id => /\d+/, :filename => /.*/
222 map.connect 'attachments/download/:id/:filename', :controller => 'attachments', :action => 'download', :id => /\d+/, :filename => /.*/
223
223
@@ -224,7 +224,7 class AttachmentsControllerTest < ActionController::TestCase
224 @request.session[:user_id] = 2
224 @request.session[:user_id] = 2
225
225
226 assert_difference 'issue.attachments.count', -1 do
226 assert_difference 'issue.attachments.count', -1 do
227 post :destroy, :id => 1
227 delete :destroy, :id => 1
228 end
228 end
229 # no referrer
229 # no referrer
230 assert_redirected_to '/projects/ecookbook'
230 assert_redirected_to '/projects/ecookbook'
@@ -239,7 +239,7 class AttachmentsControllerTest < ActionController::TestCase
239 def test_destroy_wiki_page_attachment
239 def test_destroy_wiki_page_attachment
240 @request.session[:user_id] = 2
240 @request.session[:user_id] = 2
241 assert_difference 'Attachment.count', -1 do
241 assert_difference 'Attachment.count', -1 do
242 post :destroy, :id => 3
242 delete :destroy, :id => 3
243 assert_response 302
243 assert_response 302
244 end
244 end
245 set_tmp_attachments_directory
245 set_tmp_attachments_directory
@@ -248,7 +248,7 class AttachmentsControllerTest < ActionController::TestCase
248 def test_destroy_project_attachment
248 def test_destroy_project_attachment
249 @request.session[:user_id] = 2
249 @request.session[:user_id] = 2
250 assert_difference 'Attachment.count', -1 do
250 assert_difference 'Attachment.count', -1 do
251 post :destroy, :id => 8
251 delete :destroy, :id => 8
252 assert_response 302
252 assert_response 302
253 end
253 end
254 set_tmp_attachments_directory
254 set_tmp_attachments_directory
@@ -257,15 +257,17 class AttachmentsControllerTest < ActionController::TestCase
257 def test_destroy_version_attachment
257 def test_destroy_version_attachment
258 @request.session[:user_id] = 2
258 @request.session[:user_id] = 2
259 assert_difference 'Attachment.count', -1 do
259 assert_difference 'Attachment.count', -1 do
260 post :destroy, :id => 9
260 delete :destroy, :id => 9
261 assert_response 302
261 assert_response 302
262 end
262 end
263 set_tmp_attachments_directory
263 set_tmp_attachments_directory
264 end
264 end
265
265
266 def test_destroy_without_permission
266 def test_destroy_without_permission
267 post :destroy, :id => 3
267 assert_no_difference 'Attachment.count' do
268 assert_redirected_to '/login?back_url=http%3A%2F%2Ftest.host%2Fattachments%2Fdestroy%2F3'
268 delete :destroy, :id => 3
269 end
270 assert_response 302
269 assert Attachment.find_by_id(3)
271 assert Attachment.find_by_id(3)
270 set_tmp_attachments_directory
272 set_tmp_attachments_directory
271 end
273 end
General Comments 0
You need to be logged in to leave comments. Login now