@@ -132,7 +132,7 class GroupsController < ApplicationController | |||||
132 |
|
132 | |||
133 | def autocomplete_for_user |
|
133 | def autocomplete_for_user | |
134 | @group = Group.find(params[:id]) |
|
134 | @group = Group.find(params[:id]) | |
135 |
@users = User.active.like(params[:q]). |
|
135 | @users = User.active.not_in_group(@group).like(params[:q]).all(:limit => 100) | |
136 | render :layout => false |
|
136 | render :layout => false | |
137 | end |
|
137 | end | |
138 |
|
138 |
@@ -80,6 +80,10 class User < Principal | |||||
80 | group_id = group.is_a?(Group) ? group.id : group.to_i |
|
80 | group_id = group.is_a?(Group) ? group.id : group.to_i | |
81 | { :conditions => ["#{User.table_name}.id IN (SELECT gu.user_id FROM #{table_name_prefix}groups_users#{table_name_suffix} gu WHERE gu.group_id = ?)", group_id] } |
|
81 | { :conditions => ["#{User.table_name}.id IN (SELECT gu.user_id FROM #{table_name_prefix}groups_users#{table_name_suffix} gu WHERE gu.group_id = ?)", group_id] } | |
82 | } |
|
82 | } | |
|
83 | named_scope :not_in_group, lambda {|group| | |||
|
84 | group_id = group.is_a?(Group) ? group.id : group.to_i | |||
|
85 | { :conditions => ["#{User.table_name}.id NOT IN (SELECT gu.user_id FROM #{table_name_prefix}groups_users#{table_name_suffix} gu WHERE gu.group_id = ?)", group_id] } | |||
|
86 | } | |||
83 |
|
87 | |||
84 | def before_create |
|
88 | def before_create | |
85 | self.mail_notification = Setting.default_notification_option if self.mail_notification.blank? |
|
89 | self.mail_notification = Setting.default_notification_option if self.mail_notification.blank? |
@@ -24,7 +24,7 | |||||
24 | </div> |
|
24 | </div> | |
25 |
|
25 | |||
26 | <div class="splitcontentright"> |
|
26 | <div class="splitcontentright"> | |
27 |
<% users = User.active. |
|
27 | <% users = User.active.not_in_group(@group).all(:limit => 100) %> | |
28 | <% if users.any? %> |
|
28 | <% if users.any? %> | |
29 | <% remote_form_for(:group, @group, :url => {:controller => 'groups', :action => 'add_users', :id => @group}, :method => :post) do |f| %> |
|
29 | <% remote_form_for(:group, @group, :url => {:controller => 'groups', :action => 'add_users', :id => @group}, :method => :post) do |f| %> | |
30 | <fieldset><legend><%=l(:label_user_new)%></legend> |
|
30 | <fieldset><legend><%=l(:label_user_new)%></legend> |
@@ -104,4 +104,13 class GroupsControllerTest < ActionController::TestCase | |||||
104 | post :destroy_membership, :id => 10, :membership_id => 6 |
|
104 | post :destroy_membership, :id => 10, :membership_id => 6 | |
105 | end |
|
105 | end | |
106 | end |
|
106 | end | |
|
107 | ||||
|
108 | def test_autocomplete_for_user | |||
|
109 | get :autocomplete_for_user, :id => 10, :q => 'mis' | |||
|
110 | assert_response :success | |||
|
111 | users = assigns(:users) | |||
|
112 | assert_not_nil users | |||
|
113 | assert users.any? | |||
|
114 | assert !users.include?(Group.find(10).users.first) | |||
|
115 | end | |||
107 | end |
|
116 | end |
General Comments 0
You need to be logged in to leave comments.
Login now