]> source.dussan.org Git - redmine.git/commitdiff
Fixed that improper statuses are proposed when changing status before tracker on...
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Mon, 9 Apr 2012 09:39:27 +0000 (09:39 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Mon, 9 Apr 2012 09:39:27 +0000 (09:39 +0000)
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@9378 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/controllers/issues_controller.rb
app/models/issue.rb
test/functional/issues_controller_test.rb

index 5621fbbe8ed7cf64c1e652807fd84243ebb57bf6..dfec893d6f66af3308e4abaf3adea608a9a6f59c 100644 (file)
@@ -348,8 +348,6 @@ private
   # from the params
   # TODO: Refactor, not everything in here is needed by #edit
   def update_issue_from_params
-    @allowed_statuses = @issue.new_statuses_allowed_to(User.current)
-    @priorities = IssuePriority.active
     @edit_allowed = User.current.allowed_to?(:edit_issues, @project)
     @time_entry = TimeEntry.new(:issue => @issue, :project => @issue.project)
     @time_entry.attributes = params[:time_entry]
@@ -371,6 +369,8 @@ private
       end
     end
     @issue.safe_attributes = issue_attributes
+    @priorities = IssuePriority.active
+    @allowed_statuses = @issue.new_statuses_allowed_to(User.current)
     true
   end
 
index f85ddfec4ec09ebee1a2f4ba29fd59ecb007312a..ec8c45d34f024982408c51f86183cd2bbc5a218a 100644 (file)
@@ -509,17 +509,25 @@ class Issue < ActiveRecord::Base
     !relations_to.detect {|ir| ir.relation_type == 'blocks' && !ir.issue_from.closed?}.nil?
   end
 
-  # Returns an array of status that user is able to apply
+  # Returns an array of statuses that user is able to apply
   def new_statuses_allowed_to(user=User.current, include_default=false)
-    statuses = status.find_new_statuses_allowed_to(
+    initial_status = nil
+    if new_record?
+      initial_status = IssueStatus.default
+    elsif status_id_was
+      initial_status = IssueStatus.find_by_id(status_id_was)
+    end
+    initial_status ||= status
+
+    statuses = initial_status.find_new_statuses_allowed_to(
       user.admin ? Role.all : user.roles_for_project(project),
       tracker,
       author == user,
       assigned_to_id_changed? ? assigned_to_id_was == user.id : assigned_to_id == user.id
       )
-    statuses << status unless statuses.empty?
+    statuses << initial_status unless statuses.empty?
     statuses << IssueStatus.default if include_default
-    statuses = statuses.uniq.sort
+    statuses = statuses.compact.uniq.sort
     blocked? ? statuses.reject {|s| s.is_closed?} : statuses
   end
 
index 217d6e68f5e7a2e528e3655e9827291591c480bd..9bb600eff7dfa72ec66e4f573d17ddf258c10fe5 100644 (file)
@@ -1363,6 +1363,22 @@ class IssuesControllerTest < ActionController::TestCase
     assert_equal 'This is the test_new issue', issue.subject
   end
 
+  def test_update_new_form_should_propose_transitions_based_on_initial_status
+    @request.session[:user_id] = 2
+    Workflow.delete_all
+    Workflow.create!(:role_id => 1, :tracker_id => 1, :old_status_id => 1, :new_status_id => 2)
+    Workflow.create!(:role_id => 1, :tracker_id => 1, :old_status_id => 1, :new_status_id => 5)
+    Workflow.create!(:role_id => 1, :tracker_id => 1, :old_status_id => 5, :new_status_id => 4)
+
+    xhr :post, :new, :project_id => 1,
+                     :issue => {:tracker_id => 1,
+                                :status_id => 5,
+                                :subject => 'This is an issue'}
+
+    assert_equal 5, assigns(:issue).status_id
+    assert_equal [1,2,5], assigns(:allowed_statuses).map(&:id).sort
+  end
+
   def test_post_create
     @request.session[:user_id] = 2
     assert_difference 'Issue.count' do
@@ -2171,6 +2187,23 @@ class IssuesControllerTest < ActionController::TestCase
     assert_equal 'This is the test_new issue', issue.subject
   end
 
+  def test_update_edit_form_should_propose_transitions_based_on_initial_status
+    @request.session[:user_id] = 2
+    Workflow.delete_all
+    Workflow.create!(:role_id => 1, :tracker_id => 2, :old_status_id => 2, :new_status_id => 1)
+    Workflow.create!(:role_id => 1, :tracker_id => 2, :old_status_id => 2, :new_status_id => 5)
+    Workflow.create!(:role_id => 1, :tracker_id => 2, :old_status_id => 5, :new_status_id => 4)
+
+    xhr :put, :new, :project_id => 1,
+                    :id => 2,
+                    :issue => {:tracker_id => 2,
+                               :status_id => 5,
+                               :subject => 'This is an issue'}
+
+    assert_equal 5, assigns(:issue).status_id
+    assert_equal [1,2,5], assigns(:allowed_statuses).map(&:id).sort
+  end
+
   def test_update_edit_form_with_project_change
     @request.session[:user_id] = 2
     xhr :put, :new, :project_id => 1,