From: Teryk Bellahsene Date: Tue, 19 May 2015 15:41:47 +0000 (+0200) Subject: remove the api/projects/destroy WS - SONAR-6531 X-Git-Tag: 5.2-RC1~1893 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=3051f394a266a47b73e3265a33fa4952f64734dc;p=sonarqube.git remove the api/projects/destroy WS - SONAR-6531 --- diff --git a/server/sonar-server/src/main/java/org/sonar/server/project/ws/ProjectsWs.java b/server/sonar-server/src/main/java/org/sonar/server/project/ws/ProjectsWs.java index 8c70d269a6b..6f96f2b5bbb 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/project/ws/ProjectsWs.java +++ b/server/sonar-server/src/main/java/org/sonar/server/project/ws/ProjectsWs.java @@ -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"); - } - } diff --git a/server/sonar-server/src/test/java/org/sonar/server/project/ws/ProjectsWsTest.java b/server/sonar-server/src/test/java/org/sonar/server/project/ws/ProjectsWsTest.java index 7bd3f1d0aa3..3dbe27a988d 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/project/ws/ProjectsWsTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/project/ws/ProjectsWsTest.java @@ -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); - } - } diff --git a/server/sonar-web/src/main/webapp/WEB-INF/app/controllers/api/projects_controller.rb b/server/sonar-web/src/main/webapp/WEB-INF/app/controllers/api/projects_controller.rb index cfd97e37cb5..cac85bb1e1d 100644 --- a/server/sonar-web/src/main/webapp/WEB-INF/app/controllers/api/projects_controller.rb +++ b/server/sonar-web/src/main/webapp/WEB-INF/app/controllers/api/projects_controller.rb @@ -51,22 +51,6 @@ class Api::ProjectsController < Api::ApiController end end - # - # DELETE /api/projects/ - # curl -X DELETE http://localhost:9000/api/projects/ -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=&name= # diff --git a/server/sonar-web/src/main/webapp/WEB-INF/config/routes.rb b/server/sonar-web/src/main/webapp/WEB-INF/config/routes.rb index 442ebdce8b5..6f17f4f61b0 100644 --- a/server/sonar-web/src/main/webapp/WEB-INF/config/routes.rb +++ b/server/sonar-web/src/main/webapp/WEB-INF/config/routes.rb @@ -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 index 287fec55535..00000000000 --- a/server/sonar-ws-client/src/main/java/org/sonar/wsclient/services/ProjectDeleteQuery.java +++ /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 index 0fd85abbe10..00000000000 --- a/server/sonar-ws-client/src/test/java/org/sonar/wsclient/services/ProjectDeleteQueryTest.java +++ /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")); - } - -}