##// END OF EJS Templates
Merged r9128 from trunk....
Jean-Philippe Lang -
r9038:b24ad1f0bca4
parent child
Show More
@@ -96,7 +96,7 class MembersController < ApplicationController
96 96 end
97 97
98 98 def autocomplete_for_member
99 @principals = Principal.active.like(params[:q]).find(:all, :limit => 100) - @project.principals
99 @principals = Principal.active.not_member_of(@project).like(params[:q]).all(:limit => 100)
100 100 render :layout => false
101 101 end
102 102
@@ -32,6 +32,16 class Principal < ActiveRecord::Base
32 32 :order => 'type, login, lastname, firstname, mail'
33 33 }
34 34 }
35 # Principals that are not members of projects
36 named_scope :not_member_of, lambda {|projects|
37 projects = [projects] unless projects.is_a?(Array)
38 if projects.empty?
39 {:conditions => "1=0"}
40 else
41 ids = projects.map(&:id)
42 {:conditions => ["#{Principal.table_name}.id NOT IN (SELECT DISTINCT user_id FROM #{Member.table_name} WHERE project_id IN (?))", ids]}
43 end
44 }
35 45
36 46 before_create :set_default_empty_values
37 47
@@ -50,7 +50,7
50 50 <% end %>
51 51 </div>
52 52
53 <% principals = Principal.active.find(:all, :limit => 100, :order => 'type, login, lastname ASC') - @project.principals %>
53 <% principals = Principal.active.not_member_of(@project).all(:limit => 100, :order => 'type, login, lastname ASC') %>
54 54
55 55 <div class="splitcontentright">
56 56 <% if roles.any? && principals.any? %>
@@ -18,6 +18,13
18 18 require File.expand_path('../../test_helper', __FILE__)
19 19
20 20 class PrincipalTest < ActiveSupport::TestCase
21 fixtures :users, :projects, :members, :member_roles
22
23 def test_not_member_of_scope_should_return_users_that_have_no_memberships
24 projects = Project.find_all_by_id(1, 2)
25 expected = (Principal.all - projects.map(&:memberships).flatten.map(&:principal)).sort
26 assert_equal expected, Principal.not_member_of(projects).sort
27 end
21 28
22 29 context "#like" do
23 30 setup do
General Comments 0
You need to be logged in to leave comments. Login now