summaryrefslogtreecommitdiffstats
path: root/app
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
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')
-rw-r--r--app/controllers/watchers_controller.rb18
-rw-r--r--app/views/issues/show.api.rsb6
2 files changed, 18 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
diff --git a/app/views/issues/show.api.rsb b/app/views/issues/show.api.rsb
index 441d1442e..7363937f5 100644
--- a/app/views/issues/show.api.rsb
+++ b/app/views/issues/show.api.rsb
@@ -64,4 +64,10 @@ api.issue do
end
end
end if include_in_api_response?('journals')
+
+ api.array :watchers do
+ @issue.watcher_users.each do |user|
+ api.user :id => user.id, :name => user.name
+ end
+ end if include_in_api_response?('watchers') && User.current.allowed_to?(:view_issue_watchers, @issue.project)
end