]> source.dussan.org Git - redmine.git/commitdiff
Include new statuses allowed by workflow in Issues REST API (#24976).
authorGo MAEDA <maeda@farend.jp>
Mon, 19 Apr 2021 09:04:24 +0000 (09:04 +0000)
committerGo MAEDA <maeda@farend.jp>
Mon, 19 Apr 2021 09:04:24 +0000 (09:04 +0000)
Patch by Yuichi HARADA.

git-svn-id: http://svn.redmine.org/redmine/trunk@20951 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/controllers/issues_controller.rb
app/views/issues/show.api.rsb
test/integration/api_test/issues_test.rb

index c994862e1b8633719c13a9a1a466e70682435394..887bcd4bb62209291ce09b86fa453666c3b0ee2b 100644 (file)
@@ -112,6 +112,7 @@ class IssuesController < ApplicationController
         render :template => 'issues/show'
       end
       format.api do
+        @allowed_statuses = @issue.new_statuses_allowed_to(User.current)
         @changesets = @issue.changesets.visible.preload(:repository, :user).to_a
         @changesets.reverse! if User.current.wants_comments_in_reverse_order?
       end
index f474ed9c6eb02d59651aa979442d1934576184ad..215184014462d8871adcd27032b4ba7913ce1465 100644 (file)
@@ -77,4 +77,10 @@ api.issue do
       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)
+
+  api.array :allowed_statuses do
+    @allowed_statuses.each do |status|
+      api.status :id => status.id, :name => status.name
+    end
+  end if include_in_api_response?('allowed_statuses')
 end
index b10f7dfa5f85fff1f9b10ba7cfe4b43703221e98..7a57d39feb5114c379d8fdf0c612fb73b855ecec 100644 (file)
@@ -394,6 +394,28 @@ class Redmine::ApiTest::IssuesTest < Redmine::ApiTest::Base
     end
   end
 
+  test "GET /issues/:id.xml?include=allowed_statuses should include available statuses" do
+    issue = Issue.find(1)
+    assert_equal 1, issue.tracker_id  # Bug
+    issue.update(:status_id => 2)     # Assigned
+    member = Member.find_or_new(issue.project, User.find_by_login('dlopper'))
+    assert_equal [2], member.role_ids # Developer
+
+    get '/issues/1.xml?include=allowed_statuses', :headers => credentials('dlopper', 'foo')
+    assert_response :ok
+    assert_equal 'application/xml', response.media_type
+
+    allowed_statuses = [[1, 'New'], [2, 'Assigned'], [4, 'Feedback'], [5, 'Closed'], [6, 'Rejected']]
+    assert_select 'issue allowed_statuses[type=array]' do
+      assert_select 'status', allowed_statuses.length
+      assert_select('status').each_with_index do |status, idx|
+        id, name, = allowed_statuses[idx]
+        assert_equal id.to_s, status['id']
+        assert_equal name, status['name']
+      end
+    end
+  end
+
   test "GET /issues/:id.xml should contains total_estimated_hours and total_spent_hours" do
     parent = Issue.find(3)
     parent.update_columns :estimated_hours => 2.0