OSDN Git Service

Refactor: Move the updating of an Issue to the #update method.
authorEric Davis <edavis@littlestreamsoftware.com>
Thu, 25 Feb 2010 17:01:05 +0000 (17:01 +0000)
committerEric Davis <edavis@littlestreamsoftware.com>
Thu, 25 Feb 2010 17:01:05 +0000 (17:01 +0000)
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@3486 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/controllers/issues_controller.rb
config/routes.rb
test/integration/issues_api_test.rb
test/integration/issues_test.rb

index 827186d..ff75659 100644 (file)
@@ -198,6 +198,31 @@ class IssuesController < ApplicationController
       @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 @@ class IssuesController < ApplicationController
     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
index 54a5ddf..e3707b6 100644 (file)
@@ -126,7 +126,8 @@ ActionController::Routing::Routes.draw do |map|
       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/
index d107723..c622d0c 100644 (file)
@@ -114,7 +114,7 @@ class IssuesApiTest < ActionController::IntegrationTest
   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
   
index 0a35e13..0c1a36d 100644 (file)
@@ -69,7 +69,7 @@ class IssuesTest < ActionController::IntegrationTest
     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"