Merged r9128 from trunk.

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/branches/1.3-stable@9158 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Jean-Philippe Lang 2012-03-07 19:40:50 +00:00
parent 898e10491f
commit b24ad1f0bc
4 changed files with 19 additions and 2 deletions

View File

@ -96,7 +96,7 @@ class MembersController < ApplicationController
end
def autocomplete_for_member
@principals = Principal.active.like(params[:q]).find(:all, :limit => 100) - @project.principals
@principals = Principal.active.not_member_of(@project).like(params[:q]).all(:limit => 100)
render :layout => false
end

View File

@ -32,6 +32,16 @@ class Principal < ActiveRecord::Base
:order => 'type, login, lastname, firstname, mail'
}
}
# 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

View File

@ -50,7 +50,7 @@
<% end %>
</div>
<% principals = Principal.active.find(:all, :limit => 100, :order => 'type, login, lastname ASC') - @project.principals %>
<% principals = Principal.active.not_member_of(@project).all(:limit => 100, :order => 'type, login, lastname ASC') %>
<div class="splitcontentright">
<% if roles.any? && principals.any? %>

View File

@ -18,6 +18,13 @@
require File.expand_path('../../test_helper', __FILE__)
class PrincipalTest < ActiveSupport::TestCase
fixtures :users, :projects, :members, :member_roles
def test_not_member_of_scope_should_return_users_that_have_no_memberships
projects = Project.find_all_by_id(1, 2)
expected = (Principal.all - projects.map(&:memberships).flatten.map(&:principal)).sort
assert_equal expected, Principal.not_member_of(projects).sort
end
context "#like" do
setup do