Resourcified attachments.
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@7948 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
parent
b95fd6315c
commit
885605b439
|
@ -53,7 +53,7 @@ class AttachmentsController < ApplicationController
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
verify :method => :post, :only => :destroy
|
verify :method => :delete, :only => :destroy
|
||||||
def destroy
|
def destroy
|
||||||
# Make sure association callbacks are called
|
# Make sure association callbacks are called
|
||||||
@attachment.container.attachments.delete(@attachment)
|
@attachment.container.attachments.delete(@attachment)
|
||||||
|
|
|
@ -4,9 +4,9 @@
|
||||||
<%= h(" - #{attachment.description}") unless attachment.description.blank? %>
|
<%= h(" - #{attachment.description}") unless attachment.description.blank? %>
|
||||||
<span class="size">(<%= number_to_human_size attachment.filesize %>)</span>
|
<span class="size">(<%= number_to_human_size attachment.filesize %>)</span>
|
||||||
<% if options[:deletable] %>
|
<% 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),
|
:confirm => l(:text_are_you_sure),
|
||||||
:method => :post,
|
:method => :delete,
|
||||||
:class => 'delete',
|
:class => 'delete',
|
||||||
:title => l(:button_delete) %>
|
:title => l(:button_delete) %>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
|
@ -33,8 +33,8 @@
|
||||||
<td class="downloads"><%= file.downloads %></td>
|
<td class="downloads"><%= file.downloads %></td>
|
||||||
<td class="digest"><%= file.digest %></td>
|
<td class="digest"><%= file.digest %></td>
|
||||||
<td align="center">
|
<td align="center">
|
||||||
<%= link_to(image_tag('delete.png'), {:controller => 'attachments', :action => 'destroy', :id => file},
|
<%= link_to(image_tag('delete.png'), attachment_path(file),
|
||||||
:confirm => l(:text_are_you_sure), :method => :post) if delete_allowed %>
|
:confirm => l(:text_are_you_sure), :method => :delete) if delete_allowed %>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<% end
|
<% end
|
||||||
|
|
|
@ -216,8 +216,8 @@ ActionController::Routing::Routes.draw do |map|
|
||||||
repositories.connect 'projects/:id/repository/:action', :conditions => {:method => :post}
|
repositories.connect 'projects/:id/repository/:action', :conditions => {:method => :post}
|
||||||
end
|
end
|
||||||
|
|
||||||
map.connect 'attachments/:id', :controller => 'attachments', :action => 'show', :id => /\d+/
|
map.resources :attachments, :only => [:show, :destroy]
|
||||||
map.connect 'attachments/:id.:format', :controller => 'attachments', :action => 'show', :id => /\d+/
|
# 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/:id/:filename', :controller => 'attachments', :action => 'show', :id => /\d+/, :filename => /.*/
|
||||||
map.connect 'attachments/download/:id/:filename', :controller => 'attachments', :action => 'download', :id => /\d+/, :filename => /.*/
|
map.connect 'attachments/download/:id/:filename', :controller => 'attachments', :action => 'download', :id => /\d+/, :filename => /.*/
|
||||||
|
|
||||||
|
|
|
@ -224,7 +224,7 @@ class AttachmentsControllerTest < ActionController::TestCase
|
||||||
@request.session[:user_id] = 2
|
@request.session[:user_id] = 2
|
||||||
|
|
||||||
assert_difference 'issue.attachments.count', -1 do
|
assert_difference 'issue.attachments.count', -1 do
|
||||||
post :destroy, :id => 1
|
delete :destroy, :id => 1
|
||||||
end
|
end
|
||||||
# no referrer
|
# no referrer
|
||||||
assert_redirected_to '/projects/ecookbook'
|
assert_redirected_to '/projects/ecookbook'
|
||||||
|
@ -239,7 +239,7 @@ class AttachmentsControllerTest < ActionController::TestCase
|
||||||
def test_destroy_wiki_page_attachment
|
def test_destroy_wiki_page_attachment
|
||||||
@request.session[:user_id] = 2
|
@request.session[:user_id] = 2
|
||||||
assert_difference 'Attachment.count', -1 do
|
assert_difference 'Attachment.count', -1 do
|
||||||
post :destroy, :id => 3
|
delete :destroy, :id => 3
|
||||||
assert_response 302
|
assert_response 302
|
||||||
end
|
end
|
||||||
set_tmp_attachments_directory
|
set_tmp_attachments_directory
|
||||||
|
@ -248,7 +248,7 @@ class AttachmentsControllerTest < ActionController::TestCase
|
||||||
def test_destroy_project_attachment
|
def test_destroy_project_attachment
|
||||||
@request.session[:user_id] = 2
|
@request.session[:user_id] = 2
|
||||||
assert_difference 'Attachment.count', -1 do
|
assert_difference 'Attachment.count', -1 do
|
||||||
post :destroy, :id => 8
|
delete :destroy, :id => 8
|
||||||
assert_response 302
|
assert_response 302
|
||||||
end
|
end
|
||||||
set_tmp_attachments_directory
|
set_tmp_attachments_directory
|
||||||
|
@ -257,15 +257,17 @@ class AttachmentsControllerTest < ActionController::TestCase
|
||||||
def test_destroy_version_attachment
|
def test_destroy_version_attachment
|
||||||
@request.session[:user_id] = 2
|
@request.session[:user_id] = 2
|
||||||
assert_difference 'Attachment.count', -1 do
|
assert_difference 'Attachment.count', -1 do
|
||||||
post :destroy, :id => 9
|
delete :destroy, :id => 9
|
||||||
assert_response 302
|
assert_response 302
|
||||||
end
|
end
|
||||||
set_tmp_attachments_directory
|
set_tmp_attachments_directory
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_destroy_without_permission
|
def test_destroy_without_permission
|
||||||
post :destroy, :id => 3
|
assert_no_difference 'Attachment.count' do
|
||||||
assert_redirected_to '/login?back_url=http%3A%2F%2Ftest.host%2Fattachments%2Fdestroy%2F3'
|
delete :destroy, :id => 3
|
||||||
|
end
|
||||||
|
assert_response 302
|
||||||
assert Attachment.find_by_id(3)
|
assert Attachment.find_by_id(3)
|
||||||
set_tmp_attachments_directory
|
set_tmp_attachments_directory
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue