summaryrefslogtreecommitdiffstats
path: root/app/controllers/watchers_controller.rb
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2013-01-30 20:51:21 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2013-01-30 20:51:21 +0000
commita0158eff9643b836488bf40667669d07d8653429 (patch)
tree3bdf34a6bb3e2ad3114f3e0d3deaa371d5716abb /app/controllers/watchers_controller.rb
parentf2fd78f7b868c184e4ab2058e41a27043640843a (diff)
downloadredmine-a0158eff9643b836488bf40667669d07d8653429.tar.gz
redmine-a0158eff9643b836488bf40667669d07d8653429.zip
Add/remove issue watchers via the REST API (#6727).
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@11290 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app/controllers/watchers_controller.rb')
-rw-r--r--app/controllers/watchers_controller.rb18
1 files changed, 12 insertions, 6 deletions
diff --git a/app/controllers/watchers_controller.rb b/app/controllers/watchers_controller.rb
index e564d64ec..00d36f90c 100644
--- a/app/controllers/watchers_controller.rb
+++ b/app/controllers/watchers_controller.rb
@@ -19,6 +19,7 @@ class WatchersController < ApplicationController
before_filter :find_project
before_filter :require_login, :check_project_privacy, :only => [:watch, :unwatch]
before_filter :authorize, :only => [:new, :destroy]
+ accept_api_auth :create, :destroy
def watch
if @watched.respond_to?(:visible?) && !@watched.visible?(User.current)
@@ -36,15 +37,19 @@ class WatchersController < ApplicationController
end
def create
- if params[:watcher].is_a?(Hash) && request.post?
- user_ids = params[:watcher][:user_ids] || [params[:watcher][:user_id]]
- user_ids.each do |user_id|
- Watcher.create(:watchable => @watched, :user_id => user_id)
- end
+ user_ids = []
+ if params[:watcher].is_a?(Hash)
+ user_ids << (params[:watcher][:user_ids] || params[:watcher][:user_id])
+ else
+ user_ids << params[:user_id]
+ end
+ user_ids.flatten.compact.uniq.each do |user_id|
+ Watcher.create(:watchable => @watched, :user_id => user_id)
end
respond_to do |format|
format.html { redirect_to_referer_or {render :text => 'Watcher added.', :layout => true}}
format.js
+ format.api { render_api_ok }
end
end
@@ -56,10 +61,11 @@ class WatchersController < ApplicationController
end
def destroy
- @watched.set_watcher(User.find(params[:user_id]), false) if request.post?
+ @watched.set_watcher(User.find(params[:user_id]), false)
respond_to do |format|
format.html { redirect_to :back }
format.js
+ format.api { render_api_ok }
end
end