From 1cc9145ce4fdfb959324f60f1ee59d173c1b66f1 Mon Sep 17 00:00:00 2001 From: Marius BALTEANU Date: Tue, 21 Apr 2020 00:12:11 +0300 Subject: [PATCH 2/4] Use Principal to get users and groups for watchers in watchers controller --- app/controllers/watchers_controller.rb | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/app/controllers/watchers_controller.rb b/app/controllers/watchers_controller.rb index 079436ab7..630566dcd 100644 --- a/app/controllers/watchers_controller.rb +++ b/app/controllers/watchers_controller.rb @@ -43,8 +43,7 @@ class WatchersController < ApplicationController user_ids << params[:user_id] end 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 = Principal.active.visible.where(:id => user_ids).where(:users => {:type => ['User', 'Group']}).to_a users.each do |user| @watchables.each do |watchable| Watcher.create(:watchable => watchable, :user => user) @@ -60,8 +59,7 @@ class WatchersController < ApplicationController def append 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 + @users = Principal.active.visible.where(:id => user_ids).where(:users => {:type => ['User', 'Group']}).to_a end if @users.blank? head 200 @@ -122,16 +120,13 @@ class WatchersController < ApplicationController end def users_for_new_watcher - scope, scope_groups = nil + scope = nil if params[:q].blank? && @project.present? - scope = @project.users - scope_groups = @project.principals.merge(Group.givable) + scope = @project.principals.where(:users => {:type => ['User', 'Group']}) else - scope = User.all.limit(100) - scope_groups = Group.givable.limit(100) + scope = Principal.where(:users => {:type => ['User', 'Group']}).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 -- 2.22.0