From: Julien Lancelot Date: Tue, 10 Apr 2018 14:58:55 +0000 (+0200) Subject: SONAR-10569 Authorize to change default visibility of projects without organizations X-Git-Tag: 6.7.4~15 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=e518fae934aebbf5c8376d298a3f75024900cec1;p=sonarqube.git SONAR-10569 Authorize to change default visibility of projects without organizations --- diff --git a/server/sonar-server/src/main/java/org/sonar/server/organization/ws/OrganizationsWsModule.java b/server/sonar-server/src/main/java/org/sonar/server/organization/ws/OrganizationsWsModule.java index f27020591f8..a5f94963fb6 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/organization/ws/OrganizationsWsModule.java +++ b/server/sonar-server/src/main/java/org/sonar/server/organization/ws/OrganizationsWsModule.java @@ -40,7 +40,9 @@ public class OrganizationsWsModule extends Module { // actions SearchAction.class, SearchMembersAction.class, - SearchMyOrganizationsAction.class); + SearchMyOrganizationsAction.class, + // Update of project visibility is used on on-premise instances, not only on SonarCloud / Organizations + UpdateProjectVisibilityAction.class); if (config.getBoolean(SONARCLOUD_ENABLED).orElse(false)) { add( EnableSupportAction.class, @@ -48,8 +50,7 @@ public class OrganizationsWsModule extends Module { CreateAction.class, DeleteAction.class, RemoveMemberAction.class, - UpdateAction.class, - UpdateProjectVisibilityAction.class); + UpdateAction.class); } } diff --git a/server/sonar-server/src/test/java/org/sonar/server/organization/ws/OrganizationsWsModuleTest.java b/server/sonar-server/src/test/java/org/sonar/server/organization/ws/OrganizationsWsModuleTest.java index 66c96ce2047..89444a8c470 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/organization/ws/OrganizationsWsModuleTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/organization/ws/OrganizationsWsModuleTest.java @@ -39,7 +39,7 @@ public class OrganizationsWsModuleTest { underTest.configure(container); assertThat(container.getPicoContainer().getComponentAdapters()) - .hasSize(COMPONENTS_IN_EMPTY_COMPONENT_CONTAINER + 5); + .hasSize(COMPONENTS_IN_EMPTY_COMPONENT_CONTAINER + 6); } @Test diff --git a/tests/src/test/java/org/sonarqube/tests/Category1Suite.java b/tests/src/test/java/org/sonarqube/tests/Category1Suite.java index 836bd9807aa..14b616708af 100644 --- a/tests/src/test/java/org/sonarqube/tests/Category1Suite.java +++ b/tests/src/test/java/org/sonarqube/tests/Category1Suite.java @@ -26,6 +26,7 @@ import org.junit.runners.Suite; import org.sonarqube.tests.authorisation.ExecuteAnalysisPermissionTest; import org.sonarqube.tests.authorisation.IssuePermissionTest; import org.sonarqube.tests.authorisation.PermissionSearchTest; +import org.sonarqube.tests.authorisation.ProjectPermissionsTest; import org.sonarqube.tests.authorisation.ProvisioningPermissionTest; import org.sonarqube.tests.authorisation.QualityProfileAdminPermissionTest; import org.sonarqube.tests.complexity.ComplexityMeasuresTest; @@ -88,6 +89,7 @@ import static util.ItUtils.xooPlugin; PermissionSearchTest.class, ProvisioningPermissionTest.class, QualityProfileAdminPermissionTest.class, + ProjectPermissionsTest.class, // custom measure CustomMeasuresTest.class, // measure diff --git a/tests/src/test/java/org/sonarqube/tests/authorisation/ProjectPermissionsTest.java b/tests/src/test/java/org/sonarqube/tests/authorisation/ProjectPermissionsTest.java new file mode 100644 index 00000000000..93f593cec97 --- /dev/null +++ b/tests/src/test/java/org/sonarqube/tests/authorisation/ProjectPermissionsTest.java @@ -0,0 +1,96 @@ +/* + * SonarQube + * Copyright (C) 2009-2017 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program 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. + * + * This program 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.sonarqube.tests.authorisation; + +import com.sonar.orchestrator.Orchestrator; +import org.junit.ClassRule; +import org.junit.Rule; +import org.junit.Test; +import org.sonarqube.pageobjects.ProjectPermissionsPage; +import org.sonarqube.tests.Category1Suite; +import org.sonarqube.tests.Tester; +import org.sonarqube.ws.WsProjects.CreateWsResponse.Project; +import org.sonarqube.ws.WsUsers.CreateWsResponse.User; +import org.sonarqube.ws.client.component.ShowWsRequest; +import org.sonarqube.ws.client.organization.UpdateProjectVisibilityWsRequest; +import org.sonarqube.ws.client.project.UpdateVisibilityRequest; + +import static org.assertj.core.api.Assertions.assertThat; + +public class ProjectPermissionsTest { + + @ClassRule + public static Orchestrator orchestrator = Category1Suite.ORCHESTRATOR; + + @Rule + public Tester tester = new Tester(orchestrator).disableOrganizations(); + + @Test + public void change_project_visibility_from_ui() { + Project project = tester.projects().generate(null); + User administrator = tester.users().generateAdministrator(); + + ProjectPermissionsPage page = tester.openBrowser().logIn() + .submitCredentials(administrator.getLogin()) + .openProjectPermissions(project.getKey()); + + page + .shouldBePublic() + .turnToPrivate() + .shouldBePrivate() + .turnToPublic() + .shouldBePublic(); + } + + @Test + public void change_project_visibility_from_ws() { + Project project = tester.projects().generate(null); + assertThat(tester.wsClient().components().show(new ShowWsRequest().setKey(project.getKey())).getComponent().getVisibility()).isEqualTo("public"); + + tester.wsClient().projects().updateVisibility(UpdateVisibilityRequest.builder().setProject(project.getKey()).setVisibility("private").build()); + + assertThat(tester.wsClient().components().show(new ShowWsRequest().setKey(project.getKey())).getComponent().getVisibility()).isEqualTo("private"); + } + + /** + * SONAR-10569 + */ + @Test + public void change_default_project_visibility_from_ws() { + try { + tester.wsClient().organizations().updateProjectVisibility(UpdateProjectVisibilityWsRequest.builder() + .setOrganization(tester.organizations().getDefaultOrganization().getKey()) + .setProjectVisibility("private") + .build()); + + Project project = tester.projects().generate(null); + + assertThat(tester.wsClient().components().show(new ShowWsRequest().setKey(project.getKey())).getComponent().getVisibility()).isEqualTo("private"); + + } finally { + // Restore default visibility to public to not break other tests + tester.wsClient().organizations().updateProjectVisibility(UpdateProjectVisibilityWsRequest.builder() + .setOrganization(tester.organizations().getDefaultOrganization().getKey()) + .setProjectVisibility("public") + .build()); + } + } + +} diff --git a/tests/src/test/java/org/sonarqube/tests/projectAdministration/ProjectPermissionsTest.java b/tests/src/test/java/org/sonarqube/tests/projectAdministration/ProjectPermissionsTest.java deleted file mode 100644 index 2184a9a9506..00000000000 --- a/tests/src/test/java/org/sonarqube/tests/projectAdministration/ProjectPermissionsTest.java +++ /dev/null @@ -1,80 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2017 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program 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. - * - * This program 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.sonarqube.tests.projectAdministration; - -import com.sonar.orchestrator.Orchestrator; -import com.sonar.orchestrator.build.SonarScanner; -import org.sonarqube.tests.Category1Suite; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.ClassRule; -import org.junit.Rule; -import org.junit.Test; -import org.sonarqube.pageobjects.Navigation; -import org.sonarqube.pageobjects.ProjectPermissionsPage; -import util.user.UserRule; - -import static util.ItUtils.projectDir; -import static util.selenium.Selenese.runSelenese; - -public class ProjectPermissionsTest { - - @ClassRule - public static Orchestrator orchestrator = Category1Suite.ORCHESTRATOR; - - @Rule - public UserRule userRule = UserRule.from(orchestrator); - - private Navigation nav = Navigation.create(orchestrator); - private String adminUser; - - @BeforeClass - public static void beforeClass() { - executeBuild("project-permissions-project", "Test Project"); - executeBuild("project-permissions-project-2", "Another Test Project"); - } - - @Before - public void before() { - adminUser = userRule.createAdminUser(); - } - - @Test - public void test_project_permissions_page_shows_only_single_project() throws Exception { - runSelenese(orchestrator, "/projectAdministration/ProjectPermissionsTest/test_project_permissions_page_shows_only_single_project.html"); - } - - @Test - public void change_project_visibility() { - ProjectPermissionsPage page = nav.logIn().submitCredentials(adminUser).openProjectPermissions("project-permissions-project"); - page - .shouldBePublic() - .turnToPrivate() - .turnToPublic(); - } - - private static void executeBuild(String projectKey, String projectName) { - orchestrator.executeBuild( - SonarScanner.create(projectDir("shared/xoo-sample")) - .setProjectKey(projectKey) - .setProjectName(projectName) - ); - } -} diff --git a/tests/src/test/resources/projectAdministration/ProjectPermissionsTest/test_project_permissions_page_shows_only_single_project.html b/tests/src/test/resources/projectAdministration/ProjectPermissionsTest/test_project_permissions_page_shows_only_single_project.html deleted file mode 100644 index f0ba9552e9b..00000000000 --- a/tests/src/test/resources/projectAdministration/ProjectPermissionsTest/test_project_permissions_page_shows_only_single_project.html +++ /dev/null @@ -1,71 +0,0 @@ - - - - - - - test_project_overview_after_first_analysis - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
test_project_overview_after_first_analysis
open/sessions/login
typeloginadmin
typepasswordadmin
clickAndWaitcommit
waitForElementPresentcss=.js-user-authenticated
open/project_roles?id=project-permissions-project
waitForElementPresentcss=#projects
assertNotTextcss=#projects*Another Test Project*
assertElementNotPresentcss=footer
assertElementNotPresentcss=.search-box
- -