diff options
author | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2012-03-06 18:37:30 +0000 |
---|---|---|
committer | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2012-03-06 18:37:30 +0000 |
commit | 6aad82e524c1b2cc8afc3299e129b239f834105b (patch) | |
tree | 44f8b8999729f2bc21ad28fc2991ac780623b7cc /app/models | |
parent | b7555bd1ff6b738590679ca7c3fd00d2297a1c74 (diff) | |
download | redmine-6aad82e524c1b2cc8afc3299e129b239f834105b.tar.gz redmine-6aad82e524c1b2cc8afc3299e129b239f834105b.zip |
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
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/principal.rb | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/app/models/principal.rb b/app/models/principal.rb index 9955501e3..de6539986 100644 --- a/app/models/principal.rb +++ b/app/models/principal.rb @@ -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 |