Project

General

Profile

Feature #4511 » 0002-Use-Principal-to-get-users-and-groups-for-watchers-i.patch

Marius BĂLTEANU, 2020-04-25 09:31

View differences:

app/controllers/watchers_controller.rb
43 43
      user_ids << params[:user_id]
44 44
    end
45 45
    user_ids = user_ids.flatten.compact.uniq
46
    users = User.active.visible.where(:id => user_ids).to_a
47
    users += Group.givable.active.visible.where(:id => user_ids).to_a
46
    users = Principal.active.visible.where(:id => user_ids).where(:users => {:type => ['User', 'Group']}).to_a
48 47
    users.each do |user|
49 48
      @watchables.each do |watchable|
50 49
        Watcher.create(:watchable => watchable, :user => user)
......
60 59
  def append
61 60
    if params[:watcher]
62 61
      user_ids = params[:watcher][:user_ids] || [params[:watcher][:user_id]]
63
      @users = User.active.visible.where(:id => user_ids).to_a
64
      @users += Group.givable.active.visible.where(:id => user_ids).to_a
62
      @users = Principal.active.visible.where(:id => user_ids).where(:users => {:type => ['User', 'Group']}).to_a
65 63
    end
66 64
    if @users.blank?
67 65
      head 200
......
122 120
  end
123 121

  
124 122
  def users_for_new_watcher
125
    scope, scope_groups = nil
123
    scope = nil
126 124
    if params[:q].blank? && @project.present?
127
      scope = @project.users
128
      scope_groups = @project.principals.merge(Group.givable)
125
      scope = @project.principals.where(:users => {:type => ['User', 'Group']})
129 126
    else
130
      scope = User.all.limit(100)
131
      scope_groups = Group.givable.limit(100)
127
      scope = Principal.where(:users => {:type => ['User', 'Group']}).limit(100)
132 128
    end
133 129
    users = scope.active.visible.sorted.like(params[:q]).to_a
134
    users += scope_groups.active.visible.sorted.like(params[:q]).to_a
135 130
    if @watchables && @watchables.size == 1
136 131
      users -= @watchables.first.watcher_users
137 132
    end
(9-9/10)