]> source.dussan.org Git - redmine.git/commitdiff
Show statuses of project trackers only (#5385).
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Sat, 27 May 2017 09:12:42 +0000 (09:12 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Sat, 27 May 2017 09:12:42 +0000 (09:12 +0000)
Patch by Marius BALTEANU.

git-svn-id: http://svn.redmine.org/redmine/trunk@16575 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/models/issue_query.rb
app/models/project.rb
app/models/query.rb
test/unit/project_test.rb
test/unit/query_test.rb

index 6d1298c1f95c8c853d4919de264d2dd469ca05ce..ae559713452d5d4f639802840e81807248c1883a 100644 (file)
@@ -82,7 +82,7 @@ class IssueQuery < Query
 
   def initialize_available_filters
     add_available_filter "status_id",
-      :type => :list_status, :values => lambda { IssueStatus.sorted.collect{|s| [s.name, s.id.to_s] } }
+      :type => :list_status, :values => lambda { issue_statuses }
 
     add_available_filter("project_id",
       :type => :list, :values => lambda { project_values }
index 4203068893753f53d7502ca665e53f8a395f488d..37a610980f27d5c360bd3fe7c22a3167797bcaf0 100644 (file)
@@ -324,6 +324,7 @@ class Project < ActiveRecord::Base
     @shared_versions = nil
     @rolled_up_versions = nil
     @rolled_up_trackers = nil
+    @rolled_up_statuses = nil
     @rolled_up_custom_fields = nil
     @all_issue_custom_fields = nil
     @all_time_entry_custom_fields = nil
@@ -452,6 +453,17 @@ class Project < ActiveRecord::Base
       sorted
   end
 
+  def rolled_up_statuses
+    issue_status_ids = WorkflowTransition.
+      where(:tracker_id => trackers).
+      distinct.
+      pluck(:old_status_id, :new_status_id).
+      flatten.
+      uniq
+
+    IssueStatus.where(:id => issue_status_ids).sorted
+  end
+
   # Closes open and locked project versions that are completed
   def close_completed_versions
     Version.transaction do
index 863bdbc4abc16ae79e35eb1a3e2c777f70bd5d0e..7d6b37f367edecdb8893397ff9199727114e8d1b 100644 (file)
@@ -551,6 +551,16 @@ class Query < ActiveRecord::Base
     Version.sort_by_status(versions).collect{|s| ["#{s.project.name} - #{s.name}", s.id.to_s, l("version_status_#{s.status}")] }
   end
 
+  # Returns a scope of issue statuses that are available as columns for filters
+  def issue_statuses
+    if project
+      statuses = project.rolled_up_statuses
+    else
+      statuses = IssueStatus.all.sorted
+    end
+    statuses.collect{|s| [s.name, s.id.to_s]}
+  end
+
   # Returns a scope of issue custom fields that are available as columns or filters
   def issue_custom_fields
     if project
index 66d6fa3b26a870e555de3d25c9eacaa3c23d4089..24f695831a674ef980164c80e93c693e85307be7 100644 (file)
@@ -483,6 +483,21 @@ class ProjectTest < ActiveSupport::TestCase
     assert_equal [1,2], parent.rolled_up_trackers.collect(&:id)
   end
 
+  def test_rolled_up_statuses
+    project = Project.find(1)
+
+    WorkflowTransition.delete_all
+    WorkflowTransition.create(:role_id => 1, :tracker_id => 1, :old_status_id => 1, :new_status_id => 3)
+    WorkflowTransition.create(:role_id => 1, :tracker_id => 1, :old_status_id => 1, :new_status_id => 4)
+    WorkflowTransition.create(:role_id => 1, :tracker_id => 1, :old_status_id => 2, :new_status_id => 3)
+    WorkflowTransition.create(:role_id => 1, :tracker_id => 2, :old_status_id => 1, :new_status_id => 3)
+
+    assert_kind_of IssueStatus, project.rolled_up_statuses.first
+    assert_equal IssueStatus.find(1), project.rolled_up_statuses.first
+
+    assert_equal [1, 2, 3, 4], project.rolled_up_statuses.collect(&:id)
+  end
+
   test "#rolled_up_trackers should ignore projects with issue_tracking module disabled" do
     parent = Project.generate!
     parent.trackers = Tracker.find([1, 2])
index 09d9508d629e8d7e4c3d24efb7dac29e30e4a9a6..5cbcb40af9ed48d0cf12e9028ee56a9603487291 100644 (file)
@@ -2093,4 +2093,30 @@ class QueryTest < ActiveSupport::TestCase
     issues = find_issues_with_query(query)
     assert_equal [1, 2, 5, 11, 12, 13], issues.map(&:id).sort
   end
+
+  def test_issue_statuses_should_return_only_statuses_used_by_that_project
+    query = IssueQuery.new(:name => '_', :project => Project.find(1))
+    query.filters = {'status_id' => {:operator => '=', :values => []}}
+
+    WorkflowTransition.delete_all
+    WorkflowTransition.create(:role_id => 1, :tracker_id => 1, :old_status_id => 1, :new_status_id => 3)
+    WorkflowTransition.create(:role_id => 1, :tracker_id => 1, :old_status_id => 1, :new_status_id => 4)
+    WorkflowTransition.create(:role_id => 1, :tracker_id => 1, :old_status_id => 2, :new_status_id => 3)
+    WorkflowTransition.create(:role_id => 1, :tracker_id => 2, :old_status_id => 1, :new_status_id => 3)
+
+    assert_equal ['1','2','3','4'], query.available_filters['status_id'][:values].map(&:second)
+  end
+
+  def test_issue_statuses_without_project_should_return_all_statuses
+    query = IssueQuery.new(:name => '_')
+    query.filters = {'status_id' => {:operator => '=', :values => []}}
+
+    WorkflowTransition.delete_all
+    WorkflowTransition.create(:role_id => 1, :tracker_id => 1, :old_status_id => 1, :new_status_id => 3)
+    WorkflowTransition.create(:role_id => 1, :tracker_id => 1, :old_status_id => 1, :new_status_id => 4)
+    WorkflowTransition.create(:role_id => 1, :tracker_id => 1, :old_status_id => 2, :new_status_id => 3)
+    WorkflowTransition.create(:role_id => 1, :tracker_id => 2, :old_status_id => 1, :new_status_id => 3)
+
+    assert_equal ['1','2','3','4','5','6'], query.available_filters['status_id'][:values].map(&:second)
+  end
 end