Rename AttachmentsController#edit and #update to #edit_all and #update_all (#22356).

git-svn-id: http://svn.redmine.org/redmine/trunk@15860 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Jean-Philippe Lang
2016-10-01 12:46:29 +00:00
parent 973c9484b0
commit a2bcc9c40e
4 changed files with 21 additions and 19 deletions

View File

@@ -17,7 +17,7 @@
class AttachmentsController < ApplicationController
before_action :find_attachment, :only => [:show, :download, :thumbnail, :destroy]
before_action :find_editable_attachments, :only => [:edit, :update]
before_action :find_editable_attachments, :only => [:edit_all, :update_all]
before_action :file_readable, :read_authorize, :only => [:show, :download, :thumbnail]
before_action :delete_authorize, :only => :destroy
before_action :authorize_global, :only => :upload
@@ -26,7 +26,7 @@ class AttachmentsController < ApplicationController
# MIME type text/javascript.
skip_after_filter :verify_same_origin_request, :only => :download
accept_api_auth :show, :download, :thumbnail, :upload, :destroy
accept_api_auth :show, :download, :thumbnail, :upload, :update, :destroy
def show
respond_to do |format|
@@ -107,17 +107,19 @@ class AttachmentsController < ApplicationController
end
end
def edit
# Edit all the attachments of a container
def edit_all
end
def update
# Update all the attachments of a container
def update_all
if params[:attachments].is_a?(Hash)
if Attachment.update_attachments(@attachments, params[:attachments])
redirect_back_or_default home_path
return
end
end
render :action => 'edit'
render :action => 'edit_all'
end
def destroy

View File

@@ -294,8 +294,8 @@ Rails.application.routes.draw do
get 'attachments/download/:id', :to => 'attachments#download', :id => /\d+/
get 'attachments/thumbnail/:id(/:size)', :to => 'attachments#thumbnail', :id => /\d+/, :size => /\d+/, :as => 'thumbnail'
resources :attachments, :only => [:show, :destroy]
get 'attachments/:object_type/:object_id/edit', :to => 'attachments#edit', :as => :object_attachments_edit
patch 'attachments/:object_type/:object_id', :to => 'attachments#update', :as => :object_attachments
get 'attachments/:object_type/:object_id/edit', :to => 'attachments#edit_all', :as => :object_attachments_edit
patch 'attachments/:object_type/:object_id', :to => 'attachments#update_all', :as => :object_attachments
resources :groups do
resources :memberships, :controller => 'principal_memberships'

View File

@@ -354,9 +354,9 @@ class AttachmentsControllerTest < Redmine::ControllerTest
puts '(ImageMagick convert not available)'
end
def test_edit
def test_edit_all
@request.session[:user_id] = 2
get :edit, :object_type => 'issues', :object_id => '2'
get :edit_all, :object_type => 'issues', :object_id => '2'
assert_response :success
assert_select 'form[action=?]', '/attachments/issues/2' do
@@ -371,24 +371,24 @@ class AttachmentsControllerTest < Redmine::ControllerTest
end
end
def test_edit_invalid_container_class_should_return_404
get :edit, :object_type => 'nuggets', :object_id => '3'
def test_edit_all_with_invalid_container_class_should_return_404
get :edit_all, :object_type => 'nuggets', :object_id => '3'
assert_response 404
end
def test_edit_invalid_object_should_return_404
get :edit, :object_type => 'issues', :object_id => '999'
def test_edit_all_with_invalid_object_should_return_404
get :edit_all, :object_type => 'issues', :object_id => '999'
assert_response 404
end
def test_edit_for_object_that_is_not_visible_should_return_403
get :edit, :object_type => 'issues', :object_id => '4'
def test_edit_all_for_object_that_is_not_visible_should_return_403
get :edit_all, :object_type => 'issues', :object_id => '4'
assert_response 403
end
def test_update
def test_update_all
@request.session[:user_id] = 2
patch :update, :object_type => 'issues', :object_id => '2', :attachments => {
patch :update_all, :object_type => 'issues', :object_id => '2', :attachments => {
'1' => {:filename => 'newname.text', :description => ''},
'4' => {:filename => 'newname.rb', :description => 'Renamed'},
}
@@ -399,9 +399,9 @@ class AttachmentsControllerTest < Redmine::ControllerTest
assert_equal 'Renamed', attachment.description
end
def test_update_with_failure
def test_update_all_with_failure
@request.session[:user_id] = 2
patch :update, :object_type => 'issues', :object_id => '3', :attachments => {
patch :update_all, :object_type => 'issues', :object_id => '3', :attachments => {
'1' => {:filename => '', :description => ''},
'4' => {:filename => 'newname.rb', :description => 'Renamed'},
}