[#800 #801] Exclude users already watching the issue

This commit is contained in:
Eric Davis 2010-12-03 14:56:29 -08:00
parent 8160cd02bd
commit c3555b1728
3 changed files with 30 additions and 4 deletions

View File

@ -37,9 +37,17 @@ class AutoCompletesController < ApplicationController
if params[:remove_group_members].present?
@group = Group.find(params[:remove_group_members])
@removed_users = @group.users
else
@removed_users = []
end
if params[:remove_watchers].present? && params[:klass].present?
watcher_class = params[:klass].constantize
if watcher_class.included_modules.include?(Redmine::Acts::Watchable) # check class is a watching class
@object = watcher_class.find(params[:remove_watchers])
@removed_users = @object.watcher_users
end
end
@removed_users ||= []
@users = User.active.like(params[:q]).find(:all, :limit => 100) - @removed_users
render :layout => false

View File

@ -12,12 +12,12 @@
:object_id => watched},
:method => :post,
:html => {:id => 'new-watcher-form', :style => 'display:none;'}) do |f| %>
<% users = User.active.find(:all, :limit => 10) %>
<% users = User.active.find(:all, :limit => 25) - watched.watcher_users %>
<p><%= label_tag "user_search", l(:label_user_search) %><%= text_field_tag 'user_search', nil, :style => "width:98%;" %></p>
<%= observe_field(:user_search,
:frequency => 0.5,
:update => :users,
:url => auto_complete_users_path,
:url => auto_complete_users_path(:remove_watchers => watched.id, :klass => watched.class),
:with => 'q')
%>

View File

@ -109,5 +109,23 @@ class AutoCompletesControllerTest < ActionController::TestCase
assert_select "input[type=checkbox][value=?]", @firstname.id, :count => 0
end
end
context "restrict by removing issue watchers" do
setup do
@issue = Issue.find(2)
@issue.add_watcher(@login)
@issue.add_watcher(@firstname)
get :users, :q => 'complete', :remove_watchers => @issue.id, :klass => 'Issue'
end
should_respond_with :success
should "not include existing watchers" do
assert_select "input[type=checkbox][value=?]", @lastname.id
assert_select "input[type=checkbox][value=?]", @login.id, :count => 0
assert_select "input[type=checkbox][value=?]", @firstname.id, :count => 0
end
end
end
end