watchers_autocomplete_visible_only.patch

Felix Schäfer, 2013-10-14 10:07

Download (2.13 KB)

View differences:

app/controllers/watchers_controller.rb
52 52
  def append
53 53
    if params[:watcher].is_a?(Hash)
54 54
      user_ids = params[:watcher][:user_ids] || [params[:watcher][:user_id]]
55
      @users = User.active.find_all_by_id(user_ids)
55
      @users = User.visible.find_all_by_id(user_ids)
56 56
    end
57 57
  end
58 58

  
......
66 66
  end
67 67

  
68 68
  def autocomplete_for_user
69
    @users = User.active.sorted.like(params[:q]).limit(100).all
69
    @users = User.visible.sorted.like(params[:q]).limit(100).all
70 70
    if @watched
71 71
      @users -= @watched.watcher_users
72 72
    end
app/models/user.rb
78 78

  
79 79
  scope :logged, lambda { where("#{User.table_name}.status <> #{STATUS_ANONYMOUS}") }
80 80
  scope :status, lambda {|arg| where(arg.blank? ? nil : {:status => arg.to_i}) }
81
  scope :visible, lambda {|*args|
82
    pids = Project.visible(*args).pluck(:id)
83
    active.joins(:members).where(:members => {:project_id => pids}).uniq
84
  }
81 85

  
82 86
  acts_as_customizable
83 87

  
app/views/watchers/_new.html.erb
17 17
                 :project_id => @project) }')" %>
18 18

  
19 19
  <div id="users_for_watcher">
20
    <%= principals_check_box_tags 'watcher[user_ids][]', (watched ? watched.addable_watcher_users : User.active.all(:limit => 100)) %>
20
    <%= principals_check_box_tags 'watcher[user_ids][]', (watched ? watched.addable_watcher_users : User.visible.all(:limit => 100)) %>
21 21
  </div>
22 22

  
23 23
  <p class="buttons">