]> source.dussan.org Git - sonarqube.git/commitdiff
Add API method to delete project.
authorGeorge Shakhnazaryan <george@shakhnazaryan.com>
Sat, 30 Jul 2011 18:20:22 +0000 (13:20 -0500)
committerGeorge Shakhnazaryan <george@shakhnazaryan.com>
Sat, 30 Jul 2011 18:20:22 +0000 (13:20 -0500)
sonar-server/src/main/webapp/WEB-INF/app/controllers/api/projects_controller.rb
sonar-server/src/main/webapp/WEB-INF/config/routes.rb

index ad53b529d7f934c44c8995ec05d7bf08a2b8de6c..34b0253a90b140554d3869e71a270aef499ae162 100644 (file)
@@ -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/<key>
+  # curl -X DELETE  http://localhost:9000/api/projects/<key> -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
   
index ba3c53ba26bdc180f398bfce47f2bfeea93a0ce5..02d72fb7868061e72353606673072bde31948227 100644 (file)
@@ -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,