From 885605b439dec39b23d2043c436d03b447ad919c Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Sun, 27 Nov 2011 11:16:47 +0000 Subject: [PATCH] Resourcified attachments. git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@7948 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/controllers/attachments_controller.rb | 2 +- app/views/attachments/_links.html.erb | 4 ++-- app/views/files/index.html.erb | 4 ++-- config/routes.rb | 6 +++--- test/functional/attachments_controller_test.rb | 14 ++++++++------ 5 files changed, 16 insertions(+), 14 deletions(-) diff --git a/app/controllers/attachments_controller.rb b/app/controllers/attachments_controller.rb index 9e6dd4cb8..55cef02a8 100644 --- a/app/controllers/attachments_controller.rb +++ b/app/controllers/attachments_controller.rb @@ -53,7 +53,7 @@ class AttachmentsController < ApplicationController end - verify :method => :post, :only => :destroy + verify :method => :delete, :only => :destroy def destroy # Make sure association callbacks are called @attachment.container.attachments.delete(@attachment) diff --git a/app/views/attachments/_links.html.erb b/app/views/attachments/_links.html.erb index 4f4e2d180..c92599a66 100644 --- a/app/views/attachments/_links.html.erb +++ b/app/views/attachments/_links.html.erb @@ -4,9 +4,9 @@ <%= h(" - #{attachment.description}") unless attachment.description.blank? %> (<%= number_to_human_size attachment.filesize %>) <% if options[:deletable] %> - <%= link_to image_tag('delete.png'), {:controller => 'attachments', :action => 'destroy', :id => attachment}, + <%= link_to image_tag('delete.png'), attachment_path(attachment), :confirm => l(:text_are_you_sure), - :method => :post, + :method => :delete, :class => 'delete', :title => l(:button_delete) %> <% end %> diff --git a/app/views/files/index.html.erb b/app/views/files/index.html.erb index a1b884850..397ca5c65 100644 --- a/app/views/files/index.html.erb +++ b/app/views/files/index.html.erb @@ -33,8 +33,8 @@ <%= file.downloads %> <%= file.digest %> - <%= link_to(image_tag('delete.png'), {:controller => 'attachments', :action => 'destroy', :id => file}, - :confirm => l(:text_are_you_sure), :method => :post) if delete_allowed %> + <%= link_to(image_tag('delete.png'), attachment_path(file), + :confirm => l(:text_are_you_sure), :method => :delete) if delete_allowed %> <% end diff --git a/config/routes.rb b/config/routes.rb index dd21ef27b..833f23849 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -215,9 +215,9 @@ ActionController::Routing::Routes.draw do |map| repositories.connect 'projects/:id/repository/:action', :conditions => {:method => :post} end - - map.connect 'attachments/:id', :controller => 'attachments', :action => 'show', :id => /\d+/ - map.connect 'attachments/:id.:format', :controller => 'attachments', :action => 'show', :id => /\d+/ + + map.resources :attachments, :only => [:show, :destroy] + # additional routes for having the file name at the end of url map.connect 'attachments/:id/:filename', :controller => 'attachments', :action => 'show', :id => /\d+/, :filename => /.*/ map.connect 'attachments/download/:id/:filename', :controller => 'attachments', :action => 'download', :id => /\d+/, :filename => /.*/ diff --git a/test/functional/attachments_controller_test.rb b/test/functional/attachments_controller_test.rb index bc1a5183a..42076b57e 100644 --- a/test/functional/attachments_controller_test.rb +++ b/test/functional/attachments_controller_test.rb @@ -224,7 +224,7 @@ class AttachmentsControllerTest < ActionController::TestCase @request.session[:user_id] = 2 assert_difference 'issue.attachments.count', -1 do - post :destroy, :id => 1 + delete :destroy, :id => 1 end # no referrer assert_redirected_to '/projects/ecookbook' @@ -239,7 +239,7 @@ class AttachmentsControllerTest < ActionController::TestCase def test_destroy_wiki_page_attachment @request.session[:user_id] = 2 assert_difference 'Attachment.count', -1 do - post :destroy, :id => 3 + delete :destroy, :id => 3 assert_response 302 end set_tmp_attachments_directory @@ -248,7 +248,7 @@ class AttachmentsControllerTest < ActionController::TestCase def test_destroy_project_attachment @request.session[:user_id] = 2 assert_difference 'Attachment.count', -1 do - post :destroy, :id => 8 + delete :destroy, :id => 8 assert_response 302 end set_tmp_attachments_directory @@ -257,15 +257,17 @@ class AttachmentsControllerTest < ActionController::TestCase def test_destroy_version_attachment @request.session[:user_id] = 2 assert_difference 'Attachment.count', -1 do - post :destroy, :id => 9 + delete :destroy, :id => 9 assert_response 302 end set_tmp_attachments_directory end def test_destroy_without_permission - post :destroy, :id => 3 - assert_redirected_to '/login?back_url=http%3A%2F%2Ftest.host%2Fattachments%2Fdestroy%2F3' + assert_no_difference 'Attachment.count' do + delete :destroy, :id => 3 + end + assert_response 302 assert Attachment.find_by_id(3) set_tmp_attachments_directory end -- 2.39.5