From: Julien Lancelot Date: Fri, 8 Mar 2019 09:46:44 +0000 (+0100) Subject: Simplify PermissionTemplateService#hasDefaultTemplateWithPermissionOnProjectCreator X-Git-Tag: 7.7~50 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=eb54e11ba036b966f82e599a449efca15c58475e;p=sonarqube.git Simplify PermissionTemplateService#hasDefaultTemplateWithPermissionOnProjectCreator Remove the parameter 'organizationUuid' as it's already available in the ComponentDto parameter --- diff --git a/server/sonar-server/src/main/java/org/sonar/server/ce/queue/ReportSubmitter.java b/server/sonar-server/src/main/java/org/sonar/server/ce/queue/ReportSubmitter.java index d2ee41a2554..96fa87df0ea 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/ce/queue/ReportSubmitter.java +++ b/server/sonar-server/src/main/java/org/sonar/server/ce/queue/ReportSubmitter.java @@ -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(); } diff --git a/server/sonar-server/src/main/java/org/sonar/server/component/ComponentUpdater.java b/server/sonar-server/src/main/java/org/sonar/server/component/ComponentUpdater.java index 0eb1efecd36..0adfdb802c7 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/component/ComponentUpdater.java +++ b/server/sonar-server/src/main/java/org/sonar/server/component/ComponentUpdater.java @@ -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); } } diff --git a/server/sonar-server/src/main/java/org/sonar/server/permission/PermissionTemplateService.java b/server/sonar-server/src/main/java/org/sonar/server/permission/PermissionTemplateService.java index 140f6f12312..7e4295a516b 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/permission/PermissionTemplateService.java +++ b/server/sonar-server/src/main/java/org/sonar/server/permission/PermissionTemplateService.java @@ -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 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 allPermissionTemplates = dbClient.permissionTemplateDao().selectAll(dbSession, organizationUuid, null); List matchingTemplates = new ArrayList<>(); for (PermissionTemplateDto permissionTemplateDto : allPermissionTemplates) { diff --git a/server/sonar-server/src/test/java/org/sonar/server/ce/queue/BranchReportSubmitterTest.java b/server/sonar-server/src/test/java/org/sonar/server/ce/queue/BranchReportSubmitterTest.java index 9960fab0f24..232014af9ca 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/ce/queue/BranchReportSubmitterTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/ce/queue/BranchReportSubmitterTest.java @@ -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) 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); diff --git a/server/sonar-server/src/test/java/org/sonar/server/ce/queue/ReportSubmitterTest.java b/server/sonar-server/src/test/java/org/sonar/server/ce/queue/ReportSubmitterTest.java index c74dd885ec4..51c94ca8c69 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/ce/queue/ReportSubmitterTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/ce/queue/ReportSubmitterTest.java @@ -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 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}")); diff --git a/server/sonar-server/src/test/java/org/sonar/server/component/ComponentUpdaterTest.java b/server/sonar-server/src/test/java/org/sonar/server/component/ComponentUpdaterTest.java index b759ca71db1..3a39e42a538 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/component/ComponentUpdaterTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/component/ComponentUpdaterTest.java @@ -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(), diff --git a/server/sonar-server/src/test/java/org/sonar/server/permission/PermissionTemplateServiceTest.java b/server/sonar-server/src/test/java/org/sonar/server/permission/PermissionTemplateServiceTest.java index 8dd7516cbb4..88ae06abbc8 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/permission/PermissionTemplateServiceTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/permission/PermissionTemplateServiceTest.java @@ -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); }