]> source.dussan.org Git - redmine.git/commitdiff
Adds API response to /issue_statuses to get the list of all available statuses (...
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Sun, 20 Nov 2011 14:25:58 +0000 (14:25 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Sun, 20 Nov 2011 14:25:58 +0000 (14:25 +0000)
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@7878 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/controllers/issue_statuses_controller.rb
app/views/issue_statuses/index.api.rsb [new file with mode: 0644]
config/routes.rb
test/functional/issue_statuses_controller_test.rb
test/integration/api_test/issue_statuses_test.rb [new file with mode: 0644]

index 0be67f40151f70337a07a9e73fecc4d335e6bd43..1f747a4f3c2b9aecc560ca26157feff0653cc3ca 100644 (file)
 class IssueStatusesController < 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, :create, :update, :move, :update_issue_done_ratio ],
          :redirect_to => { :action => :index }
 
   def index
-    @issue_status_pages, @issue_statuses = paginate :issue_statuses, :per_page => 25, :order => "position"
-    render :action => "index", :layout => false if request.xhr?
+    respond_to do |format|
+      format.html {
+        @issue_status_pages, @issue_statuses = paginate :issue_statuses, :per_page => 25, :order => "position"
+        render :action => "index", :layout => false if request.xhr?
+      }
+      format.api {
+        @issue_statuses = IssueStatus.all(:order => 'position')
+      }
+    end
   end
 
   def new
diff --git a/app/views/issue_statuses/index.api.rsb b/app/views/issue_statuses/index.api.rsb
new file mode 100644 (file)
index 0000000..8a51674
--- /dev/null
@@ -0,0 +1,10 @@
+api.array :issue_statuses do
+  @issue_statuses.each do |status|
+    api.issue_status do
+      api.id status.id
+      api.name status.name
+      api.is_default status.is_default
+      api.is_closed status.is_closed
+    end
+  end
+end
index 209db1e893b27562d232505bf626939e16700940..7106be9d5879d8eecb6a8087280d0c21bdeb81ab 100644 (file)
@@ -228,6 +228,7 @@ ActionController::Routing::Routes.draw do |map|
 
   #left old routes at the bottom for backwards compat
   map.connect 'trackers.:format', :controller => 'trackers', :action => 'index'
+  map.connect 'issue_statuses.:format', :controller => 'issue_statuses', :action => 'index'
   map.connect 'projects/:project_id/issues/:action', :controller => 'issues'
   map.connect 'projects/:project_id/documents/:action', :controller => 'documents'
   map.connect 'projects/:project_id/boards/:action/:id', :controller => 'boards'
index c03f30866f0c3cd44121ba8c8b3d632fc2244d6e..d49232605395a3ad5da2d3910715efe51fe80645 100644 (file)
@@ -21,6 +21,18 @@ class IssueStatusesControllerTest < ActionController::TestCase
     assert_response :success
     assert_template 'index'
   end
+  
+  def test_index_by_anonymous_should_redirect_to_login_form
+    @request.session[:user_id] = nil
+    get :index
+    assert_redirected_to '/login?back_url=http%3A%2F%2Ftest.host%2Fissue_statuses'
+  end
+  
+  def test_index_by_user_should_respond_with_406
+    @request.session[:user_id] = 2
+    get :index
+    assert_response 406
+  end
 
   def test_new
     get :new
diff --git a/test/integration/api_test/issue_statuses_test.rb b/test/integration/api_test/issue_statuses_test.rb
new file mode 100644 (file)
index 0000000..ed5996b
--- /dev/null
@@ -0,0 +1,51 @@
+# Redmine - project management software
+# Copyright (C) 2006-2011  Jean-Philippe Lang
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+
+require File.expand_path('../../../test_helper', __FILE__)
+
+class ApiTest::IssueStatusesTest < ActionController::IntegrationTest
+  fixtures :issue_statuses
+
+  def setup
+    Setting.rest_api_enabled = '1'
+  end
+
+  context "/issue_statuses" do
+    context "GET" do
+
+      should "return issue statuses" do
+        get '/issue_statuses.xml'
+
+        assert_response :success
+        assert_equal 'application/xml', @response.content_type
+        assert_tag :tag => 'issue_statuses',
+          :attributes => {:type => 'array'},
+          :child => {
+            :tag => 'issue_status',
+            :child => {
+              :tag => 'id',
+              :content => '2',
+              :sibling => {
+                :tag => 'name',
+                :content => 'Assigned'
+              }
+            }
+          }
+      end
+    end
+  end
+end