Patch #29885 » fix_403_cm_new_watchers_v2.patch
| app/controllers/watchers_controller.rb | ||
|---|---|---|
|
scope = nil
|
||
|
if params[:q].blank? && @project.present?
|
||
|
scope = @project.users
|
||
|
elsif params[:q].blank? && @projects.present?
|
||
|
user_ids = @projects.map { |p| p.users.map(&:id) }.flatten.uniq
|
||
|
scope = User.where(:id => user_ids)
|
||
|
else
|
||
|
scope = User.all.limit(100)
|
||
|
end
|
||
| app/views/watchers/_new.html.erb | ||
|---|---|---|
|
<%= javascript_tag "observeSearchfield('user_search', 'users_for_watcher', '#{ escape_javascript url_for(:controller => 'watchers',
|
||
|
:action => 'autocomplete_for_user',
|
||
|
:object_type => (watchables.present? ? watchables.first.class.name.underscore : nil),
|
||
|
:object_id => (watchables.present? && watchables.size == 1 ? watchables.first.id : nil),
|
||
|
:object_id => (watchables.present? ? watchables.pluck(:id) : nil),
|
||
|
:project_id => @project) }')" %>
|
||
|
<div id="users_for_watcher">
|
||
| test/functional/watchers_controller_test.rb | ||
|---|---|---|
|
assert_select 'input[name=?][value="9"]', 'watcher[user_ids][]'
|
||
|
end
|
||
|
def test_autocomplete_for_user_without_keyword_with_multiple_watchables
|
||
|
@request.session[:user_id] = 2
|
||
|
User.find(2).roles.each { |role| role.add_permission! :add_issue_watchers }
|
||
|
get :autocomplete_for_user, :params => {:object_type => 'issue', :object_id => [1, 4]}, :xhr => true
|
||
|
# Return the users of the project to which object_id belongs.
|
||
|
# issue 1: eCookbook, issue 4: OnlineStore
|
||
|
assert_response :success
|
||
|
assert_select 'input', :count => 3
|
||
|
assert_select 'input[name=?][value="2"]', 'watcher[user_ids][]'
|
||
|
assert_select 'input[name=?][value="3"]', 'watcher[user_ids][]'
|
||
|
assert_select 'input[name=?][value="8"]', 'watcher[user_ids][]'
|
||
|
end
|
||
|
def test_autocomplete_for_user_with_keyword_and_multiple_watchables
|
||
|
@request.session[:user_id] = 2
|
||
|
User.find(2).roles.each { |role| role.add_permission! :add_issue_watchers }
|
||
|
get :autocomplete_for_user, :params => {:object_type => 'issue', :object_id => [1, 4], :q => 'mi'}, :xhr => true
|
||
|
# Ignore the project and return users matching "mi".
|
||
|
assert_response :success
|
||
|
assert_select 'input', :count => 4
|
||
|
assert_select 'input[name=?][value="1"]', 'watcher[user_ids][]'
|
||
|
assert_select 'input[name=?][value="2"]', 'watcher[user_ids][]'
|
||
|
assert_select 'input[name=?][value="8"]', 'watcher[user_ids][]'
|
||
|
assert_select 'input[name=?][value="9"]', 'watcher[user_ids][]'
|
||
|
end
|
||
|
def test_search_non_member_on_create
|
||
|
@request.session[:user_id] = 2
|
||
|
project = Project.find_by_name("ecookbook")
|
||
- « Previous
- 1
- 2
- Next »