defineIndexAction(controller);
defineCreateAction(controller);
- defineDestroyAction(controller);
for (ProjectsWsAction action : actions) {
action.define(controller);
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");
- }
-
}
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 {
@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");
}
assertThat(controller).isNotNull();
assertThat(controller.description()).isNotEmpty();
assertThat(controller.since()).isEqualTo("2.10");
- assertThat(controller.actions()).hasSize(3);
+ assertThat(controller.actions()).hasSize(5);
}
@Test
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);
- }
-
}
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>
#
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
+++ /dev/null
-/*
- * 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);
- }
-}
+++ /dev/null
-/*
- * 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"));
- }
-
-}