summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGo MAEDA <maeda@farend.jp>2021-07-09 02:42:47 +0000
committerGo MAEDA <maeda@farend.jp>2021-07-09 02:42:47 +0000
commit5fa84c0b4e0a04c9d212a0b2e2969cc72c4f7fe5 (patch)
treea019baecf5d304d9427fd65a1d8fb17166b8610c
parent9178bf733627a6808be72d98a7c47c6c2758c511 (diff)
downloadredmine-5fa84c0b4e0a04c9d212a0b2e2969cc72c4f7fe5.tar.gz
redmine-5fa84c0b4e0a04c9d212a0b2e2969cc72c4f7fe5.zip
API to close/reopen projects (#35507).
Patch by Yuichi HARADA. git-svn-id: http://svn.redmine.org/redmine/trunk@21066 e93f8b46-1217-0410-a6f0-8f06a7374b81
-rw-r--r--app/controllers/projects_controller.rb12
-rw-r--r--config/routes.rb4
-rw-r--r--test/integration/api_test/projects_test.rb17
3 files changed, 28 insertions, 5 deletions
diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb
index 9d7d37bb1..445ff840f 100644
--- a/app/controllers/projects_controller.rb
+++ b/app/controllers/projects_controller.rb
@@ -30,7 +30,7 @@ class ProjectsController < ApplicationController
before_action :authorize_global, :only => [:new, :create]
before_action :require_admin, :only => [:copy, :archive, :unarchive]
accept_rss_auth :index
- accept_api_auth :index, :show, :create, :update, :destroy, :archive, :unarchive
+ accept_api_auth :index, :show, :create, :update, :destroy, :archive, :unarchive, :close, :reopen
require_sudo_mode :destroy
helper :custom_fields
@@ -275,12 +275,18 @@ class ProjectsController < ApplicationController
def close
@project.close
- redirect_to project_path(@project)
+ respond_to do |format|
+ format.html { redirect_to project_path(@project) }
+ format.api { render_api_ok }
+ end
end
def reopen
@project.reopen
- redirect_to project_path(@project)
+ respond_to do |format|
+ format.html { redirect_to project_path(@project) }
+ format.api { render_api_ok }
+ end
end
# Delete @project
diff --git a/config/routes.rb b/config/routes.rb
index 7e5e3eee9..1fd513d00 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -133,8 +133,8 @@ Rails.application.routes.draw do
get 'settings(/:tab)', :action => 'settings', :as => 'settings'
match 'archive', :via => [:post, :put]
match 'unarchive', :via => [:post, :put]
- post 'close'
- post 'reopen'
+ match 'close', :via => [:post, :put]
+ match 'reopen', :via => [:post, :put]
match 'copy', :via => [:get, :post]
match 'bookmark', :via => [:delete, :post]
end
diff --git a/test/integration/api_test/projects_test.rb b/test/integration/api_test/projects_test.rb
index 1d8eb17eb..0785aecb5 100644
--- a/test/integration/api_test/projects_test.rb
+++ b/test/integration/api_test/projects_test.rb
@@ -373,4 +373,21 @@ class Redmine::ApiTest::ProjectsTest < Redmine::ApiTest::Base
assert p = Project.find_by_id(2)
assert p.active?
end
+
+ test "PUT /projects/:id/close.xml should close project" do
+ put '/projects/1/close.xml', :headers => credentials('admin')
+ assert_response :no_content
+ assert_equal '', @response.body
+ assert p = Project.find(1)
+ assert p.closed?
+ end
+
+ test "PUT /projects/:id/reopen.xml should reopen project" do
+ Project.find(1).update_column :status, Project::STATUS_CLOSED
+ put '/projects/1/reopen.xml', :headers => credentials('admin')
+ assert_response :no_content
+ assert_equal '', @response.body
+ assert p = Project.find(1)
+ assert p.active?
+ end
end