From 7edcb366e27ba6f04eb9b4ccc5ff460659e19ad7 Mon Sep 17 00:00:00 2001 From: George Shakhnazaryan Date: Sat, 30 Jul 2011 13:20:22 -0500 Subject: Add API method to delete project. --- .../app/controllers/api/projects_controller.rb | 19 ++++++++++++++++++- sonar-server/src/main/webapp/WEB-INF/config/routes.rb | 1 + 2 files changed, 19 insertions(+), 1 deletion(-) (limited to 'sonar-server/src') diff --git a/sonar-server/src/main/webapp/WEB-INF/app/controllers/api/projects_controller.rb b/sonar-server/src/main/webapp/WEB-INF/app/controllers/api/projects_controller.rb index ad53b529d7f..34b0253a90b 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/controllers/api/projects_controller.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/controllers/api/projects_controller.rb @@ -18,6 +18,8 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02 # class Api::ProjectsController < Api::ApiController + + before_filter :admin_required, :only => [ :destroy ] # PARAMETERS # subprojects [true|false] : load sub-projects ? Default is false. Ignored if the parameter key is set. @@ -49,7 +51,22 @@ class Api::ProjectsController < Api::ApiController end end - + # + # DELETE /api/projects/ + # curl -X DELETE http://localhost:9000/api/projects/ -v -u admin:admin + # + def destroy + begin + if params[:id] + @project = Project.by_key(params[:id]) + Project.delete_project(@project) + end + render_success("Project deleted") + rescue Exception => e + logger.error("Fails to execute #{request.url} : #{e.message}") + render_error(e.message) + end + end private diff --git a/sonar-server/src/main/webapp/WEB-INF/config/routes.rb b/sonar-server/src/main/webapp/WEB-INF/config/routes.rb index ba3c53ba26b..02d72fb7868 100644 --- a/sonar-server/src/main/webapp/WEB-INF/config/routes.rb +++ b/sonar-server/src/main/webapp/WEB-INF/config/routes.rb @@ -10,6 +10,7 @@ ActionController::Routing::Routes.draw do |map| map.namespace :api do |api| api.resources :events, :only => [:index, :show, :create, :destroy] api.resources :user_properties, :only => [:index, :show, :create, :destroy], :requirements => { :id => /.*/ } + api.resources :projects, :only => [:index, :destroy], :requirements => { :id => /.*/ } api.resources :favorites, :only => [:index, :show, :create, :destroy], :requirements => { :id => /.*/ } api.resources :reviews, :only => [:index, :show, :create], :member => { :add_comment => :put, -- cgit v1.2.3