From a4ee2963fbd509b7e16c8fce663d1b2bd63024d9 Mon Sep 17 00:00:00 2001 From: Go MAEDA Date: Fri, 26 Mar 2021 04:37:14 +0000 Subject: [PATCH] Associated Revision API (#22008). Patch by Yuichi HARADA. git-svn-id: http://svn.redmine.org/redmine/trunk@20852 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/controllers/repositories_controller.rb | 15 +++++++++++++-- test/integration/api_test/api_routing_test.rb | 5 +++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb index caa6a29b4..73929c1df 100644 --- a/app/controllers/repositories_controller.rb +++ b/app/controllers/repositories_controller.rb @@ -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 diff --git a/test/integration/api_test/api_routing_test.rb b/test/integration/api_test/api_routing_test.rb index 9c5da6adf..5e2b6d85a 100644 --- a/test/integration/api_test/api_routing_test.rb +++ b/test/integration/api_test/api_routing_test.rb @@ -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' -- 2.39.5