Browse Source

Use Principal to get users and groups for watchers in watchers controller (#4511).

Patch by Marius BALTEANU.


git-svn-id: http://svn.redmine.org/redmine/trunk@19724 e93f8b46-1217-0410-a6f0-8f06a7374b81
tags/4.2.0
Go MAEDA 4 years ago
parent
commit
f09e0e8f8c
1 changed files with 5 additions and 10 deletions
  1. 5
    10
      app/controllers/watchers_controller.rb

+ 5
- 10
app/controllers/watchers_controller.rb View File

@@ -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

Loading…
Cancel
Save