]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-13999 remove orgs from permission WS
authorMichal Duda <michal.duda@sonarsource.com>
Fri, 11 Dec 2020 17:52:10 +0000 (18:52 +0100)
committersonartech <sonartech@sonarsource.com>
Tue, 22 Dec 2020 20:09:36 +0000 (20:09 +0000)
32 files changed:
server/sonar-ce/src/test/java/org/sonar/ce/notification/ReportAnalysisFailureNotificationExecutionListenerTest.java
server/sonar-db-dao/src/main/java/org/sonar/db/organization/DefaultTemplates.java [deleted file]
server/sonar-db-dao/src/main/java/org/sonar/db/organization/OrganizationDao.java
server/sonar-db-dao/src/main/java/org/sonar/db/organization/OrganizationMapper.java
server/sonar-db-dao/src/main/java/org/sonar/db/permission/template/DefaultTemplates.java [new file with mode: 0644]
server/sonar-db-dao/src/main/resources/org/sonar/db/organization/OrganizationMapper.xml
server/sonar-db-dao/src/test/java/org/sonar/db/organization/DefaultTemplatesTest.java [deleted file]
server/sonar-db-dao/src/test/java/org/sonar/db/permission/template/DefaultTemplatesTest.java [new file with mode: 0644]
server/sonar-db-dao/src/testFixtures/java/org/sonar/db/component/ComponentTesting.java
server/sonar-db-dao/src/testFixtures/java/org/sonar/db/organization/OrganizationDbTester.java
server/sonar-webserver-auth/src/main/java/org/sonar/server/organization/OrganizationUpdaterImpl.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/DefaultTemplatesResolver.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/PermissionUpdater.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/AddUserAction.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/template/AddProjectCreatorToTemplateAction.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/template/AddUserToTemplateAction.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/template/BulkApplyTemplateAction.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/template/CreateTemplateAction.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/template/RemoveProjectCreatorFromTemplateAction.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/template/RemoveUserFromTemplateAction.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/PermissionTemplateServiceTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/UserPermissionChangerTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/ws/AddGroupActionTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/ws/AddUserActionTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/ws/BasePermissionWsTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/ws/GroupsActionTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/ws/SearchProjectPermissionsActionTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/ws/template/BulkApplyTemplateActionTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/ws/template/CreateTemplateActionTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/ws/template/TemplateGroupsActionTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/ws/template/TemplateUsersActionTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/ws/template/UpdateTemplateActionTest.java

index 961d03238c04acde456dc099180205eb0882421d..8e02119265dcf91261814857d89205d84cb90e30 100644 (file)
@@ -69,17 +69,17 @@ public class ReportAnalysisFailureNotificationExecutionListenerTest {
   public ExpectedException expectedException = ExpectedException.none();
 
   private final Random random = new Random();
-  private DbClient dbClient = dbTester.getDbClient();
-  private NotificationService notificationService = mock(NotificationService.class);
-  private ReportAnalysisFailureNotificationSerializer serializer = mock(ReportAnalysisFailureNotificationSerializer.class);
-  private System2 system2 = mock(System2.class);
-  private DbClient dbClientMock = mock(DbClient.class);
-  private CeTask ceTaskMock = mock(CeTask.class);
-  private Throwable throwableMock = mock(Throwable.class);
-  private CeTaskResult ceTaskResultMock = mock(CeTaskResult.class);
-  private ReportAnalysisFailureNotificationExecutionListener fullMockedUnderTest = new ReportAnalysisFailureNotificationExecutionListener(
+  private final DbClient dbClient = dbTester.getDbClient();
+  private final NotificationService notificationService = mock(NotificationService.class);
+  private final ReportAnalysisFailureNotificationSerializer serializer = mock(ReportAnalysisFailureNotificationSerializer.class);
+  private final System2 system2 = mock(System2.class);
+  private final DbClient dbClientMock = mock(DbClient.class);
+  private final CeTask ceTaskMock = mock(CeTask.class);
+  private final Throwable throwableMock = mock(Throwable.class);
+  private final CeTaskResult ceTaskResultMock = mock(CeTaskResult.class);
+  private final ReportAnalysisFailureNotificationExecutionListener fullMockedUnderTest = new ReportAnalysisFailureNotificationExecutionListener(
     notificationService, dbClientMock, serializer, system2);
-  private ReportAnalysisFailureNotificationExecutionListener underTest = new ReportAnalysisFailureNotificationExecutionListener(
+  private final ReportAnalysisFailureNotificationExecutionListener underTest = new ReportAnalysisFailureNotificationExecutionListener(
     notificationService, dbClient, serializer, system2);
 
   @Before
@@ -311,8 +311,8 @@ public class ReportAnalysisFailureNotificationExecutionListenerTest {
       .setTaskType(CeTaskTypes.REPORT)
       .setComponentUuid(project.uuid())
       .setCreatedAt(createdAt))
-      .setExecutedAt(executedAt)
-      .setStatus(CeActivityDto.Status.FAILED));
+        .setExecutedAt(executedAt)
+        .setStatus(CeActivityDto.Status.FAILED));
     dbTester.getSession().commit();
   }
 
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/organization/DefaultTemplates.java b/server/sonar-db-dao/src/main/java/org/sonar/db/organization/DefaultTemplates.java
deleted file mode 100644 (file)
index 9915024..0000000
+++ /dev/null
@@ -1,78 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2020 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.sonar.db.organization;
-
-import javax.annotation.CheckForNull;
-import javax.annotation.Nullable;
-
-import static java.util.Objects.requireNonNull;
-
-public class DefaultTemplates {
-  // Hold the template uuid for new projects
-  private String projectUuid;
-  // Hold the template uuid for new applications
-  private String applicationsUuid;
-  // Hold the template uuid for new portfolios
-  private String portfoliosUuid;
-
-  public String getProjectUuid() {
-    checkProjectNotNull(this.projectUuid);
-    return this.projectUuid;
-  }
-
-  public DefaultTemplates setProjectUuid(String projectUuid) {
-    checkProjectNotNull(projectUuid);
-    this.projectUuid = projectUuid;
-    return this;
-  }
-
-  private static void checkProjectNotNull(String project) {
-    requireNonNull(project, "defaultTemplates.project can't be null");
-  }
-
-  @CheckForNull
-  public String getApplicationsUuid() {
-    return applicationsUuid;
-  }
-
-  public DefaultTemplates setApplicationsUuid(@Nullable String applicationsUuid) {
-    this.applicationsUuid = applicationsUuid;
-    return this;
-  }
-
-  @CheckForNull
-  public String getPortfoliosUuid() {
-    return portfoliosUuid;
-  }
-
-  public DefaultTemplates setPortfoliosUuid(@Nullable String portfoliosUuid) {
-    this.portfoliosUuid = portfoliosUuid;
-    return this;
-  }
-
-  @Override
-  public String toString() {
-    return "DefaultTemplates{" +
-      "projectUuid='" + projectUuid + '\'' +
-      ", portfoliosUuid='" + portfoliosUuid + '\'' +
-      ", applicationsUuid='" + applicationsUuid + '\'' +
-      '}';
-  }
-}
index d1453a5d32c103487a9f6d1d74b2a080aa2f2707..7678f09e2c3982cf9cf46a145a6a49f7f1a31a7e 100644 (file)
@@ -29,6 +29,7 @@ import org.sonar.db.DbSession;
 import org.sonar.db.Pagination;
 import org.sonar.db.alm.ALM;
 import org.sonar.db.component.BranchType;
+import org.sonar.db.permission.template.DefaultTemplates;
 import org.sonar.db.qualitygate.QGateWithOrgDto;
 import org.sonar.db.user.GroupDto;
 
index 8e806bda37bea75dab80205b2ad5584ee83eb61c..defe27ba19731b8c37dfa2c2a673cf66c847cd18 100644 (file)
@@ -24,6 +24,7 @@ import javax.annotation.CheckForNull;
 import org.apache.ibatis.annotations.Param;
 import org.sonar.db.Pagination;
 import org.sonar.db.component.BranchType;
+import org.sonar.db.permission.template.DefaultTemplates;
 
 public interface OrganizationMapper {
   void insert(@Param("organization") OrganizationDto organization, @Param("newProjectPrivate") boolean newProjectPrivate);
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/permission/template/DefaultTemplates.java b/server/sonar-db-dao/src/main/java/org/sonar/db/permission/template/DefaultTemplates.java
new file mode 100644 (file)
index 0000000..6dfb913
--- /dev/null
@@ -0,0 +1,82 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.sonar.db.permission.template;
+
+import javax.annotation.CheckForNull;
+import javax.annotation.Nullable;
+
+import static java.util.Objects.requireNonNull;
+
+public class DefaultTemplates {
+  // Hold the template uuid for new projects
+  private String projectUuid;
+  // Hold the template uuid for new applications
+  private String applicationsUuid;
+  // Hold the template uuid for new portfolios
+  private String portfoliosUuid;
+
+  public DefaultTemplates() {
+    // nothing to do here
+  }
+
+  public String getProjectUuid() {
+    checkProjectNotNull(this.projectUuid);
+    return this.projectUuid;
+  }
+
+  public DefaultTemplates setProjectUuid(String projectUuid) {
+    checkProjectNotNull(projectUuid);
+    this.projectUuid = projectUuid;
+    return this;
+  }
+
+  private static void checkProjectNotNull(String project) {
+    requireNonNull(project, "defaultTemplates.project can't be null");
+  }
+
+  @CheckForNull
+  public String getApplicationsUuid() {
+    return applicationsUuid;
+  }
+
+  public DefaultTemplates setApplicationsUuid(@Nullable String applicationsUuid) {
+    this.applicationsUuid = applicationsUuid;
+    return this;
+  }
+
+  @CheckForNull
+  public String getPortfoliosUuid() {
+    return portfoliosUuid;
+  }
+
+  public DefaultTemplates setPortfoliosUuid(@Nullable String portfoliosUuid) {
+    this.portfoliosUuid = portfoliosUuid;
+    return this;
+  }
+
+  @Override
+  public String toString() {
+    return "DefaultTemplates{" +
+      "projectUuid='" + projectUuid + '\'' +
+      ", portfoliosUuid='" + portfoliosUuid + '\'' +
+      ", applicationsUuid='" + applicationsUuid + '\'' +
+      '}';
+  }
+}
index cf9445386c2ea5e18c292666d188d701ef765c71..6c4c69169efe61c6b1a5c3524f205a981783d9f7 100644 (file)
@@ -29,7 +29,7 @@
       org.uuid = #{uuid, jdbcType=VARCHAR}
   </select>
 
-  <select id="selectDefaultTemplatesByUuid" resultType="org.sonar.db.organization.DefaultTemplates">
+  <select id="selectDefaultTemplatesByUuid" resultType="org.sonar.db.permission.template.DefaultTemplates">
     select
       <include refid="defaultTemplatesColumns"/>
     from organizations org
diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/organization/DefaultTemplatesTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/organization/DefaultTemplatesTest.java
deleted file mode 100644 (file)
index d665ad7..0000000
+++ /dev/null
@@ -1,69 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2020 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.sonar.db.organization;
-
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.ExpectedException;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-public class DefaultTemplatesTest {
-  @Rule
-  public ExpectedException expectedException = ExpectedException.none();
-
-  private DefaultTemplates underTest = new DefaultTemplates();
-
-  @Test
-  public void setProject_throws_NPE_if_argument_is_null() {
-    expectedException.expect(NullPointerException.class);
-    expectedException.expectMessage("defaultTemplates.project can't be null");
-
-    underTest.setProjectUuid(null);
-  }
-
-  @Test
-  public void getProject_throws_NPE_if_project_is_null() {
-    expectedException.expect(NullPointerException.class);
-    expectedException.expectMessage("defaultTemplates.project can't be null");
-
-    underTest.getProjectUuid();
-  }
-
-  @Test
-  public void setApplicationsUuid_accepts_null() {
-    underTest.setApplicationsUuid(null);
-  }
-
-  @Test
-  public void setPortfoliosUuid_accepts_null() {
-    underTest.setPortfoliosUuid(null);
-  }
-
-  @Test
-  public void check_toString() {
-    assertThat(underTest.toString()).isEqualTo("DefaultTemplates{projectUuid='null', portfoliosUuid='null', applicationsUuid='null'}");
-    underTest
-        .setProjectUuid("a project")
-        .setApplicationsUuid("an application")
-        .setPortfoliosUuid("a portfolio");
-    assertThat(underTest.toString()).isEqualTo("DefaultTemplates{projectUuid='a project', portfoliosUuid='a portfolio', applicationsUuid='an application'}");
-  }
-}
diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/permission/template/DefaultTemplatesTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/permission/template/DefaultTemplatesTest.java
new file mode 100644 (file)
index 0000000..36fd47c
--- /dev/null
@@ -0,0 +1,76 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.sonar.db.permission.template;
+
+import org.junit.Test;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+public class DefaultTemplatesTest {
+
+  private final DefaultTemplates underTest = new DefaultTemplates();
+
+  @Test
+  public void setProject_throws_NPE_if_argument_is_null() {
+    assertThatThrownBy(() -> underTest.setProjectUuid(null))
+      .isInstanceOf(NullPointerException.class)
+      .hasMessage("defaultTemplates.project can't be null");
+  }
+
+  @Test
+  public void getProject_throws_NPE_if_project_is_null() {
+    assertThatThrownBy(underTest::getProjectUuid)
+      .isInstanceOf(NullPointerException.class)
+      .hasMessage("defaultTemplates.project can't be null");
+  }
+
+  @Test
+  public void setProjectU() {
+    String uuid = "uuid-1";
+    underTest.setProjectUuid(uuid);
+
+    assertThat(underTest.getProjectUuid()).isEqualTo(uuid);
+  }
+
+  @Test
+  public void setApplicationsUuid_accepts_null() {
+    underTest.setApplicationsUuid(null);
+
+    assertThat(underTest.getApplicationsUuid()).isNull();
+  }
+
+  @Test
+  public void setPortfoliosUuid_accepts_null() {
+    underTest.setPortfoliosUuid(null);
+
+    assertThat(underTest.getPortfoliosUuid()).isNull();
+  }
+
+  @Test
+  public void check_toString() {
+    assertThat(underTest).hasToString("DefaultTemplates{projectUuid='null', portfoliosUuid='null', applicationsUuid='null'}");
+    underTest
+      .setProjectUuid("a project")
+      .setApplicationsUuid("an application")
+      .setPortfoliosUuid("a portfolio");
+    assertThat(underTest).hasToString("DefaultTemplates{projectUuid='a project', portfoliosUuid='a portfolio', applicationsUuid='an application'}");
+  }
+}
index 7284a46c23d2eedbb5a7397952b6426da7b627b4..d25c36220afdcac36e82d8a22e2652da628dd1ca 100644 (file)
@@ -252,6 +252,10 @@ public class ComponentTesting {
       .setQualifier(Qualifiers.VIEW);
   }
 
+  public static ComponentDto newApplication() {
+    return newView(Uuids.createFast()).setQualifier(Qualifiers.APP);
+  }
+
   public static ComponentDto newApplication(OrganizationDto organizationDto) {
     return newApplication(organizationDto.getUuid());
   }
index 22ce994c617f2a38e403616e9302826d569cbccc..173c66d2b495c435fbc7d25775eca789df7890ed 100644 (file)
@@ -24,6 +24,7 @@ import java.util.function.Consumer;
 import javax.annotation.Nullable;
 import org.sonar.db.DbSession;
 import org.sonar.db.DbTester;
+import org.sonar.db.permission.template.DefaultTemplates;
 import org.sonar.db.user.UserDto;
 
 //TODO remove
index ddb59e6329e04ae4973aa58f67344487e315d553..69d544b90eb283438fd8d8bc84ba1f3cdc099ca6 100644 (file)
@@ -30,7 +30,7 @@ import org.sonar.api.utils.System2;
 import org.sonar.core.util.UuidFactory;
 import org.sonar.db.DbClient;
 import org.sonar.db.DbSession;
-import org.sonar.db.organization.DefaultTemplates;
+import org.sonar.db.permission.template.DefaultTemplates;
 import org.sonar.db.organization.OrganizationDto;
 import org.sonar.db.organization.OrganizationMemberDto;
 import org.sonar.db.permission.GlobalPermission;
index 1a94569e9333eabaaa23b7430b96d3e08b539869..4b51e25268bdf4aaae54abd2a9d750ccd4865fb3 100644 (file)
@@ -23,7 +23,6 @@ import java.util.Optional;
 import javax.annotation.Nullable;
 import javax.annotation.concurrent.Immutable;
 import org.sonar.db.DbSession;
-import org.sonar.db.organization.DefaultTemplates;
 
 import static java.util.Objects.requireNonNull;
 import static java.util.Optional.ofNullable;
index 633578eeb9536f2bc7e94a48e27cde8824e4d422..b503b5edcd40e70a07cc8c1ee4e01f4006d035fc 100644 (file)
@@ -27,9 +27,7 @@ import org.sonar.server.es.ProjectIndexer;
 import org.sonar.server.es.ProjectIndexers;
 
 /**
- * Add or remove global/project permissions to a group. This class
- * does not verify that caller has administration right on the related
- * organization or project.
+ * Add or remove global/project permissions to a group. This class does not verify that caller has administration right on the related project.
  */
 public class PermissionUpdater {
 
index dacd8d3449e7eb7d7b20f6ae10d7febef6c1a3b2..9c00983fa932161a33f72a36532ae18f84b69f4b 100644 (file)
@@ -20,7 +20,6 @@
 package org.sonar.server.permission.ws;
 
 import java.util.Optional;
-import org.sonar.api.server.ws.Change;
 import org.sonar.api.server.ws.Request;
 import org.sonar.api.server.ws.Response;
 import org.sonar.api.server.ws.WebService;
@@ -74,9 +73,7 @@ public class AddUserAction implements PermissionsWsAction {
         "</ul>")
       .setSince("5.2")
       .setPost(true)
-      .setHandler(this)
-      .setChangelog(
-        new Change("7.4", "If organizationKey and projectId are both set, the organisationKey must be the key of the organization of the project"));
+      .setHandler(this);
 
     wsParameters.createPermissionParameter(action, "The permission you would like to grant to the user");
     createUserLoginParameter(action);
index 7dab5449a1a0f10583c7c388a63d02cf747f6591..1b56f5b7a03a2d62bb4075424fb6568380e52551 100644 (file)
@@ -128,13 +128,11 @@ public class AddProjectCreatorToTemplateAction implements PermissionsWsAction {
 
   private static class AddProjectCreatorToTemplateRequest {
     private final String templateId;
-    private final String organization;
     private final String templateName;
     private final String permission;
 
     private AddProjectCreatorToTemplateRequest(Builder builder) {
       this.templateId = builder.templateId;
-      this.organization = builder.organization;
       this.templateName = builder.templateName;
       this.permission = requireNonNull(builder.permission);
     }
@@ -144,11 +142,6 @@ public class AddProjectCreatorToTemplateAction implements PermissionsWsAction {
       return templateId;
     }
 
-    @CheckForNull
-    public String getOrganization() {
-      return organization;
-    }
-
     @CheckForNull
     public String getTemplateName() {
       return templateName;
@@ -165,7 +158,6 @@ public class AddProjectCreatorToTemplateAction implements PermissionsWsAction {
 
   private static class Builder {
     private String templateId;
-    private String organization;
     private String templateName;
     private String permission;
 
@@ -178,11 +170,6 @@ public class AddProjectCreatorToTemplateAction implements PermissionsWsAction {
       return this;
     }
 
-    public Builder setOrganization(@Nullable String s) {
-      this.organization = s;
-      return this;
-    }
-
     public Builder setTemplateName(@Nullable String templateName) {
       this.templateName = templateName;
       return this;
index 869150df917fa0ed5c3544bd7f710b42a947c5ff..97fce65b15117dd0693d84492477313a2506f34e 100644 (file)
@@ -114,7 +114,6 @@ public class AddUserToTemplateAction implements PermissionsWsAction {
     private String login;
     private String permission;
     private String templateId;
-    private String organization;
     private String templateName;
 
     public String getLogin() {
@@ -154,15 +153,5 @@ public class AddUserToTemplateAction implements PermissionsWsAction {
       this.templateName = templateName;
       return this;
     }
-
-    @CheckForNull
-    public String getOrganization() {
-      return organization;
-    }
-
-    public AddUserToTemplateRequest setOrganization(@Nullable String s) {
-      this.organization = s;
-      return this;
-    }
   }
 }
index babe83632ea431433bd3acb91764b83fa3d005a0..d51b370cdf4ee61e9b20c73cc94c84229b454918 100644 (file)
@@ -119,7 +119,7 @@ public class BulkApplyTemplateAction implements PermissionsWsAction {
 
     action.createParam(PARAM_VISIBILITY)
       .setDescription("Filter the projects that should be visible to everyone (%s), or only specific user/groups (%s).<br/>" +
-        "If no visibility is specified, the default project visibility of the organization will be used.",
+        "If no visibility is specified, the default project visibility will be used.",
         Visibility.PUBLIC.getLabel(), Visibility.PRIVATE.getLabel())
       .setRequired(false)
       .setInternal(true)
@@ -189,7 +189,6 @@ public class BulkApplyTemplateAction implements PermissionsWsAction {
 
   private static class BulkApplyTemplateRequest {
     private String templateId;
-    private String organization;
     private String templateName;
     private String query;
     private Collection<String> qualifiers = singleton(Qualifiers.PROJECT);
@@ -208,16 +207,6 @@ public class BulkApplyTemplateAction implements PermissionsWsAction {
       return this;
     }
 
-    @CheckForNull
-    public String getOrganization() {
-      return organization;
-    }
-
-    public BulkApplyTemplateRequest setOrganization(@Nullable String s) {
-      this.organization = s;
-      return this;
-    }
-
     @CheckForNull
     public String getTemplateName() {
       return templateName;
index 318c7171cf788617441e8aeb1924a8b7a00a57b4..f3b9daf66e05c0273066555cdab349a541644e3f 100644 (file)
@@ -132,7 +132,6 @@ public class CreateTemplateAction implements PermissionsWsAction {
     private String description;
     private String name;
     private String projectKeyPattern;
-    private String organization;
 
     @CheckForNull
     public String getDescription() {
@@ -162,15 +161,5 @@ public class CreateTemplateAction implements PermissionsWsAction {
       this.projectKeyPattern = projectKeyPattern;
       return this;
     }
-
-    @CheckForNull
-    public String getOrganization() {
-      return organization;
-    }
-
-    public CreateTemplateRequest setOrganization(@Nullable String s) {
-      this.organization = s;
-      return this;
-    }
   }
 }
index 189dee54538e9a879b33bc51d49fea73517c164e..fd513f9f2f2f71773b9ca8ac4ab2b739a885c853 100644 (file)
@@ -111,13 +111,11 @@ public class RemoveProjectCreatorFromTemplateAction implements PermissionsWsActi
 
   private static class RemoveProjectCreatorFromTemplateRequest {
     private final String templateId;
-    private final String organization;
     private final String templateName;
     private final String permission;
 
     private RemoveProjectCreatorFromTemplateRequest(Builder builder) {
       this.templateId = builder.templateId;
-      this.organization = builder.organization;
       this.templateName = builder.templateName;
       this.permission = requireNonNull(builder.permission);
     }
@@ -127,11 +125,6 @@ public class RemoveProjectCreatorFromTemplateAction implements PermissionsWsActi
       return templateId;
     }
 
-    @CheckForNull
-    public String getOrganization() {
-      return organization;
-    }
-
     @CheckForNull
     public String getTemplateName() {
       return templateName;
@@ -148,7 +141,6 @@ public class RemoveProjectCreatorFromTemplateAction implements PermissionsWsActi
 
   public static class Builder {
     private String templateId;
-    private String organization;
     private String templateName;
     private String permission;
 
@@ -161,11 +153,6 @@ public class RemoveProjectCreatorFromTemplateAction implements PermissionsWsActi
       return this;
     }
 
-    public Builder setOrganization(@Nullable String s) {
-      this.organization = s;
-      return this;
-    }
-
     public Builder setTemplateName(@Nullable String templateName) {
       this.templateName = templateName;
       return this;
index 6ebd6630fa9f812b68a25233e2556a28d8fb311e..0a6b572366162bde63191c22a4a28204bb4dd944 100644 (file)
@@ -107,7 +107,6 @@ public class RemoveUserFromTemplateAction implements PermissionsWsAction {
     private String login;
     private String permission;
     private String templateId;
-    private String organization;
     private String templateName;
 
     public String getLogin() {
@@ -138,16 +137,6 @@ public class RemoveUserFromTemplateAction implements PermissionsWsAction {
       return this;
     }
 
-    @CheckForNull
-    public String getOrganization() {
-      return organization;
-    }
-
-    public RemoveUserFromTemplateRequest setOrganization(@Nullable String s) {
-      this.organization = s;
-      return this;
-    }
-
     @CheckForNull
     public String getTemplateName() {
       return templateName;
index dc934d293e9a613e31d6a248f78e6322ba253ed8..0cb3acca3135b5c685f77298f7f434e51b0ac795 100644 (file)
@@ -54,15 +54,14 @@ public class PermissionTemplateServiceTest {
   @Rule
   public DbTester dbTester = DbTester.create();
 
-  private ResourceTypesRule resourceTypesRule = new ResourceTypesRule().setRootQualifiers(PROJECT, VIEW, APP);
-  private DefaultTemplatesResolver defaultTemplatesResolver = new DefaultTemplatesResolverImpl(dbTester.getDbClient(), resourceTypesRule);
-  private PermissionService permissionService = new PermissionServiceImpl(resourceTypesRule);
-  private UserSessionRule userSession = UserSessionRule.standalone();
-  private PermissionTemplateDbTester templateDb = dbTester.permissionTemplates();
-  private DbSession session = dbTester.getSession();
-  private ProjectIndexers projectIndexers = new TestProjectIndexers();
-
-  private PermissionTemplateService underTest = new PermissionTemplateService(dbTester.getDbClient(), projectIndexers, userSession, defaultTemplatesResolver,
+  private final ResourceTypesRule resourceTypesRule = new ResourceTypesRule().setRootQualifiers(PROJECT, VIEW, APP);
+  private final DefaultTemplatesResolver defaultTemplatesResolver = new DefaultTemplatesResolverImpl(dbTester.getDbClient(), resourceTypesRule);
+  private final PermissionService permissionService = new PermissionServiceImpl(resourceTypesRule);
+  private final UserSessionRule userSession = UserSessionRule.standalone();
+  private final PermissionTemplateDbTester templateDb = dbTester.permissionTemplates();
+  private final DbSession session = dbTester.getSession();
+  private final ProjectIndexers projectIndexers = new TestProjectIndexers();
+  private final PermissionTemplateService underTest = new PermissionTemplateService(dbTester.getDbClient(), projectIndexers, userSession, defaultTemplatesResolver,
     new SequenceUuidFactory());
 
   @Test
@@ -307,7 +306,7 @@ public class PermissionTemplateServiceTest {
 
   @Test
   public void apply_default_template_on_portfolio() {
-    ComponentDto view = dbTester.components().insertPublicPortfolio(dbTester.getDefaultOrganization());
+    ComponentDto view = dbTester.components().insertPublicPortfolio();
     PermissionTemplateDto projectPermissionTemplate = dbTester.permissionTemplates().insertTemplate();
     PermissionTemplateDto portPermissionTemplate = dbTester.permissionTemplates().insertTemplate();
     GroupDto group = dbTester.users().insertGroup();
index 5906f964a929c27d1c2bd5ff69f34003b4bdfe7e..bce8cbd3a4b8c86d1fbb647bd2661484470451ef 100644 (file)
@@ -75,7 +75,7 @@ public class UserPermissionChangerTest {
 
   @Test
   public void apply_adds_any_global_permission_to_user() {
-    permissionService.getGlobalPermissions().stream()
+    permissionService.getGlobalPermissions()
       .forEach(perm -> {
         UserPermissionChange change = new UserPermissionChange(ADD, perm.getKey(), null, UserId.from(user1), permissionService);
 
@@ -86,15 +86,15 @@ public class UserPermissionChangerTest {
   }
 
   @Test
-  public void apply_removes_any_organization_permission_to_user() {
+  public void apply_removes_any_global_permission_to_user() {
     // give ADMIN perm to user2 so that user1 is not the only one with this permission and it can be removed from user1
     db.users().insertPermissionOnUser(user2, GlobalPermission.ADMINISTER);
-    permissionService.getGlobalPermissions().stream()
+    permissionService.getGlobalPermissions()
       .forEach(perm -> db.users().insertPermissionOnUser(user1, perm));
     assertThat(db.users().selectPermissionsOfUser(user1))
       .containsOnly(permissionService.getGlobalPermissions().toArray(new GlobalPermission[0]));
 
-    permissionService.getGlobalPermissions().stream()
+    permissionService.getGlobalPermissions()
       .forEach(perm -> {
         UserPermissionChange change = new UserPermissionChange(REMOVE, perm.getKey(), null, UserId.from(user1), permissionService);
 
index 332bab6513efac234752c8bce96e0b5cebbb808b..4fe2c8ccbaa2cbb1f4a2f0e6085127bd38f0bbda 100644 (file)
@@ -43,13 +43,14 @@ import static org.assertj.core.api.Assertions.tuple;
 import static org.sonar.api.web.UserRole.CODEVIEWER;
 import static org.sonar.api.web.UserRole.ISSUE_ADMIN;
 import static org.sonar.api.web.UserRole.USER;
-import static org.sonar.core.permission.GlobalPermissions.PROVISIONING;
 import static org.sonar.core.permission.GlobalPermissions.SYSTEM_ADMIN;
 import static org.sonar.db.component.ComponentTesting.newDirectory;
 import static org.sonar.db.component.ComponentTesting.newFileDto;
 import static org.sonar.db.component.ComponentTesting.newModuleDto;
 import static org.sonar.db.component.ComponentTesting.newPrivateProjectDto;
 import static org.sonar.db.component.ComponentTesting.newSubView;
+import static org.sonar.db.permission.GlobalPermission.ADMINISTER;
+import static org.sonar.db.permission.GlobalPermission.PROVISION_PROJECTS;
 import static org.sonar.db.permission.GlobalPermission.SCAN;
 import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_GROUP_ID;
 import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_GROUP_NAME;
@@ -62,9 +63,9 @@ public class AddGroupActionTest extends BasePermissionWsTest<AddGroupAction> {
   private static final String A_PROJECT_UUID = "project-uuid";
   private static final String A_PROJECT_KEY = "project-key";
 
-  private ResourceTypes resourceTypes = new ResourceTypesRule().setRootQualifiers(Qualifiers.PROJECT);
-  private PermissionService permissionService = new PermissionServiceImpl(resourceTypes);
-  private WsParameters wsParameters = new WsParameters(permissionService);
+  private final ResourceTypes resourceTypes = new ResourceTypesRule().setRootQualifiers(Qualifiers.PROJECT);
+  private final PermissionService permissionService = new PermissionServiceImpl(resourceTypes);
+  private final WsParameters wsParameters = new WsParameters(permissionService);
 
   @Override
   protected AddGroupAction buildWsAction() {
@@ -89,10 +90,10 @@ public class AddGroupActionTest extends BasePermissionWsTest<AddGroupAction> {
 
     newRequest()
       .setParam(PARAM_GROUP_NAME, "sonar-administrators")
-      .setParam(PARAM_PERMISSION, SYSTEM_ADMIN)
+      .setParam(PARAM_PERMISSION, ADMINISTER.getKey())
       .execute();
 
-    assertThat(db.users().selectGroupPermissions(group, null)).containsOnly(SYSTEM_ADMIN);
+    assertThat(db.users().selectGroupPermissions(group, null)).containsOnly("admin");
   }
 
   @Test
@@ -102,10 +103,10 @@ public class AddGroupActionTest extends BasePermissionWsTest<AddGroupAction> {
 
     newRequest()
       .setParam(PARAM_GROUP_NAME, group.getName())
-      .setParam(PARAM_PERMISSION, PROVISIONING)
+      .setParam(PARAM_PERMISSION, PROVISION_PROJECTS.getKey())
       .execute();
 
-    assertThat(db.users().selectGroupPermissions(group, null)).containsOnly(PROVISIONING);
+    assertThat(db.users().selectGroupPermissions(group, null)).containsOnly("provisioning");
   }
 
   @Test
@@ -124,7 +125,7 @@ public class AddGroupActionTest extends BasePermissionWsTest<AddGroupAction> {
   @Test
   public void add_permission_to_project_referenced_by_its_id() {
     GroupDto group = db.users().insertGroup("sonar-administrators");
-    ComponentDto project = db.components().insertComponent(newPrivateProjectDto(db.getDefaultOrganization(), A_PROJECT_UUID).setDbKey(A_PROJECT_KEY));
+    ComponentDto project = db.components().insertComponent(newPrivateProjectDto(A_PROJECT_UUID).setDbKey(A_PROJECT_KEY));
     loginAsAdmin();
 
     newRequest()
@@ -140,7 +141,7 @@ public class AddGroupActionTest extends BasePermissionWsTest<AddGroupAction> {
   @Test
   public void add_permission_to_project_referenced_by_its_key() {
     GroupDto group = db.users().insertGroup("sonar-administrators");
-    ComponentDto project = db.components().insertComponent(newPrivateProjectDto(db.getDefaultOrganization(), A_PROJECT_UUID).setDbKey(A_PROJECT_KEY));
+    ComponentDto project = db.components().insertComponent(newPrivateProjectDto(A_PROJECT_UUID).setDbKey(A_PROJECT_KEY));
     loginAsAdmin();
 
     newRequest()
@@ -329,7 +330,7 @@ public class AddGroupActionTest extends BasePermissionWsTest<AddGroupAction> {
 
     newRequest()
       .setParam(PARAM_GROUP_NAME, group.getName())
-      .setParam(PARAM_PERMISSION, PROVISIONING)
+      .setParam(PARAM_PERMISSION, PROVISION_PROJECTS.getKey())
       .execute();
   }
 
@@ -343,7 +344,7 @@ public class AddGroupActionTest extends BasePermissionWsTest<AddGroupAction> {
 
     newRequest()
       .setParam(PARAM_GROUP_NAME, group.getName())
-      .setParam(PARAM_PERMISSION, PROVISIONING)
+      .setParam(PARAM_PERMISSION, PROVISION_PROJECTS.getKey())
       .setParam(PARAM_PROJECT_KEY, project.getDbKey())
       .execute();
   }
index f699e94ee5619c685545cc8b3d94164e5933d739..aabdb07891bf8de8d1075ce957e6d07d21c3d36a 100644 (file)
@@ -112,7 +112,7 @@ public class AddUserActionTest extends BasePermissionWsTest<AddUserAction> {
 
   @Test
   public void add_permission_to_view() {
-    ComponentDto view = db.components().insertComponent(newView(db.getDefaultOrganization(), "view-uuid").setDbKey("view-key"));
+    ComponentDto view = db.components().insertComponent(newView( "view-uuid").setDbKey("view-key"));
     loginAsAdmin();
 
     newRequest()
index 2171d1f63b5b1ed16e0939e4bfb769d9e6ffabcf..d30ea15334623660923ede8fe8413d8344211f4c 100644 (file)
@@ -95,7 +95,7 @@ public abstract class BasePermissionWsTest<A extends PermissionsWsAction> {
     userSession.logIn().addPermission(ADMINISTER);
   }
 
-  protected PermissionTemplateDto selectTemplateInDefaultOrganization(String name) {
+  protected PermissionTemplateDto selectPermissionTemplate(String name) {
     return db.getDbClient().permissionTemplateDao().selectByName(db.getSession(), name);
   }
 
@@ -105,8 +105,4 @@ public abstract class BasePermissionWsTest<A extends PermissionsWsAction> {
     db.commit();
     return dto;
   }
-
-  protected PermissionTemplateDto addTemplateToDefaultOrganization() {
-    return addTemplate();
-  }
 }
index e7d0c7806dd4255246f6486a73dccf70b632b894..3e1d9a1173ba5faf03b4fc7ae629d463c0a40088 100644 (file)
@@ -58,10 +58,9 @@ public class GroupsActionTest extends BasePermissionWsTest<GroupsAction> {
 
   private GroupDto group1;
   private GroupDto group2;
-  private GroupDto group3;
-  private ResourceTypes resourceTypes = new ResourceTypesRule().setRootQualifiers(Qualifiers.PROJECT);
-  private PermissionService permissionService = new PermissionServiceImpl(resourceTypes);
-  private WsParameters wsParameters = new WsParameters(permissionService);
+  private final ResourceTypes resourceTypes = new ResourceTypesRule().setRootQualifiers(Qualifiers.PROJECT);
+  private final PermissionService permissionService = new PermissionServiceImpl(resourceTypes);
+  private final WsParameters wsParameters = new WsParameters(permissionService);
 
   @Override
   protected GroupsAction buildWsAction() {
@@ -75,7 +74,7 @@ public class GroupsActionTest extends BasePermissionWsTest<GroupsAction> {
   public void setUp() {
     group1 = db.users().insertGroup("group-1-name");
     group2 = db.users().insertGroup("group-2-name");
-    group3 = db.users().insertGroup("group-3-name");
+    GroupDto group3 = db.users().insertGroup("group-3-name");
     db.users().insertPermissionOnGroup(group1, SCAN);
     db.users().insertPermissionOnGroup(group2, SCAN);
     db.users().insertPermissionOnGroup(group3, ADMINISTER);
@@ -222,7 +221,7 @@ public class GroupsActionTest extends BasePermissionWsTest<GroupsAction> {
 
   @Test
   public void return_only_groups_with_permission_when_no_search_query() {
-    ComponentDto project = db.components().insertComponent(newPrivateProjectDto(db.getDefaultOrganization(), "project-uuid"));
+    ComponentDto project = db.components().insertComponent(newPrivateProjectDto("project-uuid"));
     GroupDto group = db.users().insertGroup("project-group-name");
     db.users().insertProjectPermissionOnGroup(group, ISSUE_ADMIN, project);
 
@@ -257,7 +256,7 @@ public class GroupsActionTest extends BasePermissionWsTest<GroupsAction> {
 
   @Test
   public void search_groups_on_views() {
-    ComponentDto view = db.components().insertComponent(newView(db.getDefaultOrganization(), "view-uuid").setDbKey("view-key"));
+    ComponentDto view = db.components().insertComponent(newView("view-uuid").setDbKey("view-key"));
     GroupDto group = db.users().insertGroup("project-group-name");
     db.users().insertProjectPermissionOnGroup(group, ISSUE_ADMIN, view);
 
index 481abe2fc33a865f485d533d7f59f77f97e1132c..9b6bf60ac8e6b0ada69b78097308ec0799e6c8e7 100644 (file)
@@ -25,7 +25,6 @@ import org.junit.Test;
 import org.sonar.api.resources.Qualifiers;
 import org.sonar.api.resources.ResourceTypes;
 import org.sonar.api.web.UserRole;
-import org.sonar.db.component.ComponentDbTester;
 import org.sonar.db.component.ComponentDto;
 import org.sonar.db.component.ComponentTesting;
 import org.sonar.db.component.ResourceTypesRule;
@@ -55,10 +54,9 @@ import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_Q
 
 public class SearchProjectPermissionsActionTest extends BasePermissionWsTest<SearchProjectPermissionsAction> {
 
-  private ComponentDbTester componentDb = new ComponentDbTester(db);
-  private I18nRule i18n = new I18nRule();
-  private ResourceTypes resourceTypes = new ResourceTypesRule().setRootQualifiers(Qualifiers.PROJECT);
-  private PermissionService permissionService = new PermissionServiceImpl(resourceTypes);
+  private final I18nRule i18n = new I18nRule();
+  private final ResourceTypes resourceTypes = new ResourceTypesRule().setRootQualifiers(Qualifiers.PROJECT);
+  private final PermissionService permissionService = new PermissionServiceImpl(resourceTypes);
 
   @Before
   public void setUp() {
@@ -176,7 +174,7 @@ public class SearchProjectPermissionsActionTest extends BasePermissionWsTest<Sea
 
   @Test
   public void search_project_permissions_with_project_permission() {
-    ComponentDto project = db.components().insertComponent(newPrivateProjectDto(db.getDefaultOrganization(), "project-uuid"));
+    ComponentDto project = db.components().insertComponent(newPrivateProjectDto("project-uuid"));
     userSession.logIn().addProjectPermission(UserRole.ADMIN, project);
 
     String result = newRequest()
@@ -229,9 +227,7 @@ public class SearchProjectPermissionsActionTest extends BasePermissionWsTest<Sea
 
   @Test
   public void handle_more_than_1000_projects() {
-    IntStream.rangeClosed(1, 1001).forEach(i -> {
-      db.components().insertPrivateProject("project-uuid-" + i);
-    });
+    IntStream.rangeClosed(1, 1001).forEach(i -> db.components().insertPrivateProject("project-uuid-" + i));
 
     String result = newRequest()
       .setParam(TEXT_QUERY, "project")
@@ -299,25 +295,25 @@ public class SearchProjectPermissionsActionTest extends BasePermissionWsTest<Sea
   }
 
   private ComponentDto insertView() {
-    return db.components().insertComponent(newView(db.getDefaultOrganization())
+    return db.components().insertComponent(newView()
       .setUuid("752d8bfd-420c-4a83-a4e5-8ab19b13c8fc")
       .setName("Java")
       .setDbKey("Java"));
   }
 
-  private ComponentDto insertProjectInView(ComponentDto project, ComponentDto view) {
-    return db.components().insertComponent(newProjectCopy("project-in-view-uuid", project, view));
+  private void insertProjectInView(ComponentDto project, ComponentDto view) {
+    db.components().insertComponent(newProjectCopy("project-in-view-uuid", project, view));
   }
 
   private ComponentDto insertClang() {
-    return db.components().insertComponent(newPrivateProjectDto(db.getDefaultOrganization(), "project-uuid-2")
+    return db.components().insertComponent(newPrivateProjectDto("project-uuid-2")
       .setName("Clang")
       .setDbKey("clang")
       .setUuid("ce4c03d6-430f-40a9-b777-ad877c00aa4d"));
   }
 
   private ComponentDto insertJdk7() {
-    return db.components().insertComponent(ComponentTesting.newPublicProjectDto(db.getDefaultOrganization())
+    return db.components().insertComponent(ComponentTesting.newPublicProjectDto()
       .setName("JDK 7")
       .setDbKey("net.java.openjdk:jdk7")
       .setUuid("0bd7b1e7-91d6-439e-a607-4a3a9aad3c6a"));
index cdd08b990f4c7b023e4e772639d21ee6e028cf0c..3cbe39c8460cd0536d0beb9bced81843a3b0f625 100644 (file)
@@ -68,11 +68,9 @@ public class BulkApplyTemplateActionTest extends BasePermissionWsTest<BulkApplyT
   private GroupDto group1;
   private GroupDto group2;
   private PermissionTemplateDto template1;
-  private PermissionTemplateDto template2;
-  private ProjectIndexers projectIndexers = new TestProjectIndexers();
-
-  private ResourceTypesRule resourceTypesRule = new ResourceTypesRule().setRootQualifiers(PROJECT, VIEW, APP);
-  private DefaultTemplatesResolver defaultTemplatesResolver = new DefaultTemplatesResolverImpl(db.getDbClient(), resourceTypesRule);
+  private final ProjectIndexers projectIndexers = new TestProjectIndexers();
+  private final ResourceTypesRule resourceTypesRule = new ResourceTypesRule().setRootQualifiers(PROJECT, VIEW, APP);
+  private final DefaultTemplatesResolver defaultTemplatesResolver = new DefaultTemplatesResolverImpl(db.getDbClient(), resourceTypesRule);
 
   @Override
   protected BulkApplyTemplateAction buildWsAction() {
@@ -95,7 +93,7 @@ public class BulkApplyTemplateActionTest extends BasePermissionWsTest<BulkApplyT
     addGroupToTemplate(group1, template1, UserRole.ADMIN);
     addGroupToTemplate(group2, template1, UserRole.USER);
     // template 2
-    template2 = db.permissionTemplates().insertTemplate();
+    PermissionTemplateDto template2 = db.permissionTemplates().insertTemplate();
     addUserToTemplate(user1, template2, UserRole.USER);
     addUserToTemplate(user2, template2, UserRole.USER);
     addGroupToTemplate(group1, template2, UserRole.USER);
@@ -160,8 +158,8 @@ public class BulkApplyTemplateActionTest extends BasePermissionWsTest<BulkApplyT
   public void apply_template_by_qualifiers() {
     ComponentDto publicProject = db.components().insertPublicProject();
     ComponentDto privateProject = db.components().insertPrivateProject();
-    ComponentDto view = db.components().insertComponent(newView(db.getDefaultOrganization()));
-    ComponentDto application = db.components().insertComponent(newApplication(db.getDefaultOrganization()));
+    ComponentDto view = db.components().insertComponent(newView());
+    ComponentDto application = db.components().insertComponent(newApplication());
     loginAsAdmin();
 
     newRequest()
@@ -177,11 +175,11 @@ public class BulkApplyTemplateActionTest extends BasePermissionWsTest<BulkApplyT
 
   @Test
   public void apply_template_by_query_on_name_and_key_public_project() {
-    ComponentDto publicProjectFoundByKey = ComponentTesting.newPublicProjectDto(db.getDefaultOrganization()).setDbKey("sonar");
+    ComponentDto publicProjectFoundByKey = ComponentTesting.newPublicProjectDto().setDbKey("sonar");
     db.components().insertProjectAndSnapshot(publicProjectFoundByKey);
-    ComponentDto publicProjectFoundByName = ComponentTesting.newPublicProjectDto(db.getDefaultOrganization()).setName("name-sonar-name");
+    ComponentDto publicProjectFoundByName = ComponentTesting.newPublicProjectDto().setName("name-sonar-name");
     db.components().insertProjectAndSnapshot(publicProjectFoundByName);
-    ComponentDto projectUntouched = ComponentTesting.newPublicProjectDto(db.getDefaultOrganization()).setDbKey("new-sona").setName("project-name");
+    ComponentDto projectUntouched = ComponentTesting.newPublicProjectDto().setDbKey("new-sona").setName("project-name");
     db.components().insertProjectAndSnapshot(projectUntouched);
     loginAsAdmin();
 
@@ -198,11 +196,11 @@ public class BulkApplyTemplateActionTest extends BasePermissionWsTest<BulkApplyT
   @Test
   public void apply_template_by_query_on_name_and_key() {
     // partial match on key
-    ComponentDto privateProjectFoundByKey = ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization()).setDbKey("sonarqube");
+    ComponentDto privateProjectFoundByKey = ComponentTesting.newPrivateProjectDto().setDbKey("sonarqube");
     db.components().insertProjectAndSnapshot(privateProjectFoundByKey);
-    ComponentDto privateProjectFoundByName = ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization()).setName("name-sonar-name");
+    ComponentDto privateProjectFoundByName = ComponentTesting.newPrivateProjectDto().setName("name-sonar-name");
     db.components().insertProjectAndSnapshot(privateProjectFoundByName);
-    ComponentDto projectUntouched = ComponentTesting.newPublicProjectDto(db.getDefaultOrganization()).setDbKey("new-sona").setName("project-name");
+    ComponentDto projectUntouched = ComponentTesting.newPublicProjectDto().setDbKey("new-sona").setName("project-name");
     db.components().insertProjectAndSnapshot(projectUntouched);
     loginAsAdmin();
 
index ba2c0033ecbbfce5c2459ef03b4a2a6cc0ab7af5..d898801971f66e8c5b4ef478db3d57332f51b098 100644 (file)
@@ -56,7 +56,7 @@ public class CreateTemplateActionTest extends BasePermissionWsTest<CreateTemplat
     assertJson(result.getInput())
       .ignoreFields("id")
       .isSimilarTo(getClass().getResource("create_template-example.json"));
-    PermissionTemplateDto finance = selectTemplateInDefaultOrganization("Finance");
+    PermissionTemplateDto finance = selectPermissionTemplate("Finance");
     assertThat(finance.getName()).isEqualTo("Finance");
     assertThat(finance.getDescription()).isEqualTo("Permissions for financially related projects");
     assertThat(finance.getKeyPattern()).isEqualTo(".*\\.finance\\..*");
@@ -71,7 +71,7 @@ public class CreateTemplateActionTest extends BasePermissionWsTest<CreateTemplat
 
     newRequest("Finance", null, null);
 
-    PermissionTemplateDto finance = selectTemplateInDefaultOrganization("Finance");
+    PermissionTemplateDto finance = selectPermissionTemplate("Finance");
     assertThat(finance.getName()).isEqualTo("Finance");
     assertThat(finance.getDescription()).isNullOrEmpty();
     assertThat(finance.getKeyPattern()).isNullOrEmpty();
index 7074058a9e16c0cb05fc3c7d45a5dc01cc710c9b..e27b7dae66f329ebca9c2c13393185cb2f97960e 100644 (file)
@@ -60,10 +60,10 @@ import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_T
 
 public class TemplateGroupsActionTest extends BasePermissionWsTest<TemplateGroupsAction> {
 
-  private ResourceTypes resourceTypes = new ResourceTypesRule().setRootQualifiers(Qualifiers.PROJECT);
-  private PermissionService permissionService = new PermissionServiceImpl(resourceTypes);
-  private WsParameters wsParameters = new WsParameters(permissionService);
-  private RequestValidator requestValidator = new RequestValidator(permissionService);
+  private final ResourceTypes resourceTypes = new ResourceTypesRule().setRootQualifiers(Qualifiers.PROJECT);
+  private final PermissionService permissionService = new PermissionServiceImpl(resourceTypes);
+  private final WsParameters wsParameters = new WsParameters(permissionService);
+  private final RequestValidator requestValidator = new RequestValidator(permissionService);
 
   @Override
   protected TemplateGroupsAction buildWsAction() {
@@ -83,10 +83,10 @@ public class TemplateGroupsActionTest extends BasePermissionWsTest<TemplateGroup
 
   @Test
   public void template_groups_of_json_example() {
-    GroupDto adminGroup = insertGroupOnDefaultOrganization("sonar-administrators", "System administrators");
-    GroupDto userGroup = insertGroupOnDefaultOrganization("sonar-users", "Any new users created will automatically join this group");
+    GroupDto adminGroup = insertGroup("sonar-administrators", "System administrators");
+    GroupDto userGroup = insertGroup("sonar-users", "Any new users created will automatically join this group");
 
-    PermissionTemplateDto template = addTemplateToDefaultOrganization();
+    PermissionTemplateDto template = addTemplate();
     addGroupToTemplate(newPermissionTemplateGroup(ISSUE_ADMIN, template.getUuid(), adminGroup.getUuid()));
     addGroupToTemplate(newPermissionTemplateGroup(ISSUE_ADMIN, template.getUuid(), userGroup.getUuid()));
     // Anyone group
@@ -108,7 +108,7 @@ public class TemplateGroupsActionTest extends BasePermissionWsTest<TemplateGroup
 
   @Test
   public void return_all_permissions_of_matching_groups() {
-    PermissionTemplateDto template = addTemplateToDefaultOrganization();
+    PermissionTemplateDto template = addTemplate();
 
     GroupDto group1 = db.users().insertGroup("group-1-name");
     addGroupToTemplate(newPermissionTemplateGroup(CODEVIEWER, template.getUuid(), group1.getUuid()));
@@ -124,7 +124,7 @@ public class TemplateGroupsActionTest extends BasePermissionWsTest<TemplateGroup
     addGroupToTemplate(newPermissionTemplateGroup(USER, template.getUuid(), null));
     addGroupToTemplate(newPermissionTemplateGroup(ISSUE_ADMIN, template.getUuid(), null));
 
-    PermissionTemplateDto anotherTemplate = addTemplateToDefaultOrganization();
+    PermissionTemplateDto anotherTemplate = addTemplate();
     GroupDto group4 = db.users().insertGroup("group-4-name");
     addGroupToTemplate(newPermissionTemplateGroup(ADMIN, anotherTemplate.getUuid(), group3.getUuid()));
     addGroupToTemplate(newPermissionTemplateGroup(ADMIN, anotherTemplate.getUuid(), group4.getUuid()));
@@ -143,7 +143,7 @@ public class TemplateGroupsActionTest extends BasePermissionWsTest<TemplateGroup
 
   @Test
   public void search_by_permission() {
-    PermissionTemplateDto template = addTemplateToDefaultOrganization();
+    PermissionTemplateDto template = addTemplate();
 
     GroupDto group1 = db.users().insertGroup("group-1-name");
     addGroupToTemplate(newPermissionTemplateGroup(USER, template.getUuid(), group1.getUuid()));
@@ -157,7 +157,7 @@ public class TemplateGroupsActionTest extends BasePermissionWsTest<TemplateGroup
     // Anyone
     addGroupToTemplate(newPermissionTemplateGroup(USER, template.getUuid(), null));
 
-    PermissionTemplateDto anotherTemplate = addTemplateToDefaultOrganization();
+    PermissionTemplateDto anotherTemplate = addTemplate();
     addGroupToTemplate(newPermissionTemplateGroup(ADMIN, anotherTemplate.getUuid(), group3.getUuid()));
     loginAsAdmin();
 
@@ -177,12 +177,12 @@ public class TemplateGroupsActionTest extends BasePermissionWsTest<TemplateGroup
     GroupDto group2 = db.users().insertGroup("group-2-name");
     GroupDto group3 = db.users().insertGroup("group-3-name");
 
-    PermissionTemplateDto template = addTemplateToDefaultOrganization();
+    PermissionTemplateDto template = addTemplate();
     addGroupToTemplate(newPermissionTemplateGroup(USER, template.getUuid(), group1.getUuid()));
     addGroupToTemplate(newPermissionTemplateGroup(ADMIN, template.getUuid(), group2.getUuid()));
     addGroupToTemplate(newPermissionTemplateGroup(USER, template.getUuid(), null));
 
-    PermissionTemplateDto anotherTemplate = addTemplateToDefaultOrganization();
+    PermissionTemplateDto anotherTemplate = addTemplate();
     addGroupToTemplate(newPermissionTemplateGroup(USER, anotherTemplate.getUuid(), group1.getUuid()));
     loginAsAdmin();
 
@@ -195,7 +195,7 @@ public class TemplateGroupsActionTest extends BasePermissionWsTest<TemplateGroup
 
   @Test
   public void search_with_pagination() {
-    PermissionTemplateDto template = addTemplateToDefaultOrganization();
+    PermissionTemplateDto template = addTemplate();
     GroupDto group1 = db.users().insertGroup("group-1-name");
     addGroupToTemplate(newPermissionTemplateGroup(USER, template.getUuid(), group1.getUuid()));
     GroupDto group2 = db.users().insertGroup("group-2-name");
@@ -214,7 +214,7 @@ public class TemplateGroupsActionTest extends BasePermissionWsTest<TemplateGroup
 
   @Test
   public void search_with_text_query() {
-    PermissionTemplateDto template = addTemplateToDefaultOrganization();
+    PermissionTemplateDto template = addTemplate();
     GroupDto group1 = db.users().insertGroup("group-1-name");
     addGroupToTemplate(newPermissionTemplateGroup(USER, template.getUuid(), group1.getUuid()));
     GroupDto group2 = db.users().insertGroup("group-2-name");
@@ -231,7 +231,7 @@ public class TemplateGroupsActionTest extends BasePermissionWsTest<TemplateGroup
 
   @Test
   public void search_with_text_query_return_all_groups_even_when_no_permission_set() {
-    PermissionTemplateDto template = addTemplateToDefaultOrganization();
+    PermissionTemplateDto template = addTemplate();
     db.users().insertGroup("group-1-name");
     db.users().insertGroup("group-2-name");
     db.users().insertGroup("group-3-name");
@@ -250,7 +250,7 @@ public class TemplateGroupsActionTest extends BasePermissionWsTest<TemplateGroup
 
   @Test
   public void search_with_text_query_return_anyone_group_even_when_no_permission_set() {
-    PermissionTemplateDto template = addTemplateToDefaultOrganization();
+    PermissionTemplateDto template = addTemplate();
     GroupDto group = db.users().insertGroup("group");
     addGroupToTemplate(newPermissionTemplateGroup(USER, template.getUuid(), group.getUuid()));
     loginAsAdmin();
@@ -266,7 +266,7 @@ public class TemplateGroupsActionTest extends BasePermissionWsTest<TemplateGroup
 
   @Test
   public void search_ignores_other_template_and_is_ordered_by_groups_with_permission_then_by_name_when_many_groups() {
-    PermissionTemplateDto template = addTemplateToDefaultOrganization();
+    PermissionTemplateDto template = addTemplate();
     PermissionTemplateDto otherTemplate = db.permissionTemplates().insertTemplate();
     IntStream.rangeClosed(1, DEFAULT_PAGE_SIZE + 1).forEach(i -> {
       GroupDto group = db.users().insertGroup("Group-" + i);
@@ -288,7 +288,7 @@ public class TemplateGroupsActionTest extends BasePermissionWsTest<TemplateGroup
 
   @Test
   public void fail_if_not_logged_in() {
-    PermissionTemplateDto template1 = addTemplateToDefaultOrganization();
+    PermissionTemplateDto template1 = addTemplate();
     userSession.anonymous();
 
     expectedException.expect(UnauthorizedException.class);
@@ -301,7 +301,7 @@ public class TemplateGroupsActionTest extends BasePermissionWsTest<TemplateGroup
 
   @Test
   public void fail_if_insufficient_privileges() {
-    PermissionTemplateDto template1 = addTemplateToDefaultOrganization();
+    PermissionTemplateDto template1 = addTemplate();
     userSession.logIn();
 
     expectedException.expect(ForbiddenException.class);
@@ -314,7 +314,7 @@ public class TemplateGroupsActionTest extends BasePermissionWsTest<TemplateGroup
 
   @Test
   public void fail_if_template_uuid_and_name_provided() {
-    PermissionTemplateDto template1 = addTemplateToDefaultOrganization();
+    PermissionTemplateDto template1 = addTemplate();
     loginAsAdmin();
 
     expectedException.expect(BadRequestException.class);
@@ -352,7 +352,7 @@ public class TemplateGroupsActionTest extends BasePermissionWsTest<TemplateGroup
   @Test
   public void fail_if_not_a_project_permission() {
     loginAsAdmin();
-    PermissionTemplateDto template1 = addTemplateToDefaultOrganization();
+    PermissionTemplateDto template1 = addTemplate();
 
     expectedException.expect(IllegalArgumentException.class);
 
@@ -362,7 +362,7 @@ public class TemplateGroupsActionTest extends BasePermissionWsTest<TemplateGroup
       .execute();
   }
 
-  private GroupDto insertGroupOnDefaultOrganization(String name, String description) {
+  private GroupDto insertGroup(String name, String description) {
     return db.users().insertGroup(newGroupDto().setName(name).setDescription(description));
   }
 
index f30838390be9f88955857902292dc160b295d1ae..dd2fbff033fcd32415877cb884604512e0128baa 100644 (file)
@@ -26,8 +26,8 @@ import org.sonar.api.resources.Qualifiers;
 import org.sonar.api.resources.ResourceTypes;
 import org.sonar.api.server.ws.WebService;
 import org.sonar.api.web.UserRole;
-import org.sonar.core.permission.GlobalPermissions;
 import org.sonar.db.component.ResourceTypesRule;
+import org.sonar.db.permission.GlobalPermission;
 import org.sonar.db.permission.template.PermissionTemplateDto;
 import org.sonar.db.permission.template.PermissionTemplateUserDto;
 import org.sonar.db.user.UserDto;
@@ -60,10 +60,10 @@ import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_T
 
 public class TemplateUsersActionTest extends BasePermissionWsTest<TemplateUsersAction> {
 
-  private ResourceTypes resourceTypes = new ResourceTypesRule().setRootQualifiers(Qualifiers.PROJECT);
-  private PermissionService permissionService = new PermissionServiceImpl(resourceTypes);
-  private WsParameters wsParameters = new WsParameters(permissionService);
-  private RequestValidator requestValidator = new RequestValidator(permissionService);
+  private final ResourceTypes resourceTypes = new ResourceTypesRule().setRootQualifiers(Qualifiers.PROJECT);
+  private final PermissionService permissionService = new PermissionServiceImpl(resourceTypes);
+  private final WsParameters wsParameters = new WsParameters(permissionService);
+  private final RequestValidator requestValidator = new RequestValidator(permissionService);
 
   @Override
   protected TemplateUsersAction buildWsAction() {
@@ -79,7 +79,9 @@ public class TemplateUsersActionTest extends BasePermissionWsTest<TemplateUsersA
     assertThat(action.isPost()).isFalse();
     assertThat(action.isInternal()).isTrue();
     assertThat(action.since()).isEqualTo("5.2");
-    assertThat(action.param(PARAM_PERMISSION).isRequired()).isFalse();
+    WebService.Param permissionParam = action.param(PARAM_PERMISSION);
+    assertThat(permissionParam).isNotNull();
+    assertThat(permissionParam.isRequired()).isFalse();
   }
 
   @Test
@@ -87,7 +89,7 @@ public class TemplateUsersActionTest extends BasePermissionWsTest<TemplateUsersA
     UserDto user1 = insertUser(newUserDto().setLogin("admin").setName("Administrator").setEmail("admin@admin.com"));
     UserDto user2 = insertUser(newUserDto().setLogin("george.orwell").setName("George Orwell").setEmail("george.orwell@1984.net"));
 
-    PermissionTemplateDto template1 = addTemplateToDefaultOrganization();
+    PermissionTemplateDto template1 = addTemplate();
     addUserToTemplate(newPermissionTemplateUser(CODEVIEWER, template1, user1));
     addUserToTemplate(newPermissionTemplateUser(CODEVIEWER, template1, user2));
     addUserToTemplate(newPermissionTemplateUser(ADMIN, template1, user2));
@@ -105,13 +107,13 @@ public class TemplateUsersActionTest extends BasePermissionWsTest<TemplateUsersA
     UserDto user2 = insertUser(newUserDto().setLogin("login-2").setName("name-2").setEmail("email-2"));
     UserDto user3 = insertUser(newUserDto().setLogin("login-3").setName("name-3").setEmail("email-3"));
 
-    PermissionTemplateDto template = addTemplateToDefaultOrganization();
+    PermissionTemplateDto template = addTemplate();
     addUserToTemplate(newPermissionTemplateUser(USER, template, user1));
     addUserToTemplate(newPermissionTemplateUser(USER, template, user2));
     addUserToTemplate(newPermissionTemplateUser(ISSUE_ADMIN, template, user1));
     addUserToTemplate(newPermissionTemplateUser(ISSUE_ADMIN, template, user3));
 
-    PermissionTemplateDto anotherTemplate = addTemplateToDefaultOrganization();
+    PermissionTemplateDto anotherTemplate = addTemplate();
     addUserToTemplate(newPermissionTemplateUser(USER, anotherTemplate, user1));
 
     Permissions.UsersWsResponse response = newRequest(null, null)
@@ -132,13 +134,13 @@ public class TemplateUsersActionTest extends BasePermissionWsTest<TemplateUsersA
     UserDto user2 = insertUser(newUserDto().setLogin("login-2").setName("name-2").setEmail("email-2"));
     UserDto user3 = insertUser(newUserDto().setLogin("login-3").setName("name-3").setEmail("email-3"));
 
-    PermissionTemplateDto template = addTemplateToDefaultOrganization();
+    PermissionTemplateDto template = addTemplate();
     addUserToTemplate(newPermissionTemplateUser(USER, template, user1));
     addUserToTemplate(newPermissionTemplateUser(USER, template, user2));
     addUserToTemplate(newPermissionTemplateUser(ISSUE_ADMIN, template, user1));
     addUserToTemplate(newPermissionTemplateUser(ISSUE_ADMIN, template, user3));
 
-    PermissionTemplateDto anotherTemplate = addTemplateToDefaultOrganization();
+    PermissionTemplateDto anotherTemplate = addTemplate();
     addUserToTemplate(newPermissionTemplateUser(USER, anotherTemplate, user1));
 
     Permissions.UsersWsResponse response = newRequest(null, null)
@@ -155,13 +157,13 @@ public class TemplateUsersActionTest extends BasePermissionWsTest<TemplateUsersA
     UserDto user2 = insertUser(newUserDto().setLogin("login-2").setName("name-2").setEmail("email-2"));
     UserDto user3 = insertUser(newUserDto().setLogin("login-3").setName("name-3").setEmail("email-3"));
 
-    PermissionTemplateDto template = addTemplateToDefaultOrganization();
+    PermissionTemplateDto template = addTemplate();
     addUserToTemplate(newPermissionTemplateUser(USER, template, user1));
     addUserToTemplate(newPermissionTemplateUser(USER, template, user2));
     addUserToTemplate(newPermissionTemplateUser(ISSUE_ADMIN, template, user1));
     addUserToTemplate(newPermissionTemplateUser(ISSUE_ADMIN, template, user3));
 
-    PermissionTemplateDto anotherTemplate = addTemplateToDefaultOrganization();
+    PermissionTemplateDto anotherTemplate = addTemplate();
     addUserToTemplate(newPermissionTemplateUser(USER, anotherTemplate, user1));
 
     loginAsAdmin();
@@ -178,13 +180,13 @@ public class TemplateUsersActionTest extends BasePermissionWsTest<TemplateUsersA
     UserDto user2 = insertUser(newUserDto().setLogin("login-2").setName("name-2").setEmail("email-2"));
     UserDto user3 = insertUser(newUserDto().setLogin("login-3").setName("name-3").setEmail("email-3"));
 
-    PermissionTemplateDto template = addTemplateToDefaultOrganization();
+    PermissionTemplateDto template = addTemplate();
     addUserToTemplate(newPermissionTemplateUser(USER, template, user1));
     addUserToTemplate(newPermissionTemplateUser(USER, template, user2));
     addUserToTemplate(newPermissionTemplateUser(ISSUE_ADMIN, template, user1));
     addUserToTemplate(newPermissionTemplateUser(ISSUE_ADMIN, template, user3));
 
-    PermissionTemplateDto anotherTemplate = addTemplateToDefaultOrganization();
+    PermissionTemplateDto anotherTemplate = addTemplate();
     addUserToTemplate(newPermissionTemplateUser(USER, anotherTemplate, user1));
 
     loginAsAdmin();
@@ -204,7 +206,7 @@ public class TemplateUsersActionTest extends BasePermissionWsTest<TemplateUsersA
     UserDto user2 = insertUser(newUserDto().setLogin("login-3").setName("name-3"));
     UserDto user3 = insertUser(newUserDto().setLogin("login-1").setName("name-1"));
 
-    PermissionTemplateDto template = addTemplateToDefaultOrganization();
+    PermissionTemplateDto template = addTemplate();
     addUserToTemplate(newPermissionTemplateUser(USER, template, user1));
     addUserToTemplate(newPermissionTemplateUser(USER, template, user2));
     addUserToTemplate(newPermissionTemplateUser(ISSUE_ADMIN, template, user3));
@@ -219,7 +221,7 @@ public class TemplateUsersActionTest extends BasePermissionWsTest<TemplateUsersA
 
   @Test
   public void search_ignores_other_template_and_is_ordered_by_users_with_permission_when_many_users() {
-    PermissionTemplateDto template = addTemplateToDefaultOrganization();
+    PermissionTemplateDto template = addTemplate();
     // Add another template having some users with permission to make sure it's correctly ignored
     PermissionTemplateDto otherTemplate = db.permissionTemplates().insertTemplate();
     IntStream.rangeClosed(1, DEFAULT_PAGE_SIZE + 1).forEach(i -> {
@@ -242,12 +244,12 @@ public class TemplateUsersActionTest extends BasePermissionWsTest<TemplateUsersA
 
   @Test
   public void fail_if_not_a_project_permission() {
-    PermissionTemplateDto template = addTemplateToDefaultOrganization();
+    PermissionTemplateDto template = addTemplate();
     loginAsAdmin();
 
     expectedException.expect(IllegalArgumentException.class);
 
-    newRequest(GlobalPermissions.PROVISIONING, template.getUuid())
+    newRequest(GlobalPermission.PROVISION_PROJECTS.getKey(), template.getUuid())
       .execute();
   }
 
@@ -273,7 +275,7 @@ public class TemplateUsersActionTest extends BasePermissionWsTest<TemplateUsersA
 
   @Test
   public void fail_if_template_uuid_and_name_provided() {
-    PermissionTemplateDto template = addTemplateToDefaultOrganization();
+    PermissionTemplateDto template = addTemplate();
     loginAsAdmin();
 
     expectedException.expect(BadRequestException.class);
@@ -285,7 +287,7 @@ public class TemplateUsersActionTest extends BasePermissionWsTest<TemplateUsersA
 
   @Test
   public void fail_if_not_logged_in() {
-    PermissionTemplateDto template = addTemplateToDefaultOrganization();
+    PermissionTemplateDto template = addTemplate();
     userSession.anonymous();
 
     expectedException.expect(UnauthorizedException.class);
@@ -295,7 +297,7 @@ public class TemplateUsersActionTest extends BasePermissionWsTest<TemplateUsersA
 
   @Test
   public void fail_if_insufficient_privileges() {
-    PermissionTemplateDto template = addTemplateToDefaultOrganization();
+    PermissionTemplateDto template = addTemplate();
     userSession.logIn().addPermission(SCAN);
 
     expectedException.expect(ForbiddenException.class);
index 1531b84ecc365176b8499d1d47dbd06a7ae45954..6197d44409a12cdf68043c8b16399a89e708f25f 100644 (file)
@@ -45,7 +45,7 @@ import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_P
 
 public class UpdateTemplateActionTest extends BasePermissionWsTest<UpdateTemplateAction> {
 
-  private System2 system = spy(System2.INSTANCE);
+  private final System2 system = spy(System2.INSTANCE);
   private PermissionTemplateDto template;
 
   @Override
@@ -74,7 +74,7 @@ public class UpdateTemplateActionTest extends BasePermissionWsTest<UpdateTemplat
     assertJson(result)
       .ignoreFields("id")
       .isSimilarTo(getClass().getResource("update_template-example.json"));
-    PermissionTemplateDto finance = selectTemplateInDefaultOrganization("Finance");
+    PermissionTemplateDto finance = selectPermissionTemplate("Finance");
     assertThat(finance.getName()).isEqualTo("Finance");
     assertThat(finance.getDescription()).isEqualTo("Permissions for financially related projects");
     assertThat(finance.getKeyPattern()).isEqualTo(".*\\.finance\\..*");
@@ -101,7 +101,7 @@ public class UpdateTemplateActionTest extends BasePermissionWsTest<UpdateTemplat
 
     call(template.getUuid(), "Finance", null, null);
 
-    PermissionTemplateDto finance = selectTemplateInDefaultOrganization("Finance");
+    PermissionTemplateDto finance = selectPermissionTemplate("Finance");
     assertThat(finance.getName()).isEqualTo("Finance");
     assertThat(finance.getDescription()).isEqualTo(template.getDescription());
     assertThat(finance.getKeyPattern()).isEqualTo(template.getKeyPattern());
@@ -120,7 +120,7 @@ public class UpdateTemplateActionTest extends BasePermissionWsTest<UpdateTemplat
   @Test
   public void fail_if_name_already_exists_in_another_template() {
     loginAsAdmin();
-    PermissionTemplateDto anotherTemplate = addTemplateToDefaultOrganization();
+    PermissionTemplateDto anotherTemplate = addTemplate();
 
     expectedException.expect(BadRequestException.class);
     expectedException.expectMessage("A template with the name '" + anotherTemplate.getName() + "' already exists (case insensitive).");
@@ -170,7 +170,7 @@ public class UpdateTemplateActionTest extends BasePermissionWsTest<UpdateTemplat
   @Test
   public void fail_if_name_already_exists_in_database_case_insensitive() {
     loginAsAdmin();
-    PermissionTemplateDto anotherTemplate = addTemplateToDefaultOrganization();
+    PermissionTemplateDto anotherTemplate = addTemplate();
 
     String nameCaseInsensitive = anotherTemplate.getName().toUpperCase();
     expectedException.expect(BadRequestException.class);