diff app/controllers/watchers_controller.rb @ 1517:dffacf8a6908 redmine-2.5

Update to Redmine SVN revision 13367 on 2.5-stable branch
author Chris Cannam
date Tue, 09 Sep 2014 09:29:00 +0100
parents e248c7af89ec
children
line wrap: on
line diff
--- a/app/controllers/watchers_controller.rb	Tue Sep 09 09:28:31 2014 +0100
+++ b/app/controllers/watchers_controller.rb	Tue Sep 09 09:29:00 2014 +0100
@@ -30,6 +30,7 @@
   accept_api_auth :create, :destroy
 
   def new
+    @users = users_for_new_watcher
   end
 
   def create
@@ -44,7 +45,7 @@
     end
     respond_to do |format|
       format.html { redirect_to_referer_or {render :text => 'Watcher added.', :layout => true}}
-      format.js
+      format.js { @users = users_for_new_watcher }
       format.api { render_api_ok }
     end
   end
@@ -52,7 +53,10 @@
   def append
     if params[:watcher].is_a?(Hash)
       user_ids = params[:watcher][:user_ids] || [params[:watcher][:user_id]]
-      @users = User.active.find_all_by_id(user_ids)
+      @users = User.active.where(:id => user_ids).all
+    end
+    if @users.blank?
+      render :nothing => true
     end
   end
 
@@ -66,10 +70,7 @@
   end
 
   def autocomplete_for_user
-    @users = User.active.sorted.like(params[:q]).limit(100).all
-    if @watched
-      @users -= @watched.watcher_users
-    end
+    @users = users_for_new_watcher
     render :layout => false
   end
 
@@ -91,8 +92,14 @@
   def find_watchables
     klass = Object.const_get(params[:object_type].camelcase) rescue nil
     if klass && klass.respond_to?('watched_by')
-      @watchables = klass.find_all_by_id(Array.wrap(params[:object_id]))
-      raise Unauthorized if @watchables.any? {|w| w.respond_to?(:visible?) && !w.visible?}
+      @watchables = klass.where(:id => Array.wrap(params[:object_id])).all
+      raise Unauthorized if @watchables.any? {|w|
+        if w.respond_to?(:visible?)
+          !w.visible?
+        elsif w.respond_to?(:project) && w.project
+          !w.project.visible?
+        end
+      }
     end
     render_404 unless @watchables.present?
   end
@@ -106,4 +113,17 @@
       format.js { render :partial => 'set_watcher', :locals => {:user => user, :watched => watchables} }
     end
   end
+
+  def users_for_new_watcher
+    users = []
+    if params[:q].blank? && @project.present?
+      users = @project.users.sorted
+    else
+      users = User.active.sorted.like(params[:q]).limit(100)
+    end
+    if @watched
+      users -= @watched.watcher_users
+    end
+    users
+  end
 end