Feature #35507

API to close/reopen projects

Added by Go MAEDA 4 months ago. Updated 4 months ago.

Status:ClosedStart date:
Priority:NormalDue date:
Assignee:Go MAEDA% Done:

0%

Category:REST API
Target version:5.0.0
Resolution:Fixed

Description

API to archive/unarchive projects has been implemented for Redmine 5.0.0 (#35420). I think it is better to implement API to close/reopen projects as well.

This is because archive and close of a project are similar choices for admins. Depending on the situation, admins may want to archive a project, or close a project.

35507.patch Magnifier (2.71 KB) Yuichi HARADA, 2021-07-02 08:31


Related issues

Related to Redmine - Feature #13725: Archive/close a project via API Closed

Associated revisions

Revision 21066
Added by Go MAEDA 4 months ago

API to close/reopen projects (#35507).

Patch by Yuichi HARADA.

History

#1 Updated by Go MAEDA 4 months ago

#2 Updated by Yuichi HARADA 4 months ago

I have added API to close/reopen a project.

diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb
index 9d7d37bb15..445ff840f3 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 7e5e3eee93..1fd513d00e 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

#3 Updated by Go MAEDA 4 months ago

  • Target version set to Candidate for next major release

#4 Updated by Go MAEDA 4 months ago

  • Target version changed from Candidate for next major release to 5.0.0

Setting the target version to 5.0.0.

#5 Updated by Go MAEDA 4 months ago

  • Status changed from New to Closed
  • Assignee set to Go MAEDA
  • Resolution set to Fixed

Committed the patch. Thank you for your contribution.

Also available in: Atom PDF