From c68d853bf4cfd9bf60df3166317b0dcea0702461 Mon Sep 17 00:00:00 2001 From: Eric Davis Date: Thu, 25 Feb 2010 17:01:05 +0000 Subject: [PATCH] Refactor: Move the updating of an Issue to the #update method. git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@3486 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/controllers/issues_controller.rb | 32 ++++++++++++++++++++++------ config/routes.rb | 3 ++- test/integration/issues_api_test.rb | 2 +- test/integration/issues_test.rb | 2 +- 4 files changed, 29 insertions(+), 10 deletions(-) diff --git a/app/controllers/issues_controller.rb b/app/controllers/issues_controller.rb index 827186d89b8..ff75659d7e7 100644 --- a/app/controllers/issues_controller.rb +++ b/app/controllers/issues_controller.rb @@ -198,6 +198,31 @@ def edit @issue.safe_attributes = attrs end + respond_to do |format| + format.html { } + format.xml { } + end + end + + #-- + # Start converting to the Rails REST controllers + #++ + def update + @allowed_statuses = @issue.new_statuses_allowed_to(User.current) + @priorities = IssuePriority.all + @edit_allowed = User.current.allowed_to?(:edit_issues, @project) + @time_entry = TimeEntry.new + + @notes = params[:notes] + journal = @issue.init_journal(User.current, @notes) + # User can change issue attributes only if he has :edit permission or if a workflow transition is allowed + if (@edit_allowed || !@allowed_statuses.empty?) && params[:issue] + attrs = params[:issue].dup + attrs.delete_if {|k,v| !UPDATABLE_ATTRS_ON_TRANSITION.include?(k) } unless @edit_allowed + attrs.delete(:status_id) unless @allowed_statuses.detect {|s| s.id.to_s == attrs[:status_id].to_s} + @issue.safe_attributes = attrs + end + if request.get? # nop else @@ -237,13 +262,6 @@ def edit attachments.each(&:destroy) end - #-- - # Start converting to the Rails REST controllers - #++ - def update - edit - end - def reply journal = Journal.find(params[:journal_id]) if params[:journal_id] if journal diff --git a/config/routes.rb b/config/routes.rb index 54a5ddf1724..e3707b64418 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -126,7 +126,8 @@ issues_actions.connect 'issues.:format', :action => 'new', :format => /xml/ end issues_routes.with_options :conditions => {:method => :put} do |issues_actions| - issues_actions.connect 'issues/:id.:format', :action => 'edit', :id => /\d+/, :format => /xml/ + issues_actions.connect 'issues/:id/edit', :action => 'update', :id => /\d+/ + issues_actions.connect 'issues/:id.:format', :action => 'update', :id => /\d+/, :format => /xml/ end issues_routes.with_options :conditions => {:method => :delete} do |issues_actions| issues_actions.connect 'issues/:id.:format', :action => 'destroy', :id => /\d+/, :format => /xml/ diff --git a/test/integration/issues_api_test.rb b/test/integration/issues_api_test.rb index d107723f4b8..c622d0c4687 100644 --- a/test/integration/issues_api_test.rb +++ b/test/integration/issues_api_test.rb @@ -114,7 +114,7 @@ def test_create_failure def test_update_routing assert_routing( {:method => :put, :path => '/issues/1.xml'}, - :controller => 'issues', :action => 'edit', :id => '1', :format => 'xml' + :controller => 'issues', :action => 'update', :id => '1', :format => 'xml' ) end diff --git a/test/integration/issues_test.rb b/test/integration/issues_test.rb index 0a35e139e43..0c1a36d3482 100644 --- a/test/integration/issues_test.rb +++ b/test/integration/issues_test.rb @@ -69,7 +69,7 @@ def test_issue_attachements log_user('jsmith', 'jsmith') set_tmp_attachments_directory - post 'issues/1/edit', + put 'issues/1/edit', :notes => 'Some notes', :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain'), 'description' => 'This is an attachment'}} assert_redirected_to "issues/1"