From: Go MAEDA Date: Thu, 24 Jun 2021 13:55:06 +0000 (+0000) Subject: API to archive/unarchive projects (#35420). X-Git-Tag: 5.0.0~365 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=890dc20ad749f1f9fa0fca41a2c23bb520be5008;p=redmine.git API to archive/unarchive projects (#35420). Patch by Felix Schäfer. git-svn-id: http://svn.redmine.org/redmine/trunk@21044 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index a2624031b..673c77316 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 + accept_api_auth :index, :show, :create, :update, :destroy, :archive, :unarchive require_sudo_mode :destroy helper :custom_fields @@ -233,16 +233,31 @@ class ProjectsController < ApplicationController def archive unless @project.archive - flash[:error] = l(:error_can_not_archive_project) + error = l(:error_can_not_archive_project) + end + respond_to do |format| + format.html do + flash[:error] = error if error + redirect_to_referer_or admin_projects_path(:status => params[:status]) + end + format.api do + if error + render_api_errors error + else + render_api_ok + end + end end - redirect_to_referer_or admin_projects_path(:status => params[:status]) end def unarchive unless @project.active? @project.unarchive end - redirect_to_referer_or admin_projects_path(:status => params[:status]) + respond_to do |format| + format.html{ redirect_to_referer_or admin_projects_path(:status => params[:status]) } + format.api{ render_api_ok } + end end def bookmark diff --git a/config/routes.rb b/config/routes.rb index dbcd8ddc7..7e5e3eee9 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -131,8 +131,8 @@ Rails.application.routes.draw do member do get 'settings(/:tab)', :action => 'settings', :as => 'settings' - post 'archive' - post 'unarchive' + match 'archive', :via => [:post, :put] + match 'unarchive', :via => [:post, :put] post 'close' post 'reopen' match 'copy', :via => [:get, :post] diff --git a/test/integration/api_test/projects_test.rb b/test/integration/api_test/projects_test.rb index 59b10efc3..1d8eb17eb 100644 --- a/test/integration/api_test/projects_test.rb +++ b/test/integration/api_test/projects_test.rb @@ -356,4 +356,21 @@ class Redmine::ApiTest::ProjectsTest < Redmine::ApiTest::Base assert_equal '', @response.body assert_nil Project.find_by_id(2) end + + test "PUT /projects/:id/archive.xml should archive project" do + put '/projects/1/archive.xml', :headers => credentials('admin') + assert_response :no_content + assert_equal '', @response.body + assert p = Project.find(1) + assert_not p.active? + end + + test "PUT /projects/:id/unarchive.xml should unarchive project" do + Project.find(1).update_column :status, Project::STATUS_ARCHIVED + put '/projects/1/unarchive.xml', :headers => credentials('admin') + assert_response :no_content + assert_equal '', @response.body + assert p = Project.find_by_id(2) + assert p.active? + end end