]> source.dussan.org Git - redmine.git/commitdiff
Include locked members in filters (#15201).
authorGo MAEDA <maeda@farend.jp>
Sat, 9 Jun 2018 08:07:08 +0000 (08:07 +0000)
committerGo MAEDA <maeda@farend.jp>
Sat, 9 Jun 2018 08:07:08 +0000 (08:07 +0000)
Patch by Marius BALTEANU.

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

app/models/principal.rb
app/models/query.rb
app/models/user.rb
test/functional/queries_controller_test.rb
test/unit/principal_test.rb

index b2476c1544e448820f5d97e9677f6d16f7135bf1..aac4e6b0d123734ca7d2f95bbfbe327391268003 100644 (file)
@@ -94,7 +94,9 @@ class Principal < ActiveRecord::Base
       where("1=0")
     else
       ids = projects.map(&:id)
-      active.where("#{Principal.table_name}.id IN (SELECT DISTINCT user_id FROM #{Member.table_name} WHERE project_id IN (?))", ids)
+      # include active and locked users
+      where(:status => [STATUS_LOCKED, STATUS_ACTIVE]).
+      where("#{Principal.table_name}.id IN (SELECT DISTINCT user_id FROM #{Member.table_name} WHERE project_id IN (?))", ids)
     end
   }
   # Principals that are not members of projects
index f78dd79d3b1e0560359e7e4b368b785d7fd02b39..53a245a8d79df8e926a280aa69512f495f3bee3e 100644 (file)
@@ -512,7 +512,7 @@ class Query < ActiveRecord::Base
     @principal ||= begin
       principals = []
       if project
-        principals += project.principals.visible
+        principals += Principal.member_of(project).visible
         unless project.leaf?
           principals += Principal.member_of(project.descendants.visible).visible
         end
@@ -533,14 +533,14 @@ class Query < ActiveRecord::Base
   def author_values
     author_values = []
     author_values << ["<< #{l(:label_me)} >>", "me"] if User.current.logged?
-    author_values += users.collect{|s| [s.name, s.id.to_s] }
+    author_values += users.sort_by(&:status).collect{|s| [s.name, s.id.to_s, l("status_#{User::LABEL_BY_STATUS[s.status]}")] }
     author_values
   end
 
   def assigned_to_values
     assigned_to_values = []
     assigned_to_values << ["<< #{l(:label_me)} >>", "me"] if User.current.logged?
-    assigned_to_values += (Setting.issue_group_assignment? ? principals : users).collect{|s| [s.name, s.id.to_s] }
+    assigned_to_values += (Setting.issue_group_assignment? ? principals : users).sort_by(&:status).collect{|s| [s.name, s.id.to_s, l("status_#{User::LABEL_BY_STATUS[s.status]}")] }
     assigned_to_values
   end
 
index 15d6333c6dbe313b71a4f27ffe788e92a1b46e9b..03c6b55ee8c6dca326f047cd123abc5631c002cf 100644 (file)
@@ -514,7 +514,7 @@ class User < Principal
     name
   end
 
-  CSS_CLASS_BY_STATUS = {
+  LABEL_BY_STATUS = {
     STATUS_ANONYMOUS  => 'anon',
     STATUS_ACTIVE     => 'active',
     STATUS_REGISTERED => 'registered',
@@ -522,7 +522,7 @@ class User < Principal
   }
 
   def css_classes
-    "user #{CSS_CLASS_BY_STATUS[status]}"
+    "user #{LABEL_BY_STATUS[status]}"
   end
 
   # Returns the current day according to user's time zone
index de4be4c5463fe3799416204f5bbd165c506d07f2..04fdd8ef731fd70e5e8c6c9c64fc83c5a107eb19 100644 (file)
@@ -621,4 +621,58 @@ class QueriesControllerTest < Redmine::ControllerTest
     assert_equal 4, json.count
     assert_include ["Private child of eCookbook","5"], json
   end
+
+  def test_assignee_filter_should_return_active_and_locked_users_grouped_by_status
+    @request.session[:user_id] = 1
+    get :filter, :params => {
+        :project_id => 1,
+        :type => 'IssueQuery',
+        :name => 'assigned_to_id'
+      }
+    assert_response :success
+    assert_equal 'application/json', response.content_type
+    json = ActiveSupport::JSON.decode(response.body)
+
+    assert_equal 6, json.count
+    # "me" value should not be grouped
+    assert_include ["<< me >>", "me"], json
+    assert_include ["Dave Lopper", "3", "active"], json
+    assert_include ["Dave2 Lopper2", "5", "locked"], json
+  end
+
+  def test_author_filter_should_return_active_and_locked_users_grouped_by_status
+    @request.session[:user_id] = 1
+    get :filter, :params => {
+        :project_id => 1,
+        :type => 'IssueQuery',
+        :name => 'author_id'
+      }
+    assert_response :success
+    assert_equal 'application/json', response.content_type
+    json = ActiveSupport::JSON.decode(response.body)
+
+    assert_equal 6, json.count
+    # "me" value should not be grouped
+    assert_include ["<< me >>", "me"], json
+    assert_include ["Dave Lopper", "3", "active"], json
+    assert_include ["Dave2 Lopper2", "5", "locked"], json
+  end
+
+  def test_user_filter_should_return_active_and_locked_users_grouped_by_status
+    @request.session[:user_id] = 1
+    get :filter, :params => {
+        :project_id => 1,
+        :type => 'TimeEntryQuery',
+        :name => 'user_id'
+      }
+    assert_response :success
+    assert_equal 'application/json', response.content_type
+    json = ActiveSupport::JSON.decode(response.body)
+
+    assert_equal 6, json.count
+    # "me" value should not be grouped
+    assert_include ["<< me >>", "me"], json
+    assert_include ["Dave Lopper", "3", "active"], json
+    assert_include ["Dave2 Lopper2", "5", "locked"], json
+  end
 end
index bb03a088e070912cdcc71d5b08eaa42eceb6030c..3fbd2bb053b43a6532ff2870d08964f67ab24c8b 100644 (file)
@@ -52,11 +52,11 @@ class PrincipalTest < ActiveSupport::TestCase
     assert_equal expected.map(&:id).sort, Principal.visible(user).pluck(:id).sort
   end
 
-  def test_member_of_scope_should_return_the_union_of_all_members
+  def test_member_of_scope_should_return_the_union_of_all_active_and_locked_members
     projects = Project.find([1])
-    assert_equal [3, 2], Principal.member_of(projects).sort.map(&:id)
+    assert_equal [3, 5, 2], Principal.member_of(projects).sort.map(&:id)
     projects = Project.find([1, 2])
-    assert_equal [3, 2, 8, 11], Principal.member_of(projects).sort.map(&:id)
+    assert_equal [3, 5, 2, 8, 11], Principal.member_of(projects).sort.map(&:id)
   end
 
   def test_member_of_scope_should_be_empty_for_no_projects