]> source.dussan.org Git - sonarqube.git/commitdiff
remove the api/projects/destroy WS - SONAR-6531
authorTeryk Bellahsene <teryk.bellahsene@sonarsource.com>
Tue, 19 May 2015 15:41:47 +0000 (17:41 +0200)
committerTeryk Bellahsene <teryk.bellahsene@sonarsource.com>
Wed, 20 May 2015 13:24:09 +0000 (15:24 +0200)
server/sonar-server/src/main/java/org/sonar/server/project/ws/ProjectsWs.java
server/sonar-server/src/test/java/org/sonar/server/project/ws/ProjectsWsTest.java
server/sonar-web/src/main/webapp/WEB-INF/app/controllers/api/projects_controller.rb
server/sonar-web/src/main/webapp/WEB-INF/config/routes.rb
server/sonar-ws-client/src/main/java/org/sonar/wsclient/services/ProjectDeleteQuery.java [deleted file]
server/sonar-ws-client/src/test/java/org/sonar/wsclient/services/ProjectDeleteQueryTest.java [deleted file]

index 8c70d269a6b42e23992b3c853c1951a3f2720728..6f96f2b5bbb1517651b15bd15db8044bb274bc56 100644 (file)
@@ -41,7 +41,6 @@ public class ProjectsWs implements WebService {
 
     defineIndexAction(controller);
     defineCreateAction(controller);
-    defineDestroyAction(controller);
 
     for (ProjectsWsAction action : actions) {
       action.define(controller);
@@ -118,18 +117,4 @@ public class ProjectsWs implements WebService {
 
     RailsHandler.addFormatParam(action);
   }
-
-  private void defineDestroyAction(NewController controller) {
-    WebService.NewAction action = controller.createAction("destroy")
-      .setDescription("Delete a project. Requires Administer System permission")
-      .setSince("2.11")
-      .setPost(true)
-      .setHandler(RailsHandler.INSTANCE);
-
-    action.createParam("id")
-      .setDescription("id or key of the resource (ie: component)")
-      .setRequired(true)
-      .setExampleValue("org.codehaus.sonar:sonar");
-  }
-
 }
index 7bd3f1d0aa3ae7509d27a75829a49ee51f18ca4a..3dbe27a988d3db0ff8f001aecf46117aa78f2b11 100644 (file)
@@ -24,9 +24,13 @@ import org.junit.Before;
 import org.junit.Test;
 import org.sonar.api.server.ws.RailsHandler;
 import org.sonar.api.server.ws.WebService;
+import org.sonar.server.component.ComponentCleanerService;
+import org.sonar.server.db.DbClient;
+import org.sonar.server.user.UserSession;
 import org.sonar.server.ws.WsTester;
 
 import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.Mockito.mock;
 
 public class ProjectsWsTest {
 
@@ -35,7 +39,11 @@ public class ProjectsWsTest {
 
   @Before
   public void setUp() {
-    ws = new WsTester(new ProjectsWs());
+    ws = new WsTester(new ProjectsWs(
+      new DeleteAction(mock(ComponentCleanerService.class), mock(DbClient.class), mock(UserSession.class)),
+      new GhostsAction(mock(DbClient.class), mock(UserSession.class)),
+      new ProvisionedAction(mock(DbClient.class), mock(UserSession.class))
+    ));
     controller = ws.controller("api/projects");
   }
 
@@ -44,7 +52,7 @@ public class ProjectsWsTest {
     assertThat(controller).isNotNull();
     assertThat(controller.description()).isNotEmpty();
     assertThat(controller.since()).isEqualTo("2.10");
-    assertThat(controller.actions()).hasSize(3);
+    assertThat(controller.actions()).hasSize(5);
   }
 
   @Test
@@ -64,13 +72,4 @@ public class ProjectsWsTest {
     assertThat(action.responseExampleAsString()).isNotEmpty();
     assertThat(action.params()).hasSize(4);
   }
-
-  @Test
-  public void define_destroy_action() {
-    WebService.Action action = controller.action("destroy");
-    assertThat(action).isNotNull();
-    assertThat(action.handler()).isInstanceOf(RailsHandler.class);
-    assertThat(action.params()).hasSize(1);
-  }
-
 }
index cfd97e37cb5af81a9734320bec7fda553cbd63c7..cac85bb1e1d1ab6780c05534703e1cfa2ee6e6b3 100644 (file)
@@ -51,22 +51,6 @@ 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
-    bad_request("Missing project key") unless params[:id].present?
-
-    project = Project.by_key(params[:id])
-    bad_request("Not valid project") unless project
-    access_denied unless is_admin?(project)
-    bad_request("Not valid project") unless java_facade.getResourceTypeBooleanProperty(project.qualifier, 'deletable')
-
-    Project.delete_resource_tree(project)
-    render_success("Project deleted")
-  end
-
   #
   # POST /api/projects/create?key=<key>&name=<name>
   #
index 442ebdce8b5362e4b18b44dab19906075fde9146..6f17f4f61b0663ab28cc42a11ebaa446b69f7099 100644 (file)
@@ -8,7 +8,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 :projects, :only => [:index], :requirements => { :id => /.*/ }
     api.resources :favourites, :only => [:index, :show, :create, :destroy], :requirements => { :id => /.*/ }
     api.resources :manual_measures, :only => [:index, :create, :destroy], :requirements => { :id => /.*/ }
   end
diff --git a/server/sonar-ws-client/src/main/java/org/sonar/wsclient/services/ProjectDeleteQuery.java b/server/sonar-ws-client/src/main/java/org/sonar/wsclient/services/ProjectDeleteQuery.java
deleted file mode 100644 (file)
index 287fec5..0000000
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * SonarQube is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- */
-package org.sonar.wsclient.services;
-
-/**
- * @since 2.11
- */
-public final class ProjectDeleteQuery extends DeleteQuery {
-
-  private String key;
-  private static final String BASE_URL = "/api/projects/";
-
-  private ProjectDeleteQuery(String key) {
-    this.key = key;
-  }
-
-  public String getKey() {
-    return key;
-  }
-
-  @Override
-  public String getUrl() {
-    StringBuilder url = new StringBuilder();
-    url.append(BASE_URL);
-    url.append(encode(key));
-    return url.toString();
-  }
-
-  public static ProjectDeleteQuery create(String projectKeyOrId) {
-    return new ProjectDeleteQuery(projectKeyOrId);
-  }
-}
diff --git a/server/sonar-ws-client/src/test/java/org/sonar/wsclient/services/ProjectDeleteQueryTest.java b/server/sonar-ws-client/src/test/java/org/sonar/wsclient/services/ProjectDeleteQueryTest.java
deleted file mode 100644 (file)
index 0fd85ab..0000000
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * SonarQube is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- */
-package org.sonar.wsclient.services;
-
-import org.junit.Test;
-import static org.hamcrest.core.Is.is;
-import static org.junit.Assert.assertThat;
-
-public class ProjectDeleteQueryTest extends QueryTestCase {
-
-  @Test
-  public void testUrl() {
-    ProjectDeleteQuery query = ProjectDeleteQuery.create("my:project");
-    assertThat(query.getUrl(), is("/api/projects/my%3Aproject"));
-  }
-
-}