From 41c055363ee4826799b9ffe7d76fd399c89190d3 Mon Sep 17 00:00:00 2001 From: Eric Davis Date: Mon, 13 Sep 2010 20:35:03 +0000 Subject: [PATCH] Refactor: split FilesController#new into #new and #create. git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@4084 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/controllers/files_controller.rb | 21 ++++++++++----------- app/views/files/new.html.erb | 2 +- config/routes.rb | 2 +- lib/redmine.rb | 2 +- test/functional/files_controller_test.rb | 8 ++++---- test/integration/routing_test.rb | 2 +- 6 files changed, 18 insertions(+), 19 deletions(-) diff --git a/app/controllers/files_controller.rb b/app/controllers/files_controller.rb index fe5eb48c8..0a4903d08 100644 --- a/app/controllers/files_controller.rb +++ b/app/controllers/files_controller.rb @@ -19,19 +19,18 @@ class FilesController < ApplicationController render :layout => !request.xhr? end - # TODO: split method into new (GET) and create (POST) def new - if request.post? - container = (params[:version_id].blank? ? @project : @project.versions.find_by_id(params[:version_id])) - attachments = Attachment.attach_files(container, params[:attachments]) - render_attachment_warning_if_needed(container) + @versions = @project.versions.sort + end - if !attachments.empty? && Setting.notified_events.include?('file_added') - Mailer.deliver_attachments_added(attachments[:files]) - end - redirect_to :controller => 'files', :action => 'index', :id => @project - return + def create + container = (params[:version_id].blank? ? @project : @project.versions.find_by_id(params[:version_id])) + attachments = Attachment.attach_files(container, params[:attachments]) + render_attachment_warning_if_needed(container) + + if !attachments.empty? && Setting.notified_events.include?('file_added') + Mailer.deliver_attachments_added(attachments[:files]) end - @versions = @project.versions.sort + redirect_to :controller => 'files', :action => 'index', :id => @project end end diff --git a/app/views/files/new.html.erb b/app/views/files/new.html.erb index bbb3b1733..870a315c9 100644 --- a/app/views/files/new.html.erb +++ b/app/views/files/new.html.erb @@ -2,7 +2,7 @@ <%= error_messages_for 'attachment' %>
-<% form_tag({ :action => 'new', :id => @project }, :multipart => true, :class => "tabular") do %> +<% form_tag({ :action => 'create', :id => @project }, :multipart => true, :class => "tabular") do %> <% if @versions.any? %>

diff --git a/config/routes.rb b/config/routes.rb index 129c3b456..152b90f54 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -196,7 +196,7 @@ ActionController::Routing::Routes.draw do |map| end project_mapper.with_options :conditions => {:method => :post} do |project_actions| - project_actions.connect 'projects/:id/files/new', :controller => 'files', :action => 'new' + project_actions.connect 'projects/:id/files/new', :controller => 'files', :action => 'create' end end diff --git a/lib/redmine.rb b/lib/redmine.rb index 526b83e65..9d59390c1 100644 --- a/lib/redmine.rb +++ b/lib/redmine.rb @@ -102,7 +102,7 @@ Redmine::AccessControl.map do |map| end map.project_module :files do |map| - map.permission :manage_files, {:files => :new}, :require => :loggedin + map.permission :manage_files, {:files => [:new, :create]}, :require => :loggedin map.permission :view_files, :files => :index, :versions => :download end diff --git a/test/functional/files_controller_test.rb b/test/functional/files_controller_test.rb index 838caee70..2f6f009e7 100644 --- a/test/functional/files_controller_test.rb +++ b/test/functional/files_controller_test.rb @@ -26,14 +26,14 @@ class FilesControllerTest < ActionController::TestCase :attributes => { :href => '/attachments/download/9/version_file.zip' } end - def test_add_file + def test_create_file set_tmp_attachments_directory @request.session[:user_id] = 2 Setting.notified_events = ['file_added'] ActionMailer::Base.deliveries.clear assert_difference 'Attachment.count' do - post :new, :id => 1, :version_id => '', + post :create, :id => 1, :version_id => '', :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain')}} assert_response :redirect end @@ -48,13 +48,13 @@ class FilesControllerTest < ActionController::TestCase assert mail.body.include?('testfile.txt') end - def test_add_version_file + def test_create_version_file set_tmp_attachments_directory @request.session[:user_id] = 2 Setting.notified_events = ['file_added'] assert_difference 'Attachment.count' do - post :new, :id => 1, :version_id => '2', + post :create, :id => 1, :version_id => '2', :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain')}} assert_response :redirect end diff --git a/test/integration/routing_test.rb b/test/integration/routing_test.rb index ac75d4d7c..1867a60b0 100644 --- a/test/integration/routing_test.rb +++ b/test/integration/routing_test.rb @@ -179,7 +179,7 @@ class RoutingTest < ActionController::IntegrationTest should_route :post, "/projects", :controller => 'projects', :action => 'create' should_route :post, "/projects.xml", :controller => 'projects', :action => 'create', :format => 'xml' - should_route :post, "/projects/33/files/new", :controller => 'files', :action => 'new', :id => '33' + should_route :post, "/projects/33/files/new", :controller => 'files', :action => 'create', :id => '33' should_route :post, "/projects/64/archive", :controller => 'projects', :action => 'archive', :id => '64' should_route :post, "/projects/64/unarchive", :controller => 'projects', :action => 'unarchive', :id => '64' -- 2.39.5