From b995014c495b36102f36ec80618f50f3763bcd6f Mon Sep 17 00:00:00 2001 From: Go MAEDA Date: Thu, 6 Feb 2020 08:19:13 +0000 Subject: Allow adding user groups as watchers for issues (#4511). Patch by Yuichi HARADA. git-svn-id: http://svn.redmine.org/redmine/trunk@19498 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/controllers/watchers_controller.rb | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'app/controllers') diff --git a/app/controllers/watchers_controller.rb b/app/controllers/watchers_controller.rb index f0692e31d..e0de27464 100644 --- a/app/controllers/watchers_controller.rb +++ b/app/controllers/watchers_controller.rb @@ -42,7 +42,9 @@ class WatchersController < ApplicationController else user_ids << params[:user_id] end - users = User.active.visible.where(:id => user_ids.flatten.compact.uniq) + user_ids = user_ids.flatten.compact.uniq + users = User.active.visible.where(:id => user_ids).to_a + users += Group.givable.active.visible.where(:id => user_ids).to_a users.each do |user| @watchables.each do |watchable| Watcher.create(:watchable => watchable, :user => user) @@ -59,6 +61,7 @@ class WatchersController < ApplicationController if params[:watcher] user_ids = params[:watcher][:user_ids] || [params[:watcher][:user_id]] @users = User.active.visible.where(:id => user_ids).to_a + @users += Group.givable.active.visible.where(:id => user_ids).to_a end if @users.blank? head 200 @@ -66,7 +69,7 @@ class WatchersController < ApplicationController end def destroy - user = User.find(params[:user_id]) + user = Principal.find(params[:user_id]) @watchables.each do |watchable| watchable.set_watcher(user, false) end @@ -119,13 +122,16 @@ class WatchersController < ApplicationController end def users_for_new_watcher - scope = nil + scope, scope_groups = nil if params[:q].blank? && @project.present? scope = @project.users + scope_groups = @project.principals.merge(Group.givable) else scope = User.all.limit(100) + scope_groups = Group.givable.limit(100) end users = scope.active.visible.sorted.like(params[:q]).to_a + users += scope_groups.active.visible.sorted.like(params[:q]).to_a if @watchables && @watchables.size == 1 users -= @watchables.first.watcher_users end -- cgit v1.2.3