Changed ProjectsController#destroy to DELETE only.

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@8152 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Jean-Philippe Lang 2011-12-10 09:32:41 +00:00
parent 7dc8cf9340
commit 467503fd4b
4 changed files with 11 additions and 17 deletions

View File

@ -228,18 +228,15 @@ class ProjectsController < ApplicationController
redirect_to(url_for(:controller => 'admin', :action => 'projects', :status => params[:status]))
end
verify :method => :delete, :only => :destroy, :render => {:nothing => true, :status => :method_not_allowed }
# Delete @project
def destroy
@project_to_destroy = @project
if request.get?
# display confirmation view
else
if api_request? || params[:confirm]
@project_to_destroy.destroy
respond_to do |format|
format.html { redirect_to :controller => 'admin', :action => 'projects' }
format.api { head :ok }
end
if api_request? || params[:confirm]
@project_to_destroy.destroy
respond_to do |format|
format.html { redirect_to :controller => 'admin', :action => 'projects' }
format.api { head :ok }
end
end
# hide project in layout

View File

@ -34,7 +34,7 @@
<%= link_to(l(:button_archive), { :controller => 'projects', :action => 'archive', :id => project, :status => params[:status] }, :confirm => l(:text_are_you_sure), :method => :post, :class => 'icon icon-lock') if project.active? %>
<%= link_to(l(:button_unarchive), { :controller => 'projects', :action => 'unarchive', :id => project, :status => params[:status] }, :method => :post, :class => 'icon icon-unlock') if !project.active? && (project.parent.nil? || project.parent.active?) %>
<%= link_to(l(:button_copy), { :controller => 'projects', :action => 'copy', :id => project }, :class => 'icon icon-copy') %>
<%= link_to(l(:button_delete), project_destroy_confirm_path(project), :class => 'icon icon-del') %>
<%= link_to(l(:button_delete), project_path(project), :method => :delete, :class => 'icon icon-del') %>
</td>
</tr>
<% end %>

View File

@ -125,9 +125,6 @@ ActionController::Routing::Routes.draw do |map|
end
# Destroy uses a get request to prompt the user before the actual DELETE request
map.project_destroy_confirm 'projects/:id/destroy', :controller => 'projects', :action => 'destroy', :conditions => {:method => :get}
# TODO: port to be part of the resources route(s)
map.with_options :controller => 'projects' do |project_mapper|
project_mapper.with_options :conditions => {:method => :get} do |project_views|

View File

@ -410,17 +410,17 @@ class ProjectsControllerTest < ActionController::TestCase
assert_response :method_not_allowed
end
def test_get_destroy
def test_destroy_without_confirmation
@request.session[:user_id] = 1 # admin
get :destroy, :id => 1
delete :destroy, :id => 1
assert_response :success
assert_template 'destroy'
assert_not_nil Project.find_by_id(1)
end
def test_post_destroy
def test_destroy
@request.session[:user_id] = 1 # admin
post :destroy, :id => 1, :confirm => 1
delete :destroy, :id => 1, :confirm => 1
assert_redirected_to '/admin/projects'
assert_nil Project.find_by_id(1)
end