mirror of
https://github.com/meineerde/redmine.git
synced 2026-03-17 22:48:14 +00:00
Introduces @valid_watcher?@ check on watchables (@40946).
Patch by Jens Krämer (@jkraemer). git-svn-id: https://svn.redmine.org/redmine/trunk@22916 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
parent
57743c4145
commit
c15c754589
@ -53,7 +53,9 @@ class WatchersController < ApplicationController
|
|||||||
users = Principal.assignable_watchers.where(:id => user_ids).to_a
|
users = Principal.assignable_watchers.where(:id => user_ids).to_a
|
||||||
users.each do |user|
|
users.each do |user|
|
||||||
@watchables.each do |watchable|
|
@watchables.each do |watchable|
|
||||||
Watcher.create(:watchable => watchable, :user => user)
|
if watchable.valid_watcher?(user)
|
||||||
|
Watcher.create(:watchable => watchable, :user => user)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
@ -161,10 +163,9 @@ class WatchersController < ApplicationController
|
|||||||
if @watchables && @watchables.size == 1
|
if @watchables && @watchables.size == 1
|
||||||
watchable_object = @watchables.first
|
watchable_object = @watchables.first
|
||||||
users -= watchable_object.visible_watcher_users
|
users -= watchable_object.visible_watcher_users
|
||||||
|
end
|
||||||
if watchable_object.respond_to?(:visible?)
|
@watchables&.each do |watchable|
|
||||||
users.reject! {|user| user.is_a?(User) && !watchable_object.visible?(user)}
|
users.reject!{|user| !watchable.valid_watcher?(user)}
|
||||||
end
|
|
||||||
end
|
end
|
||||||
users
|
users
|
||||||
end
|
end
|
||||||
|
|||||||
@ -70,6 +70,14 @@ module Redmine
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# true if user can be added as a watcher
|
||||||
|
def valid_watcher?(user)
|
||||||
|
return true unless respond_to?(:visible?)
|
||||||
|
return true unless user.is_a?(User)
|
||||||
|
|
||||||
|
visible?(user)
|
||||||
|
end
|
||||||
|
|
||||||
# Adds user as a watcher
|
# Adds user as a watcher
|
||||||
def add_watcher(user)
|
def add_watcher(user)
|
||||||
if persisted?
|
if persisted?
|
||||||
|
|||||||
@ -477,11 +477,11 @@ class WatchersControllerTest < Redmine::ControllerTest
|
|||||||
|
|
||||||
assert_response :success
|
assert_response :success
|
||||||
|
|
||||||
# All users from two projects eCookbook (7) and Private child of eCookbook (9)
|
# All users from two projects eCookbook (7) and Private child of eCookbook
|
||||||
assert_select 'input', :count => 5
|
# (9) who can see both issues
|
||||||
|
assert_select 'input', :count => 4
|
||||||
assert_select 'input[name=?][value="1"]', 'watcher[user_ids][]'
|
assert_select 'input[name=?][value="1"]', 'watcher[user_ids][]'
|
||||||
assert_select 'input[name=?][value="2"]', 'watcher[user_ids][]'
|
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][]'
|
assert_select 'input[name=?][value="8"]', 'watcher[user_ids][]'
|
||||||
assert_select 'input[name=?][value="10"]', 'watcher[user_ids][]'
|
assert_select 'input[name=?][value="10"]', 'watcher[user_ids][]'
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user