]> source.dussan.org Git - redmine.git/commitdiff
Associated Revision API (#22008).
authorGo MAEDA <maeda@farend.jp>
Fri, 26 Mar 2021 04:37:14 +0000 (04:37 +0000)
committerGo MAEDA <maeda@farend.jp>
Fri, 26 Mar 2021 04:37:14 +0000 (04:37 +0000)
Patch by Yuichi HARADA.

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

app/controllers/repositories_controller.rb
test/integration/api_test/api_routing_test.rb

index caa6a29b4c50deadda1839d167b820e5e27f5c3a..73929c1dfb3ee58e4a7e87b0946fa8a1205d7fb2 100644 (file)
@@ -35,6 +35,7 @@ class RepositoriesController < ApplicationController
   before_action :find_changeset, :only => [:revision, :add_related_issue, :remove_related_issue]
   before_action :authorize
   accept_rss_auth :revisions
+  accept_api_auth :add_related_issue, :remove_related_issue
 
   rescue_from Redmine::Scm::Adapters::CommandFailed, :with => :show_error_command_failed
 
@@ -233,8 +234,14 @@ class RepositoriesController < ApplicationController
       @issue = nil
     end
 
-    if @issue
-      @changeset.issues << @issue
+    respond_to do |format|
+      if @issue
+        @changeset.issues << @issue
+        format.api { render_api_ok }
+      else
+        format.api { render_api_errors "#{l(:label_issue)} #{l('activerecord.errors.messages.invalid')}" }
+      end
+      format.js
     end
   end
 
@@ -245,6 +252,10 @@ class RepositoriesController < ApplicationController
     if @issue
       @changeset.issues.delete(@issue)
     end
+    respond_to do |format|
+      format.api { render_api_ok }
+      format.js
+    end
   end
 
   def diff
index 9c5da6adf1ef579b4fe0654cdcc9258a1031500c..5e2b6d85a7a6df135303863ac300bc2f63d70ea5 100644 (file)
@@ -117,6 +117,11 @@ class Redmine::ApiTest::ApiRoutingTest < Redmine::ApiTest::Routing
     should_route 'GET /queries' => 'queries#index'
   end
 
+  def test_repositories
+    should_route 'POST /projects/1/repository/2/revisions/3/issues' => 'repositories#add_related_issue', :id => '1', :repository_id => '2', :rev => '3'
+    should_route 'DELETE /projects/1/repository/2/revisions/3/issues/4' => 'repositories#remove_related_issue', :id => '1', :repository_id => '2', :rev => '3', :issue_id => '4'
+  end
+
   def test_roles
     should_route 'GET /roles' => 'roles#index'
     should_route 'GET /roles/2' => 'roles#show', :id => '2'