diff --git a/app/models/principal.rb b/app/models/principal.rb old mode 100644 new mode 100755 index e4410dde2..7fb8763fd --- a/app/models/principal.rb +++ b/app/models/principal.rb @@ -89,7 +89,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 diff --git a/app/models/query.rb b/app/models/query.rb old mode 100644 new mode 100755 index 6c20cd992..ed31062e5 --- a/app/models/query.rb +++ b/app/models/query.rb @@ -511,7 +511,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 @@ -532,14 +532,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 diff --git a/app/models/user.rb b/app/models/user.rb index 7cdf78678..fb3018fde 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -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 diff --git a/test/functional/queries_controller_test.rb b/test/functional/queries_controller_test.rb index 35b5832b4..e573de0ef 100644 --- a/test/functional/queries_controller_test.rb +++ b/test/functional/queries_controller_test.rb @@ -592,4 +592,58 @@ class QueriesControllerTest < Redmine::ControllerTest json = ActiveSupport::JSON.decode(response.body) assert_include ["OnlineStore - Systemwide visible version", "7", "open"], 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 diff --git a/test/unit/principal_test.rb b/test/unit/principal_test.rb old mode 100644 new mode 100755 index 2abd110f9..3a7dba535 --- a/test/unit/principal_test.rb +++ b/test/unit/principal_test.rb @@ -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