]> source.dussan.org Git - redmine.git/commitdiff
Add users to assignee/author filters if they are missing (#3398).
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Wed, 21 Oct 2015 18:01:11 +0000 (18:01 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Wed, 21 Oct 2015 18:01:11 +0000 (18:01 +0000)
git-svn-id: http://svn.redmine.org/redmine/trunk@14722 e93f8b46-1217-0410-a6f0-8f06a7374b81

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

index e208b64ad0cd60a031c6335aa7221064ab13022e..b167c5d9f3fd201fd25cd810ffd35333083901b8 100644 (file)
@@ -544,6 +544,11 @@ class IssueQuery < Query
     "(#{sql})"
   end
 
+  def find_assigned_to_id_filter_values(values)
+    Principal.visible.where(:id => values).map {|p| [p.name, p.id.to_s]}
+  end
+  alias :find_author_id_filter_values :find_assigned_to_id_filter_values
+
   IssueRelation::TYPES.keys.each do |relation_type|
     alias_method "sql_for_#{relation_type}_field".to_sym, :sql_for_relations
   end
index fbcf2e6465b5c31bd21312ddd69066764303334f..ed59c5526eb6c70ed7bfb68516300f6429295b1e 100644 (file)
@@ -311,7 +311,14 @@ class Query < ActiveRecord::Base
   def available_filters_as_json
     json = {}
     available_filters.each do |field, options|
-      json[field] = options.slice(:type, :name, :values).stringify_keys
+      options = options.slice(:type, :name, :values)
+      if options[:values] && values_for(field)
+        missing = Array(values_for(field)).select(&:present?) - options[:values].map(&:last)
+        if missing.any? && respond_to?(method = "find_#{field}_filter_values")
+          options[:values] += send(method, missing)
+        end
+      end
+      json[field] = options.stringify_keys
     end
     json
   end
index 30db3abd7e59617dc8bd54b36c3bd91b2e69e120..00c3d9a399fd9068a1b939fa01caf9ea30b40f2c 100644 (file)
@@ -948,6 +948,28 @@ class QueryTest < ActiveSupport::TestCase
     assert_nil q.statement
   end
 
+  def test_available_filters_as_json_should_include_missing_assigned_to_id_values
+    user = User.generate!
+    with_current_user User.find(1) do
+      q = IssueQuery.new
+      q.filters = {"assigned_to_id" => {:operator => '=', :values => user.id.to_s}}
+
+      filters = q.available_filters_as_json
+      assert_include [user.name, user.id.to_s], filters['assigned_to_id']['values']
+    end
+  end
+
+  def test_available_filters_as_json_should_include_missing_author_id_values
+    user = User.generate!
+    with_current_user User.find(1) do
+      q = IssueQuery.new
+      q.filters = {"author_id" => {:operator => '=', :values => user.id.to_s}}
+
+      filters = q.available_filters_as_json
+      assert_include [user.name, user.id.to_s], filters['author_id']['values']
+    end
+  end
+
   def test_default_columns
     q = IssueQuery.new
     assert q.columns.any?