diff options
author | Grégoire Aubert <gregoire.aubert@sonarsource.com> | 2017-07-21 16:42:35 +0200 |
---|---|---|
committer | Grégoire Aubert <gregoire.aubert@sonarsource.com> | 2017-07-24 08:20:48 +0200 |
commit | 1b9c1f105c34d97090bbd4966105ea132b17c3dc (patch) | |
tree | af20c05ec064da109811983abb5e9c18d1ce0a8d | |
parent | e3e531c2383b6c7207afd2bb269ec67487dfa16b (diff) | |
download | sonarqube-1b9c1f105c34d97090bbd4966105ea132b17c3dc.tar.gz sonarqube-1b9c1f105c34d97090bbd4966105ea132b17c3dc.zip |
SONAR-9572 Fix bulk apply permission template
4 files changed, 43 insertions, 7 deletions
diff --git a/server/sonar-web/src/main/js/apps/projects-admin/search.js b/server/sonar-web/src/main/js/apps/projects-admin/search.js index 65e6e0fb9d3..8cc13cdf404 100644 --- a/server/sonar-web/src/main/js/apps/projects-admin/search.js +++ b/server/sonar-web/src/main/js/apps/projects-admin/search.js @@ -156,7 +156,9 @@ export default class Search extends React.PureComponent { </form> </td> <td className="thin nowrap text-middle"> - <button className="spacer-right" onClick={this.bulkApplyTemplate}> + <button + className="spacer-right js-bulk-apply-permission-template" + onClick={this.bulkApplyTemplate}> {translate('permission_templates.bulk_apply_permission_template')} </button> <button diff --git a/server/sonar-web/src/main/js/apps/projects-admin/views/BulkApplyTemplateView.js b/server/sonar-web/src/main/js/apps/projects-admin/views/BulkApplyTemplateView.js index 9769576cc53..ec5084a4621 100644 --- a/server/sonar-web/src/main/js/apps/projects-admin/views/BulkApplyTemplateView.js +++ b/server/sonar-web/src/main/js/apps/projects-admin/views/BulkApplyTemplateView.js @@ -73,8 +73,8 @@ export default ModalForm.extend({ const { selection } = this.options; let lastRequest = Promise.resolve(); - selection.forEach(projectId => { - const data = { templateId: permissionTemplate, projectId }; + selection.forEach(projectKey => { + const data = { templateId: permissionTemplate, projectKey }; if (this.options.organization) { data.organization = this.options.organization.key; } diff --git a/tests/src/test/java/org/sonarqube/pageobjects/ProjectsManagementPage.java b/tests/src/test/java/org/sonarqube/pageobjects/ProjectsManagementPage.java index ea5ff5c06db..eded1c27bfc 100644 --- a/tests/src/test/java/org/sonarqube/pageobjects/ProjectsManagementPage.java +++ b/tests/src/test/java/org/sonarqube/pageobjects/ProjectsManagementPage.java @@ -19,6 +19,8 @@ */ package org.sonarqube.pageobjects; +import com.codeborne.selenide.CollectionCondition; + import static com.codeborne.selenide.Condition.exist; import static com.codeborne.selenide.Condition.text; import static com.codeborne.selenide.Selenide.$; @@ -48,4 +50,14 @@ public class ProjectsManagementPage { $("#create-project-submit").submit(); return this; } + + public ProjectsManagementPage bulkApplyPermissionTemplate(String template) { + $(".js-bulk-apply-permission-template").should(exist).click(); + $(".modal .select2-choice").should(exist).click(); + $$(".select2-results li") + .shouldHave(CollectionCondition.sizeGreaterThan(0)) + .findBy(text("foo-template")).should(exist).click(); + $(".modal .js-apply").should(exist).click(); + return this; + } } diff --git a/tests/src/test/java/org/sonarqube/tests/projectAdministration/ProjectAdministrationTest.java b/tests/src/test/java/org/sonarqube/tests/projectAdministration/ProjectAdministrationTest.java index 7d46eb61e7c..89598145a91 100644 --- a/tests/src/test/java/org/sonarqube/tests/projectAdministration/ProjectAdministrationTest.java +++ b/tests/src/test/java/org/sonarqube/tests/projectAdministration/ProjectAdministrationTest.java @@ -21,6 +21,7 @@ package org.sonarqube.tests.projectAdministration; import com.sonar.orchestrator.Orchestrator; import com.sonar.orchestrator.build.SonarScanner; +import org.sonarqube.pageobjects.ProjectsManagementPage; import org.sonarqube.tests.Category1Suite; import java.io.UnsupportedEncodingException; import java.sql.SQLException; @@ -40,7 +41,10 @@ import org.sonar.wsclient.base.HttpException; import org.sonar.wsclient.user.UserParameters; import org.sonarqube.pageobjects.Navigation; import org.sonarqube.pageobjects.settings.SettingsPage; -import util.user.UserRule; +import org.sonarqube.tests.Tester; +import org.sonarqube.ws.client.permission.AddUserToTemplateWsRequest; +import org.sonarqube.ws.client.permission.CreateTemplateWsRequest; +import org.sonarqube.ws.client.permission.UsersWsRequest; import static org.apache.commons.lang.time.DateUtils.addDays; import static org.assertj.core.api.Assertions.assertThat; @@ -61,7 +65,7 @@ public class ProjectAdministrationTest { public ExpectedException expectedException = ExpectedException.none(); @Rule - public UserRule userRule = UserRule.from(orchestrator); + public Tester tester = new Tester(orchestrator); private Navigation nav = Navigation.create(orchestrator); @@ -72,7 +76,7 @@ public class ProjectAdministrationTest { @Before public void deleteAnalysisData() throws SQLException { orchestrator.resetData(); - adminUser = userRule.createAdminUser(); + adminUser = tester.users().generateAdministrator().getLogin(); } @Test @@ -197,6 +201,25 @@ public class ProjectAdministrationTest { .assertSettingDisplayed("sonar.coverage.exclusions"); } + @Test + public void bulk_apply_permission_template() { + String project = tester.projects().generate(null).getKey(); + String user = tester.users().generate().getLogin(); + tester.wsClient().permissions().createTemplate(new CreateTemplateWsRequest().setName("foo-template")); + tester.wsClient().permissions().addUserToTemplate( + new AddUserToTemplateWsRequest() + .setPermission("admin") + .setTemplateName("foo-template") + .setLogin(user)); + ProjectsManagementPage page = nav.logIn().submitCredentials(adminUser).openProjectsManagement(); + page.shouldHaveProject(project); + page.bulkApplyPermissionTemplate("foo-template"); + assertThat(tester.wsClient().permissions().users(new UsersWsRequest() + .setProjectKey(project) + .setPermission("admin") + ).getUsers(0).getLogin()).isEqualTo(user); + } + private void scanSampleWithDate(String date) { scanSample(date, null); } @@ -216,5 +239,4 @@ public class ProjectAdministrationTest { private int count(String condition) { return orchestrator.getDatabase().countSql("select count(1) from " + condition); } - } |