diff options
author | George Shakhnazaryan <george@shakhnazaryan.com> | 2011-07-30 13:21:23 -0500 |
---|---|---|
committer | George Shakhnazaryan <george@shakhnazaryan.com> | 2011-07-30 13:21:23 -0500 |
commit | 73fdea8e690d54b68286b3389c254c1393a64f9e (patch) | |
tree | 1cbcbc773cb4553d83eb83ea96a603532f9f86dd /sonar-server/src | |
parent | 570028a3b3be614e04a0329d33dbda532c875977 (diff) | |
parent | 7edcb366e27ba6f04eb9b4ccc5ff460659e19ad7 (diff) | |
download | sonarqube-73fdea8e690d54b68286b3389c254c1393a64f9e.tar.gz sonarqube-73fdea8e690d54b68286b3389c254c1393a64f9e.zip |
Merge branch 'delete_resource_via_api'
Diffstat (limited to 'sonar-server/src')
4 files changed, 25 insertions, 3 deletions
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/<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 diff --git a/sonar-server/src/main/webapp/WEB-INF/app/controllers/project_controller.rb b/sonar-server/src/main/webapp/WEB-INF/app/controllers/project_controller.rb index 00be0035799..79ae8f0ed59 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/controllers/project_controller.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/controllers/project_controller.rb @@ -31,8 +31,7 @@ class ProjectController < ApplicationController if params[:id] @project = Project.by_key(params[:id]) if @project && is_admin?(@project) - Snapshot.update_all(['islast=?', false], ['(root_project_id=? OR project_id=?) AND islast=?', @project.id, @project.id, true]) - Project.delete_all(['id=? OR root_id=? or copy_resource_id=?', @project.id, @project.id, @project.id]) + Project.delete_project(@project) end end redirect_to_default diff --git a/sonar-server/src/main/webapp/WEB-INF/app/models/project.rb b/sonar-server/src/main/webapp/WEB-INF/app/models/project.rb index 5c7273c0296..5fd8dde7209 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/models/project.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/models/project.rb @@ -39,6 +39,11 @@ class Project < ActiveRecord::Base Project.find(:first, :conditions => {:kee => k}) end end + + def self.delete_project(project) + Snapshot.update_all(['islast=?', false], ['(root_project_id=? OR project_id=?) AND islast=?', project.id, project.id, true]) + Project.delete_all(['id=? OR root_id=? or copy_resource_id=?', project.id, project.id, project.id]) + end def project root||self 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 e0e0afe2416..178dd80df2f 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 :manual_measures, :only => [:index, :create, :destroy], :requirements => { :id => /.*/ } api.resources :reviews, :only => [:index, :show, :create], :member => { |