]> source.dussan.org Git - sonarqube.git/commitdiff
Simplify PermissionTemplateService#hasDefaultTemplateWithPermissionOnProjectCreator
authorJulien Lancelot <julien.lancelot@sonarsource.com>
Fri, 8 Mar 2019 09:46:44 +0000 (10:46 +0100)
committerSonarTech <sonartech@sonarsource.com>
Mon, 18 Mar 2019 19:20:59 +0000 (20:20 +0100)
Remove the parameter 'organizationUuid' as it's already available in the ComponentDto parameter

server/sonar-server/src/main/java/org/sonar/server/ce/queue/ReportSubmitter.java
server/sonar-server/src/main/java/org/sonar/server/component/ComponentUpdater.java
server/sonar-server/src/main/java/org/sonar/server/permission/PermissionTemplateService.java
server/sonar-server/src/test/java/org/sonar/server/ce/queue/BranchReportSubmitterTest.java
server/sonar-server/src/test/java/org/sonar/server/ce/queue/ReportSubmitterTest.java
server/sonar-server/src/test/java/org/sonar/server/component/ComponentUpdaterTest.java
server/sonar-server/src/test/java/org/sonar/server/permission/PermissionTemplateServiceTest.java

index d2ee41a255434716f1bf26f07abef7394c94ee61..96fa87df0ea68aff44f9ad57bad5e3b57ad9b571 100644 (file)
@@ -164,7 +164,7 @@ public class ReportSubmitter {
     Integer userId = userSession.getUserId();
 
     boolean wouldCurrentUserHaveScanPermission = permissionTemplateService.wouldUserHaveScanPermissionWithDefaultTemplate(
-      dbSession, organization.getUuid(), userId, componentKey.getDbKey(), Qualifiers.PROJECT);
+      dbSession, organization.getUuid(), userId, componentKey.getDbKey());
     if (!wouldCurrentUserHaveScanPermission) {
       throw insufficientPrivilegesException();
     }
index 0eb1efecd36d4f1ad590b449843a0de8a9843c86..0adfdb802c79b0542081e3af83a2eba7a18171db 100644 (file)
@@ -91,7 +91,7 @@ public class ComponentUpdater {
       createMainBranch(dbSession, componentDto.uuid());
     }
     removeDuplicatedProjects(dbSession, componentDto.getDbKey());
-    handlePermissionTemplate(dbSession, componentDto, newComponent.getOrganizationUuid(), userId);
+    handlePermissionTemplate(dbSession, componentDto, userId);
     return componentDto;
   }
 
@@ -156,10 +156,10 @@ public class ComponentUpdater {
     }
   }
 
-  private void handlePermissionTemplate(DbSession dbSession, ComponentDto componentDto, String organizationUuid, @Nullable Integer userId) {
-    permissionTemplateService.applyDefault(dbSession, organizationUuid, componentDto, userId);
+  private void handlePermissionTemplate(DbSession dbSession, ComponentDto componentDto, @Nullable Integer userId) {
+    permissionTemplateService.applyDefault(dbSession, componentDto, userId);
     if (componentDto.qualifier().equals(PROJECT)
-      && permissionTemplateService.hasDefaultTemplateWithPermissionOnProjectCreator(dbSession, organizationUuid, componentDto)) {
+      && permissionTemplateService.hasDefaultTemplateWithPermissionOnProjectCreator(dbSession, componentDto)) {
       favoriteUpdater.add(dbSession, componentDto, userId);
     }
   }
index 140f6f12312db5956a7e905acdbecaf90b49db21..7e4295a516b44a35e7506ec996c7f85780deb727 100644 (file)
@@ -35,7 +35,6 @@ import org.sonar.db.DbSession;
 import org.sonar.db.component.ComponentDto;
 import org.sonar.db.organization.DefaultTemplates;
 import org.sonar.db.permission.GroupPermissionDto;
-import org.sonar.db.permission.OrganizationPermission;
 import org.sonar.db.permission.UserPermissionDto;
 import org.sonar.db.permission.template.PermissionTemplateCharacteristicDto;
 import org.sonar.db.permission.template.PermissionTemplateDto;
@@ -52,6 +51,7 @@ import static java.lang.String.format;
 import static java.util.Collections.singletonList;
 import static org.sonar.api.security.DefaultGroups.isAnyone;
 import static org.sonar.api.web.UserRole.PUBLIC_PERMISSIONS;
+import static org.sonar.db.permission.OrganizationPermission.SCAN;
 
 @ServerSide
 public class PermissionTemplateService {
@@ -69,21 +69,19 @@ public class PermissionTemplateService {
     this.defaultTemplatesResolver = defaultTemplatesResolver;
   }
 
-  public boolean wouldUserHaveScanPermissionWithDefaultTemplate(DbSession dbSession,
-    String organizationUuid, @Nullable Integer userId,
-    String projectKey, String qualifier) {
-    if (userSession.hasPermission(OrganizationPermission.SCAN, organizationUuid)) {
+  public boolean wouldUserHaveScanPermissionWithDefaultTemplate(DbSession dbSession, String organizationUuid, @Nullable Integer userId, String projectKey) {
+    if (userSession.hasPermission(SCAN, organizationUuid)) {
       return true;
     }
 
-    ComponentDto dto = new ComponentDto().setOrganizationUuid(organizationUuid).setDbKey(projectKey).setQualifier(qualifier);
-    PermissionTemplateDto template = findTemplate(dbSession, organizationUuid, dto);
+    ComponentDto dto = new ComponentDto().setOrganizationUuid(organizationUuid).setDbKey(projectKey).setQualifier(Qualifiers.PROJECT);
+    PermissionTemplateDto template = findTemplate(dbSession, dto);
     if (template == null) {
       return false;
     }
 
     List<String> potentialPermissions = dbClient.permissionTemplateDao().selectPotentialPermissionsByUserIdAndTemplateId(dbSession, userId, template.getId());
-    return potentialPermissions.contains(OrganizationPermission.SCAN.getKey());
+    return potentialPermissions.contains(SCAN.getKey());
   }
 
   /**
@@ -107,14 +105,14 @@ public class PermissionTemplateService {
    * can be provisioned (so has no permissions yet).
    * @param projectCreatorUserId id of the user who creates the project, only if project is provisioned. He will
    */
-  public void applyDefault(DbSession dbSession, String organizationUuid, ComponentDto component, @Nullable Integer projectCreatorUserId) {
-    PermissionTemplateDto template = findTemplate(dbSession, organizationUuid, component);
+  public void applyDefault(DbSession dbSession, ComponentDto component, @Nullable Integer projectCreatorUserId) {
+    PermissionTemplateDto template = findTemplate(dbSession, component);
     checkArgument(template != null, "Cannot retrieve default permission template");
     copyPermissions(dbSession, template, component, projectCreatorUserId);
   }
 
-  public boolean hasDefaultTemplateWithPermissionOnProjectCreator(DbSession dbSession, String organizationUuid, ComponentDto component) {
-    PermissionTemplateDto template = findTemplate(dbSession, organizationUuid, component);
+  public boolean hasDefaultTemplateWithPermissionOnProjectCreator(DbSession dbSession, ComponentDto component) {
+    PermissionTemplateDto template = findTemplate(dbSession, component);
     return hasProjectCreatorPermission(dbSession, template);
   }
 
@@ -181,7 +179,8 @@ public class PermissionTemplateService {
    * template for the component qualifier.
    */
   @CheckForNull
-  private PermissionTemplateDto findTemplate(DbSession dbSession, String organizationUuid, ComponentDto component) {
+  private PermissionTemplateDto findTemplate(DbSession dbSession, ComponentDto component) {
+    String organizationUuid = component.getOrganizationUuid();
     List<PermissionTemplateDto> allPermissionTemplates = dbClient.permissionTemplateDao().selectAll(dbSession, organizationUuid, null);
     List<PermissionTemplateDto> matchingTemplates = new ArrayList<>();
     for (PermissionTemplateDto permissionTemplateDto : allPermissionTemplates) {
index 9960fab0f24b2bf7524e47e746cf84212e0e9939..232014af9ca8da02c500dd7409219fed8925b048 100644 (file)
@@ -35,7 +35,6 @@ import org.junit.Test;
 import org.junit.rules.ExpectedException;
 import org.junit.runner.RunWith;
 import org.mockito.stubbing.Answer;
-import org.sonar.api.resources.Qualifiers;
 import org.sonar.api.utils.System2;
 import org.sonar.ce.queue.CeQueue;
 import org.sonar.ce.queue.CeQueueImpl;
@@ -208,8 +207,7 @@ public class BranchReportSubmitterTest {
       .thenAnswer((Answer<ComponentDto>) invocation -> db.components().insertMainBranch(nonExistingProject));
     when(branchSupportDelegate.createBranchComponent(any(DbSession.class), same(componentKey), eq(organization), eq(nonExistingProject), any()))
       .thenReturn(createdBranch);
-    when(permissionTemplateService.wouldUserHaveScanPermissionWithDefaultTemplate(any(), eq(organization.getUuid()), any(),
-      eq(nonExistingProject.getKey()), eq(Qualifiers.PROJECT)))
+    when(permissionTemplateService.wouldUserHaveScanPermissionWithDefaultTemplate(any(DbSession.class), eq(organization.getUuid()), any(), eq(nonExistingProject.getKey())))
       .thenReturn(true);
     String taskUuid = mockSuccessfulPrepareSubmitCall();
     InputStream reportInput = IOUtils.toInputStream("{binary}", StandardCharsets.UTF_8);
index c74dd885ec440a1efcf929926a285de25918feb0..51c94ca8c69c85f8e62b8de190fa1ac2bd42c18e 100644 (file)
@@ -29,7 +29,6 @@ import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.ExpectedException;
-import org.sonar.api.resources.Qualifiers;
 import org.sonar.api.utils.System2;
 import org.sonar.ce.queue.CeQueue;
 import org.sonar.ce.queue.CeQueueImpl;
@@ -112,8 +111,7 @@ public class ReportSubmitterTest {
     ComponentDto project = newPrivateProjectDto(db.getDefaultOrganization(), PROJECT_UUID).setDbKey(PROJECT_KEY);
     mockSuccessfulPrepareSubmitCall();
     when(componentUpdater.create(any(), any(), any())).thenReturn(project);
-    when(permissionTemplateService.wouldUserHaveScanPermissionWithDefaultTemplate(any(), eq(defaultOrganizationUuid), any(), eq(PROJECT_KEY),
-      eq(Qualifiers.PROJECT)))
+    when(permissionTemplateService.wouldUserHaveScanPermissionWithDefaultTemplate(any(), eq(defaultOrganizationUuid), any(), eq(PROJECT_KEY)))
       .thenReturn(true);
     Map<String, String> nonEmptyCharacteristics = IntStream.range(0, 1 + new Random().nextInt(5))
       .boxed()
@@ -135,9 +133,8 @@ public class ReportSubmitterTest {
     ComponentDto project = newPrivateProjectDto(db.getDefaultOrganization(), PROJECT_UUID).setDbKey(PROJECT_KEY);
     mockSuccessfulPrepareSubmitCall();
     when(componentUpdater.createWithoutCommit(any(), any(), any())).thenReturn(project);
-    when(permissionTemplateService.wouldUserHaveScanPermissionWithDefaultTemplate(any(), eq(defaultOrganizationUuid), any(), eq(PROJECT_KEY),
-      eq(Qualifiers.PROJECT)))
-        .thenReturn(true);
+    when(permissionTemplateService.wouldUserHaveScanPermissionWithDefaultTemplate(any(), eq(defaultOrganizationUuid), any(), eq(PROJECT_KEY)))
+      .thenReturn(true);
 
     underTest.submit(defaultOrganizationKey, PROJECT_KEY, null, PROJECT_NAME, emptyMap(), IOUtils.toInputStream("{binary}", UTF_8));
 
@@ -174,9 +171,9 @@ public class ReportSubmitterTest {
     ComponentDto createdProject = newPrivateProjectDto(organization, PROJECT_UUID).setDbKey(PROJECT_KEY);
     when(componentUpdater.createWithoutCommit(any(), any(), isNull())).thenReturn(createdProject);
     when(
-      permissionTemplateService.wouldUserHaveScanPermissionWithDefaultTemplate(any(), eq(organization.getUuid()), any(), eq(PROJECT_KEY), eq(Qualifiers.PROJECT)))
+      permissionTemplateService.wouldUserHaveScanPermissionWithDefaultTemplate(any(DbSession.class), eq(organization.getUuid()), any(), eq(PROJECT_KEY)))
         .thenReturn(true);
-    when(permissionTemplateService.hasDefaultTemplateWithPermissionOnProjectCreator(any(), eq(organization.getUuid()), any())).thenReturn(true);
+    when(permissionTemplateService.hasDefaultTemplateWithPermissionOnProjectCreator(any(DbSession.class), any(ComponentDto.class))).thenReturn(true);
 
     underTest.submit(organization.getKey(), PROJECT_KEY, null, PROJECT_NAME, emptyMap(), IOUtils.toInputStream("{binary}"));
 
@@ -195,10 +192,9 @@ public class ReportSubmitterTest {
 
     ComponentDto createdProject = newPrivateProjectDto(db.getDefaultOrganization(), PROJECT_UUID).setDbKey(PROJECT_KEY);
     when(componentUpdater.createWithoutCommit(any(), any(), isNull())).thenReturn(createdProject);
-    when(permissionTemplateService.wouldUserHaveScanPermissionWithDefaultTemplate(any(), eq(defaultOrganizationUuid), any(),
-      eq(PROJECT_KEY), eq(Qualifiers.PROJECT)))
-        .thenReturn(true);
-    when(permissionTemplateService.hasDefaultTemplateWithPermissionOnProjectCreator(any(), eq(defaultOrganizationUuid), any())).thenReturn(false);
+    when(permissionTemplateService.wouldUserHaveScanPermissionWithDefaultTemplate(any(DbSession.class), eq(defaultOrganizationUuid), any(), eq(PROJECT_KEY)))
+      .thenReturn(true);
+    when(permissionTemplateService.hasDefaultTemplateWithPermissionOnProjectCreator(any(DbSession.class), any(ComponentDto.class))).thenReturn(false);
     mockSuccessfulPrepareSubmitCall();
 
     underTest.submit(defaultOrganizationKey, PROJECT_KEY, null, PROJECT_NAME, emptyMap(), IOUtils.toInputStream("{binary}"));
@@ -216,9 +212,8 @@ public class ReportSubmitterTest {
     ComponentDto project = newPrivateProjectDto(db.getDefaultOrganization(), PROJECT_UUID).setDbKey(PROJECT_KEY);
     mockSuccessfulPrepareSubmitCall();
     when(componentUpdater.createWithoutCommit(any(), any(), any())).thenReturn(project);
-    when(permissionTemplateService.wouldUserHaveScanPermissionWithDefaultTemplate(any(), eq(defaultOrganizationUuid), any(),
-      eq(PROJECT_KEY), eq(Qualifiers.PROJECT)))
-        .thenReturn(true);
+    when(permissionTemplateService.wouldUserHaveScanPermissionWithDefaultTemplate(any(DbSession.class), eq(defaultOrganizationUuid), any(), eq(PROJECT_KEY)))
+      .thenReturn(true);
 
     underTest.submit(defaultOrganizationKey, PROJECT_KEY, null, PROJECT_NAME, emptyMap(), IOUtils.toInputStream("{binary}"));
 
index b759ca71db1857382a3e332b291232f06de242a2..3a39e42a53834b825324e6bfeee661af3582ba91 100644 (file)
@@ -203,7 +203,7 @@ public class ComponentUpdaterTest {
       .build();
     ComponentDto dto = underTest.create(db.getSession(), project, userId);
 
-    verify(permissionTemplateService).applyDefault(db.getSession(), dto.getOrganizationUuid(), dto, userId);
+    verify(permissionTemplateService).applyDefault(db.getSession(), dto, userId);
   }
 
   @Test
@@ -214,7 +214,7 @@ public class ComponentUpdaterTest {
       .setName(DEFAULT_PROJECT_NAME)
       .setOrganizationUuid(db.getDefaultOrganization().getUuid())
       .build();
-    when(permissionTemplateService.hasDefaultTemplateWithPermissionOnProjectCreator(eq(db.getSession()), eq(project.getOrganizationUuid()), any(ComponentDto.class)))
+    when(permissionTemplateService.hasDefaultTemplateWithPermissionOnProjectCreator(eq(db.getSession()), any(ComponentDto.class)))
       .thenReturn(true);
 
     ComponentDto dto = underTest.create(db.getSession(),
index 8dd7516cbb4c6f5d1bfb4b3372d651f340333622..88ae06abbc8d9e07aab29db1627eee9c1d528da4 100644 (file)
@@ -28,7 +28,6 @@ import org.sonar.api.resources.Qualifiers;
 import org.sonar.api.resources.ResourceTypes;
 import org.sonar.api.utils.internal.AlwaysIncreasingSystem2;
 import org.sonar.api.web.UserRole;
-import org.sonar.core.permission.GlobalPermissions;
 import org.sonar.db.DbSession;
 import org.sonar.db.DbTester;
 import org.sonar.db.component.ComponentDto;
@@ -45,9 +44,9 @@ import org.sonar.server.tester.UserSessionRule;
 
 import static java.util.Collections.singletonList;
 import static org.assertj.core.api.Assertions.assertThat;
-import static org.sonar.core.permission.GlobalPermissions.SCAN_EXECUTION;
 import static org.sonar.db.permission.OrganizationPermission.ADMINISTER;
 import static org.sonar.db.permission.OrganizationPermission.PROVISION_PROJECTS;
+import static org.sonar.db.permission.OrganizationPermission.SCAN;
 
 public class PermissionTemplateServiceTest {
 
@@ -89,7 +88,7 @@ public class PermissionTemplateServiceTest {
     dbTester.permissionTemplates().addAnyoneToTemplate(permissionTemplate, "p1");
     dbTester.organizations().setDefaultTemplates(organization, permissionTemplate.getUuid(), null, null);
 
-    underTest.applyDefault(session, organization.getUuid(), privateProject, creator.getId());
+    underTest.applyDefault(session, privateProject, creator.getId());
 
     assertThat(selectProjectPermissionsOfGroup(organization, null, privateProject)).isEmpty();
   }
@@ -106,7 +105,7 @@ public class PermissionTemplateServiceTest {
     underTest.applyAndCommit(session, permissionTemplate, singletonList(publicProject));
 
     assertThat(selectProjectPermissionsOfGroup(organization, null, publicProject))
-      .containsOnly("p1", UserRole.ADMIN, UserRole.ISSUE_ADMIN, UserRole.SECURITYHOTSPOT_ADMIN, GlobalPermissions.SCAN_EXECUTION);
+      .containsOnly("p1", UserRole.ADMIN, UserRole.ISSUE_ADMIN, UserRole.SECURITYHOTSPOT_ADMIN, SCAN.getKey());
   }
 
   @Test
@@ -119,10 +118,10 @@ public class PermissionTemplateServiceTest {
     dbTester.permissionTemplates().addAnyoneToTemplate(permissionTemplate, "p1");
     dbTester.organizations().setDefaultTemplates(organization, permissionTemplate.getUuid(), null, null);
 
-    underTest.applyDefault(session, organization.getUuid(), publicProject, null);
+    underTest.applyDefault(session, publicProject, null);
 
     assertThat(selectProjectPermissionsOfGroup(organization, null, publicProject))
-      .containsOnly("p1", UserRole.ADMIN, UserRole.ISSUE_ADMIN, UserRole.SECURITYHOTSPOT_ADMIN, GlobalPermissions.SCAN_EXECUTION);
+      .containsOnly("p1", UserRole.ADMIN, UserRole.ISSUE_ADMIN, UserRole.SECURITYHOTSPOT_ADMIN, SCAN.getKey());
   }
 
   @Test
@@ -138,7 +137,7 @@ public class PermissionTemplateServiceTest {
     underTest.applyAndCommit(session, permissionTemplate, singletonList(privateProject));
 
     assertThat(selectProjectPermissionsOfGroup(organization, group, privateProject))
-      .containsOnly("p1", UserRole.CODEVIEWER, UserRole.USER, UserRole.ADMIN, UserRole.ISSUE_ADMIN, UserRole.SECURITYHOTSPOT_ADMIN, GlobalPermissions.SCAN_EXECUTION);
+      .containsOnly("p1", UserRole.CODEVIEWER, UserRole.USER, UserRole.ADMIN, UserRole.ISSUE_ADMIN, UserRole.SECURITYHOTSPOT_ADMIN, SCAN.getKey());
   }
 
   @Test
@@ -152,10 +151,10 @@ public class PermissionTemplateServiceTest {
     dbTester.permissionTemplates().addGroupToTemplate(permissionTemplate, group, "p1");
     dbTester.organizations().setDefaultTemplates(organization, permissionTemplate.getUuid(), null, null);
 
-    underTest.applyDefault(session, organization.getUuid(), privateProject, null);
+    underTest.applyDefault(session, privateProject, null);
 
     assertThat(selectProjectPermissionsOfGroup(organization, group, privateProject))
-      .containsOnly("p1", UserRole.CODEVIEWER, UserRole.USER, UserRole.ADMIN, UserRole.ISSUE_ADMIN, UserRole.SECURITYHOTSPOT_ADMIN, GlobalPermissions.SCAN_EXECUTION);
+      .containsOnly("p1", UserRole.CODEVIEWER, UserRole.USER, UserRole.ADMIN, UserRole.ISSUE_ADMIN, UserRole.SECURITYHOTSPOT_ADMIN, SCAN.getKey());
   }
 
   @Test
@@ -171,7 +170,7 @@ public class PermissionTemplateServiceTest {
     underTest.applyAndCommit(session, permissionTemplate, singletonList(publicProject));
 
     assertThat(selectProjectPermissionsOfGroup(organization, group, publicProject))
-      .containsOnly("p1", UserRole.ADMIN, UserRole.ISSUE_ADMIN, UserRole.SECURITYHOTSPOT_ADMIN, GlobalPermissions.SCAN_EXECUTION);
+      .containsOnly("p1", UserRole.ADMIN, UserRole.ISSUE_ADMIN, UserRole.SECURITYHOTSPOT_ADMIN, SCAN.getKey());
   }
 
   @Test
@@ -185,10 +184,10 @@ public class PermissionTemplateServiceTest {
     dbTester.permissionTemplates().addGroupToTemplate(permissionTemplate, group, "p1");
     dbTester.organizations().setDefaultTemplates(organization, permissionTemplate.getUuid(), null, null);
 
-    underTest.applyDefault(session, organization.getUuid(), publicProject, null);
+    underTest.applyDefault(session, publicProject, null);
 
     assertThat(selectProjectPermissionsOfGroup(organization, group, publicProject))
-      .containsOnly("p1", UserRole.ADMIN, UserRole.ISSUE_ADMIN, UserRole.SECURITYHOTSPOT_ADMIN, GlobalPermissions.SCAN_EXECUTION);
+      .containsOnly("p1", UserRole.ADMIN, UserRole.ISSUE_ADMIN, UserRole.SECURITYHOTSPOT_ADMIN, SCAN.getKey());
   }
 
   @Test
@@ -204,7 +203,7 @@ public class PermissionTemplateServiceTest {
     underTest.applyAndCommit(session, permissionTemplate, singletonList(publicProject));
 
     assertThat(selectProjectPermissionsOfUser(user, publicProject))
-      .containsOnly("p1", UserRole.ADMIN, UserRole.ISSUE_ADMIN, UserRole.SECURITYHOTSPOT_ADMIN, GlobalPermissions.SCAN_EXECUTION);
+      .containsOnly("p1", UserRole.ADMIN, UserRole.ISSUE_ADMIN, UserRole.SECURITYHOTSPOT_ADMIN, SCAN.getKey());
   }
 
   @Test
@@ -218,10 +217,10 @@ public class PermissionTemplateServiceTest {
     dbTester.permissionTemplates().addUserToTemplate(permissionTemplate, user, "p1");
     dbTester.organizations().setDefaultTemplates(organization, permissionTemplate.getUuid(), null, null);
 
-    underTest.applyDefault(session, organization.getUuid(), publicProject, null);
+    underTest.applyDefault(session, publicProject, null);
 
     assertThat(selectProjectPermissionsOfUser(user, publicProject))
-      .containsOnly("p1", UserRole.ADMIN, UserRole.ISSUE_ADMIN, UserRole.SECURITYHOTSPOT_ADMIN, GlobalPermissions.SCAN_EXECUTION);
+      .containsOnly("p1", UserRole.ADMIN, UserRole.ISSUE_ADMIN, UserRole.SECURITYHOTSPOT_ADMIN, SCAN.getKey());
   }
 
   @Test
@@ -237,7 +236,7 @@ public class PermissionTemplateServiceTest {
     underTest.applyAndCommit(session, permissionTemplate, singletonList(privateProject));
 
     assertThat(selectProjectPermissionsOfUser(user, privateProject))
-      .containsOnly("p1", UserRole.CODEVIEWER, UserRole.USER, UserRole.ADMIN, UserRole.ISSUE_ADMIN, UserRole.SECURITYHOTSPOT_ADMIN, GlobalPermissions.SCAN_EXECUTION);
+      .containsOnly("p1", UserRole.CODEVIEWER, UserRole.USER, UserRole.ADMIN, UserRole.ISSUE_ADMIN, UserRole.SECURITYHOTSPOT_ADMIN, SCAN.getKey());
   }
 
   @Test
@@ -251,10 +250,10 @@ public class PermissionTemplateServiceTest {
     dbTester.permissionTemplates().addUserToTemplate(permissionTemplate, user, "p1");
     dbTester.organizations().setDefaultTemplates(organization, permissionTemplate.getUuid(), null, null);
 
-    underTest.applyDefault(session, organization.getUuid(), privateProject, null);
+    underTest.applyDefault(session, privateProject, null);
 
     assertThat(selectProjectPermissionsOfUser(user, privateProject))
-      .containsOnly("p1", UserRole.CODEVIEWER, UserRole.USER, UserRole.ADMIN, UserRole.ISSUE_ADMIN, UserRole.SECURITYHOTSPOT_ADMIN, GlobalPermissions.SCAN_EXECUTION);
+      .containsOnly("p1", UserRole.CODEVIEWER, UserRole.USER, UserRole.ADMIN, UserRole.ISSUE_ADMIN, UserRole.SECURITYHOTSPOT_ADMIN, SCAN.getKey());
   }
 
   @Test
@@ -268,10 +267,10 @@ public class PermissionTemplateServiceTest {
     dbTester.permissionTemplates().addProjectCreatorToTemplate(permissionTemplate, "p1");
     dbTester.organizations().setDefaultTemplates(organization, permissionTemplate.getUuid(), null, null);
 
-    underTest.applyDefault(session, organization.getUuid(), publicProject, user.getId());
+    underTest.applyDefault(session, publicProject, user.getId());
 
     assertThat(selectProjectPermissionsOfUser(user, publicProject))
-      .containsOnly("p1", UserRole.ADMIN, UserRole.ISSUE_ADMIN, UserRole.SECURITYHOTSPOT_ADMIN, GlobalPermissions.SCAN_EXECUTION);
+      .containsOnly("p1", UserRole.ADMIN, UserRole.ISSUE_ADMIN, UserRole.SECURITYHOTSPOT_ADMIN, SCAN.getKey());
   }
 
   @Test
@@ -285,10 +284,10 @@ public class PermissionTemplateServiceTest {
     dbTester.permissionTemplates().addProjectCreatorToTemplate(permissionTemplate, "p1");
     dbTester.organizations().setDefaultTemplates(organization, permissionTemplate.getUuid(), null, null);
 
-    underTest.applyDefault(session, organization.getUuid(), privateProject, user.getId());
+    underTest.applyDefault(session, privateProject, user.getId());
 
     assertThat(selectProjectPermissionsOfUser(user, privateProject))
-      .containsOnly("p1", UserRole.CODEVIEWER, UserRole.USER, UserRole.ADMIN, UserRole.ISSUE_ADMIN, UserRole.SECURITYHOTSPOT_ADMIN, GlobalPermissions.SCAN_EXECUTION);
+      .containsOnly("p1", UserRole.CODEVIEWER, UserRole.USER, UserRole.ADMIN, UserRole.ISSUE_ADMIN, UserRole.SECURITYHOTSPOT_ADMIN, SCAN.getKey());
   }
 
   @Test
@@ -301,7 +300,7 @@ public class PermissionTemplateServiceTest {
     dbTester.permissionTemplates().addGroupToTemplate(permissionTemplate, group, PROVISION_PROJECTS.getKey());
     dbTester.organizations().setDefaultTemplates(organization, permissionTemplate.getUuid(), null, null);
 
-    underTest.applyDefault(session, organization.getUuid(), view, null);
+    underTest.applyDefault(session, view, null);
 
     assertThat(selectProjectPermissionsOfGroup(organization, group, view))
       .containsOnly(ADMINISTER.getKey(), PROVISION_PROJECTS.getKey());
@@ -318,7 +317,7 @@ public class PermissionTemplateServiceTest {
     dbTester.permissionTemplates().addGroupToTemplate(appPermissionTemplate, group, PROVISION_PROJECTS.getKey());
     dbTester.organizations().setDefaultTemplates(organization, projectPermissionTemplate.getUuid(), appPermissionTemplate.getUuid(), null);
 
-    underTest.applyDefault(session, organization.getUuid(), view, null);
+    underTest.applyDefault(session, view, null);
 
     assertThat(selectProjectPermissionsOfGroup(organization, group, view))
       .containsOnly(ADMINISTER.getKey(), PROVISION_PROJECTS.getKey());
@@ -335,7 +334,7 @@ public class PermissionTemplateServiceTest {
     dbTester.permissionTemplates().addGroupToTemplate(portPermissionTemplate, group, PROVISION_PROJECTS.getKey());
     dbTester.organizations().setDefaultTemplates(organization, projectPermissionTemplate.getUuid(), null, portPermissionTemplate.getUuid());
 
-    underTest.applyDefault(session, organization.getUuid(), view, null);
+    underTest.applyDefault(session, view, null);
 
     assertThat(selectProjectPermissionsOfGroup(organization, group, view))
       .containsOnly(ADMINISTER.getKey(), PROVISION_PROJECTS.getKey());
@@ -350,7 +349,7 @@ public class PermissionTemplateServiceTest {
     dbTester.permissionTemplates().addGroupToTemplate(projectPermissionTemplate, group, PROVISION_PROJECTS.getKey());
     dbTester.organizations().setDefaultTemplates(organization, projectPermissionTemplate.getUuid(), null, null);
 
-    underTest.applyDefault(session, organization.getUuid(), view, null);
+    underTest.applyDefault(session, view, null);
 
     assertThat(selectProjectPermissionsOfGroup(organization, group, view)).containsOnly(PROVISION_PROJECTS.getKey());
   }
@@ -365,7 +364,7 @@ public class PermissionTemplateServiceTest {
     dbTester.permissionTemplates().addGroupToTemplate(permissionTemplate, group, PROVISION_PROJECTS.getKey());
     dbTester.organizations().setDefaultTemplates(organization, permissionTemplate.getUuid(), null, null);
 
-    underTest.applyDefault(session, organization.getUuid(), application, null);
+    underTest.applyDefault(session, application, null);
 
     assertThat(selectProjectPermissionsOfGroup(organization, group, application))
       .containsOnly(ADMINISTER.getKey(), PROVISION_PROJECTS.getKey());
@@ -383,7 +382,7 @@ public class PermissionTemplateServiceTest {
     dbTester.permissionTemplates().addGroupToTemplate(appPermissionTemplate, group, PROVISION_PROJECTS.getKey());
     dbTester.organizations().setDefaultTemplates(organization, projectPermissionTemplate.getUuid(), appPermissionTemplate.getUuid(), portPermissionTemplate.getUuid());
 
-    underTest.applyDefault(session, organization.getUuid(), application, null);
+    underTest.applyDefault(session, application, null);
 
     assertThat(selectProjectPermissionsOfGroup(organization, group, application))
       .containsOnly(ADMINISTER.getKey(), PROVISION_PROJECTS.getKey());
@@ -398,7 +397,7 @@ public class PermissionTemplateServiceTest {
     dbTester.permissionTemplates().addGroupToTemplate(projectPermissionTemplate, group, PROVISION_PROJECTS.getKey());
     dbTester.organizations().setDefaultTemplates(organization, projectPermissionTemplate.getUuid(), null, null);
 
-    underTest.applyDefault(session, organization.getUuid(), application, null);
+    underTest.applyDefault(session, application, null);
 
     assertThat(selectProjectPermissionsOfGroup(organization, group, application)).containsOnly(PROVISION_PROJECTS.getKey());
   }
@@ -453,7 +452,7 @@ public class PermissionTemplateServiceTest {
     dbTester.users().insertMember(group, user);
     PermissionTemplateDto template = templateDb.insertTemplate(organization);
     dbTester.organizations().setDefaultTemplates(template, null, null);
-    templateDb.addProjectCreatorToTemplate(template.getId(), SCAN_EXECUTION);
+    templateDb.addProjectCreatorToTemplate(template.getId(), SCAN.getKey());
     templateDb.addUserToTemplate(template.getId(), user.getId(), UserRole.USER);
     templateDb.addGroupToTemplate(template.getId(), group.getId(), UserRole.CODEVIEWER);
     templateDb.addGroupToTemplate(template.getId(), null, UserRole.ISSUE_ADMIN);
@@ -481,7 +480,7 @@ public class PermissionTemplateServiceTest {
   }
 
   private void checkWouldUserHaveScanPermission(OrganizationDto organization, @Nullable Integer userId, boolean expectedResult) {
-    assertThat(underTest.wouldUserHaveScanPermissionWithDefaultTemplate(session, organization.getUuid(), userId, "PROJECT_KEY", Qualifiers.PROJECT))
+    assertThat(underTest.wouldUserHaveScanPermissionWithDefaultTemplate(session, organization.getUuid(), userId, "PROJECT_KEY"))
       .isEqualTo(expectedResult);
   }