Fixed that the proposed users list may be empty when adding a project member (#10374).

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@9128 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Jean-Philippe Lang
2012-03-06 18:37:30 +00:00
parent b7555bd1ff
commit 6aad82e524
4 changed files with 20 additions and 2 deletions
+11
View File
@@ -45,6 +45,7 @@ class Principal < ActiveRecord::Base
# Principals that are members of a collection of projects
named_scope :member_of, lambda {|projects|
projects = [projects] unless projects.is_a?(Array)
if projects.empty?
{:conditions => "1=0"}
else
@@ -52,6 +53,16 @@ class Principal < ActiveRecord::Base
{:conditions => ["#{Principal.table_name}.status = 1 AND #{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
named_scope :not_member_of, lambda {|projects|
projects = [projects] unless projects.is_a?(Array)
if projects.empty?
{:conditions => "1=0"}
else
ids = projects.map(&:id)
{:conditions => ["#{Principal.table_name}.id NOT IN (SELECT DISTINCT user_id FROM #{Member.table_name} WHERE project_id IN (?))", ids]}
end
}
before_create :set_default_empty_values