summaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2011-11-20 14:17:43 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2011-11-20 14:17:43 +0000
commit053adaef52d795e5a3ef134381dd378e40856775 (patch)
tree3d467d8e9ed996a4f1495ac3c2443a1517f9451d /app
parent8b5b928b9236f09f029915d755bde23b3e8fabb5 (diff)
downloadredmine-053adaef52d795e5a3ef134381dd378e40856775.tar.gz
redmine-053adaef52d795e5a3ef134381dd378e40856775.zip
Adds API response to /trackers to get the list of all available trackers (#7181).
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@7877 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app')
-rw-r--r--app/controllers/application_controller.rb13
-rw-r--r--app/controllers/trackers_controller.rb15
-rw-r--r--app/views/trackers/index.api.rsb8
3 files changed, 33 insertions, 3 deletions
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb
index bf05db034..f031ac292 100644
--- a/app/controllers/application_controller.rb
+++ b/app/controllers/application_controller.rb
@@ -314,6 +314,19 @@ class ApplicationController < ActionController::Base
format.json { head @status }
end
end
+
+ # Filter for actions that provide an API response
+ # but have no HTML representation for non admin users
+ def require_admin_or_api_request
+ return true if api_request?
+ if User.current.admin?
+ true
+ elsif User.current.logged?
+ render_error(:status => 406)
+ else
+ deny_access
+ end
+ end
# Picks which layout to use based on the request
#
diff --git a/app/controllers/trackers_controller.rb b/app/controllers/trackers_controller.rb
index 5275b32eb..2f827af2e 100644
--- a/app/controllers/trackers_controller.rb
+++ b/app/controllers/trackers_controller.rb
@@ -18,13 +18,22 @@
class TrackersController < ApplicationController
layout 'admin'
- before_filter :require_admin
+ before_filter :require_admin, :except => :index
+ before_filter :require_admin_or_api_request, :only => :index
+ accept_api_auth :index
verify :method => :post, :only => :destroy, :redirect_to => { :action => :index }
def index
- @tracker_pages, @trackers = paginate :trackers, :per_page => 10, :order => 'position'
- render :action => "index", :layout => false if request.xhr?
+ respond_to do |format|
+ format.html {
+ @tracker_pages, @trackers = paginate :trackers, :per_page => 10, :order => 'position'
+ render :action => "index", :layout => false if request.xhr?
+ }
+ format.api {
+ @trackers = Tracker.all
+ }
+ end
end
def new
diff --git a/app/views/trackers/index.api.rsb b/app/views/trackers/index.api.rsb
new file mode 100644
index 000000000..a37c552a8
--- /dev/null
+++ b/app/views/trackers/index.api.rsb
@@ -0,0 +1,8 @@
+api.array :trackers do
+ @trackers.each do |tracker|
+ api.tracker do
+ api.id tracker.id
+ api.name tracker.name
+ end
+ end
+end