Project

General

Profile

Feature #35420 » 35420.patch

Felix Schäfer, 2021-06-16 10:38

View differences:

app/controllers/projects_controller.rb
30 30
  before_action :authorize_global, :only => [:new, :create]
31 31
  before_action :require_admin, :only => [:copy, :archive, :unarchive]
32 32
  accept_rss_auth :index
33
  accept_api_auth :index, :show, :create, :update, :destroy
33
  accept_api_auth :index, :show, :create, :update, :destroy, :archive, :unarchive
34 34
  require_sudo_mode :destroy
35 35

  
36 36
  helper :custom_fields
......
233 233

  
234 234
  def archive
235 235
    unless @project.archive
236
      flash[:error] = l(:error_can_not_archive_project)
236
      error = l(:error_can_not_archive_project)
237
    end
238
    respond_to do |format|
239
      format.html do
240
        flash[:error] = error if error
241
        redirect_to_referer_or admin_projects_path(:status => params[:status])
242
      end
243
      format.api do
244
        if error
245
          render_api_errors error
246
        else
247
          render_api_ok
248
        end
249
      end
237 250
    end
238
    redirect_to_referer_or admin_projects_path(:status => params[:status])
239 251
  end
240 252

  
241 253
  def unarchive
242 254
    unless @project.active?
243 255
      @project.unarchive
244 256
    end
245
    redirect_to_referer_or admin_projects_path(:status => params[:status])
257
    respond_to do |format|
258
      format.html{ redirect_to_referer_or admin_projects_path(:status => params[:status]) }
259
      format.api{ render_api_ok }
260
    end
246 261
  end
247 262

  
248 263
  def bookmark
config/routes.rb
131 131

  
132 132
    member do
133 133
      get 'settings(/:tab)', :action => 'settings', :as => 'settings'
134
      post 'archive'
135
      post 'unarchive'
134
      match 'archive', :via => [:post, :put]
135
      match 'unarchive', :via => [:post, :put]
136 136
      post 'close'
137 137
      post 'reopen'
138 138
      match 'copy', :via => [:get, :post]
test/integration/api_test/projects_test.rb
356 356
    assert_equal '', @response.body
357 357
    assert_nil Project.find_by_id(2)
358 358
  end
359

  
360
  test "PUT /projects/:id/archive.xml should archive project" do
361
    put '/projects/1/archive.xml', :headers => credentials('admin')
362
    assert_response :no_content
363
    assert_equal '', @response.body
364
    assert p = Project.find(1)
365
    refute p.active?
366
  end
367

  
368
  test "PUT /projects/:id/unarchive.xml should unarchive project" do
369
    Project.find(1).update_column :status, Project::STATUS_ARCHIVED
370
    put '/projects/1/unarchive.xml', :headers => credentials('admin')
371
    assert_response :no_content
372
    assert_equal '', @response.body
373
    assert p = Project.find_by_id(2)
374
    assert p.active?
375
  end
359 376
end
    (1-1/1)