summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/models/issue_query.rb2
-rw-r--r--app/models/project.rb12
-rw-r--r--app/models/query.rb10
-rw-r--r--test/unit/project_test.rb15
-rw-r--r--test/unit/query_test.rb26
5 files changed, 64 insertions, 1 deletions
diff --git a/app/models/issue_query.rb b/app/models/issue_query.rb
index 6d1298c1f..ae5597134 100644
--- a/app/models/issue_query.rb
+++ b/app/models/issue_query.rb
@@ -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 }
diff --git a/app/models/project.rb b/app/models/project.rb
index 420306889..37a610980 100644
--- a/app/models/project.rb
+++ b/app/models/project.rb
@@ -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
diff --git a/app/models/query.rb b/app/models/query.rb
index 863bdbc4a..7d6b37f36 100644
--- a/app/models/query.rb
+++ b/app/models/query.rb
@@ -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
diff --git a/test/unit/project_test.rb b/test/unit/project_test.rb
index 66d6fa3b2..24f695831 100644
--- a/test/unit/project_test.rb
+++ b/test/unit/project_test.rb
@@ -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])
diff --git a/test/unit/query_test.rb b/test/unit/query_test.rb
index 09d9508d6..5cbcb40af 100644
--- a/test/unit/query_test.rb
+++ b/test/unit/query_test.rb
@@ -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