]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-9572 Fix bulk apply permission template
authorGrégoire Aubert <gregoire.aubert@sonarsource.com>
Fri, 21 Jul 2017 14:42:35 +0000 (16:42 +0200)
committerGrégoire Aubert <gregoire.aubert@sonarsource.com>
Mon, 24 Jul 2017 06:20:48 +0000 (08:20 +0200)
server/sonar-web/src/main/js/apps/projects-admin/search.js
server/sonar-web/src/main/js/apps/projects-admin/views/BulkApplyTemplateView.js
tests/src/test/java/org/sonarqube/pageobjects/ProjectsManagementPage.java
tests/src/test/java/org/sonarqube/tests/projectAdministration/ProjectAdministrationTest.java

index 65e6e0fb9d320cad6ff9673d2c0735d62da0d0e5..8cc13cdf404aee7f43f4086d0ad58a617ec7a278 100644 (file)
@@ -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
index 9769576cc531fe00bca6787b69185a2d6220261a..ec5084a4621f1e5178b437c81f984be1788fa788 100644 (file)
@@ -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;
       }
index ea5ff5c06db622d949c3c62eae5177ce7a814750..eded1c27bfc5db58886f38485a96fba29a80c7ac 100644 (file)
@@ -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;
+  }
 }
index 7d46eb61e7cd4950eae6118a82d7a0b279843b0e..89598145a91d211169bdcc608071bc950aa18a4e 100644 (file)
@@ -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);
   }
-
 }