public boolean wouldUserHaveScanPermissionWithDefaultTemplate(DbSession dbSession, String organizationUuid, @Nullable Integer userId, String projectKey, String qualifier) { if (userSession.hasPermission(OrganizationPermission.SCAN, organizationUuid)) { return true; } ComponentDto dto = new ComponentDto().setOrganizationUuid(organizationUuid).setDbKey(projectKey).setQualifier(qualifier); PermissionTemplateDto template = findTemplate(dbSession, organizationUuid, dto); if (template == null) { return false; } List<String> potentialPermissions = dbClient.permissionTemplateDao().selectPotentialPermissionsByUserIdAndTemplateId(dbSession, userId, template.getId()); return potentialPermissions.contains(OrganizationPermission.SCAN.getKey()); }
private ComponentDto newViewDto(OrganizationDto organizationDto) { return ComponentTesting.newView(organizationDto, VIEW_UUID) .setOrganizationUuid(ORGANIZATION_UUID) .setDbKey(VIEW_KEY) .setName(VIEW_NAME); }
@Test public void do_nothing_if_no_webhooks() { ComponentDto componentDto = componentDbTester.insertPrivateProject().setOrganizationUuid(defaultOrganizationProvider.get().getUuid()); underTest.sendProjectAnalysisUpdate(new WebHooks.Analysis(componentDto.uuid(), "1", "#1"), () -> mock); assertThat(caller.countSent()).isEqualTo(0); assertThat(logTester.logs(DEBUG)).isEmpty(); verifyZeroInteractions(deliveryStorage); }
private ComponentDto createBase(Component component) { String componentKey = component.getDbKey(); String componentUuid = component.getUuid(); ComponentDto componentDto = new ComponentDto(); componentDto.setOrganizationUuid(analysisMetadataHolder.getOrganization().getUuid()); componentDto.setUuid(componentUuid); componentDto.setDbKey(componentKey); componentDto.setMainBranchProjectUuid(mainBranchProjectUuid); componentDto.setEnabled(true); componentDto.setCreatedAt(new Date(system2.now())); return componentDto; }
@Test public void isEnabled_returns_true_if_one_valid_project_webhook() { String organizationUuid = defaultOrganizationProvider.get().getUuid(); ComponentDto componentDto = componentDbTester.insertPrivateProject().setOrganizationUuid(organizationUuid); webhookDbTester.insert(newWebhook(componentDto).setName("First").setUrl("http://url1")); assertThat(underTest.isEnabled(componentDto)).isTrue(); }
private ComponentDto insertComponent(String key, String uuid) { ComponentDto componentDto = new ComponentDto() .setOrganizationUuid("org1") .setDbKey(key) .setUuid(uuid) .setUuidPath(uuid + ".") .setRootUuid(uuid) .setProjectUuid(uuid); dbClient.componentDao().insert(db.getSession(), componentDto); return componentDto; }
private ComponentDto insertComponent(String key, String uuid) { ComponentDto componentDto = new ComponentDto() .setOrganizationUuid("org1") .setDbKey(key) .setUuid(uuid) .setUuidPath(uuid + ".") .setRootUuid(uuid) .setProjectUuid(uuid); dbClient.componentDao().insert(db.getSession(), componentDto); return componentDto; }
@Test public void select_deselected_projects() { ComponentDto project1 = db.components().insertPrivateProject(t -> t.setName("Project1 name"), t -> t.setOrganizationUuid(organization.getUuid())); ComponentDto project2 = db.components().insertPrivateProject(t -> t.setName("Project2 name"), t -> t.setOrganizationUuid(organization.getUuid())); ComponentDto project3 = db.components().insertPrivateProject(t -> t.setName("Project3 name"), t -> t.setOrganizationUuid(organization.getUuid())); OrganizationDto organization2 = db.organizations().insert(); ComponentDto project4 = db.components().insertPrivateProject(t -> t.setName("Project4 name"), t -> t.setOrganizationUuid(organization2.getUuid())); ComponentDto branch = db.components().insertProjectBranch(project1, t -> t.setKey("branch")); QProfileDto profile1 = newQualityProfileDto(); db.qualityProfiles().insert(profile1); db.qualityProfiles().associateWithProject(project1, profile1); QProfileDto profile2 = newQualityProfileDto(); db.qualityProfiles().insert(profile2); db.qualityProfiles().associateWithProject(project2, profile2); QProfileDto profile3 = newQualityProfileDto(); assertThat(underTest.selectDeselectedProjects(dbSession, organization, profile1, null)) .extracting("projectId", "projectUuid", "projectKey", "projectName", "profileKey") .containsExactly( tuple(project2.getId(), project2.uuid(), project2.getDbKey(), project2.name(), null), tuple(project3.getId(), project3.uuid(), project3.getDbKey(), project3.name(), null)); assertThat(underTest.selectDeselectedProjects(dbSession, organization, profile1, "ect2")).hasSize(1); assertThat(underTest.selectDeselectedProjects(dbSession, organization, profile3, null)).hasSize(3); }
@Test public void select_selected_projects() { ComponentDto project1 = db.components().insertPrivateProject(t -> t.setName("Project1 name"), t -> t.setOrganizationUuid(organization.getUuid())); ComponentDto project2 = db.components().insertPrivateProject(t -> t.setName("Project2 name"), t -> t.setOrganizationUuid(organization.getUuid())); ComponentDto project3 = db.components().insertPrivateProject(t -> t.setName("Project3 name"), t -> t.setOrganizationUuid(organization.getUuid())); OrganizationDto organization2 = db.organizations().insert(); ComponentDto project4 = db.components().insertPrivateProject(t -> t.setName("Project4 name"), t -> t.setOrganizationUuid(organization2.getUuid())); ComponentDto branch = db.components().insertProjectBranch(project1, t -> t.setKey("branch")); QProfileDto profile1 = newQualityProfileDto(); db.qualityProfiles().insert(profile1); db.qualityProfiles().associateWithProject(project1, profile1); db.qualityProfiles().associateWithProject(project2, profile1); QProfileDto profile2 = newQualityProfileDto(); db.qualityProfiles().insert(profile2); db.qualityProfiles().associateWithProject(project3, profile2); QProfileDto profile3 = newQualityProfileDto(); assertThat(underTest.selectSelectedProjects(dbSession, organization, profile1, null)) .extracting("projectId", "projectUuid", "projectKey", "projectName", "profileKey") .containsOnly( tuple(project1.getId(), project1.uuid(), project1.getDbKey(), project1.name(), profile1.getKee()), tuple(project2.getId(), project2.uuid(), project2.getDbKey(), project2.name(), profile1.getKee())); assertThat(underTest.selectSelectedProjects(dbSession, organization, profile1, "ect1")).hasSize(1); assertThat(underTest.selectSelectedProjects(dbSession, organization, profile3, null)).isEmpty(); }
private ComponentDto createRootComponent(DbSession session, NewComponent newComponent) { checkBranchFormat(newComponent.qualifier(), newComponent.deprecatedBranch()); String keyWithBranch = ComponentKeys.createKey(newComponent.key(), newComponent.deprecatedBranch()); checkRequest(!dbClient.componentDao().selectByKey(session, keyWithBranch).isPresent(), "Could not create %s, key already exists: %s", getQualifierToDisplay(newComponent.qualifier()), keyWithBranch); String uuid = Uuids.create(); ComponentDto component = new ComponentDto() .setOrganizationUuid(newComponent.getOrganizationUuid()) .setUuid(uuid) .setUuidPath(ComponentDto.UUID_PATH_OF_ROOT) .setRootUuid(uuid) .setModuleUuid(null) .setModuleUuidPath(ComponentDto.UUID_PATH_SEPARATOR + uuid + ComponentDto.UUID_PATH_SEPARATOR) .setProjectUuid(uuid) .setDbKey(keyWithBranch) .setName(newComponent.name()) .setLongName(newComponent.name()) .setScope(Scopes.PROJECT) .setQualifier(newComponent.qualifier()) .setPrivate(newComponent.isPrivate()) .setCreatedAt(new Date(system2.now())); dbClient.componentDao().insert(session, component); return component; }
@Test public void select_project_associations() { ComponentDto project1 = db.components().insertPrivateProject(t -> t.setName("Project1 name"), t -> t.setOrganizationUuid(organization.getUuid())); ComponentDto project2 = db.components().insertPrivateProject(t -> t.setName("Project2 name"), t -> t.setOrganizationUuid(organization.getUuid())); ComponentDto project3 = db.components().insertPrivateProject(t -> t.setName("Project3 name"), t -> t.setOrganizationUuid(organization.getUuid())); OrganizationDto organization2 = db.organizations().insert(); ComponentDto project4 = db.components().insertPrivateProject(t -> t.setName("Project4 name"), t -> t.setOrganizationUuid(organization2.getUuid())); ComponentDto branch = db.components().insertProjectBranch(project1, t -> t.setKey("branch")); QProfileDto profile1 = newQualityProfileDto(); db.qualityProfiles().insert(profile1); db.qualityProfiles().associateWithProject(project1, profile1); QProfileDto profile2 = newQualityProfileDto(); db.qualityProfiles().insert(profile2); db.qualityProfiles().associateWithProject(project2, profile2); QProfileDto profile3 = newQualityProfileDto(); assertThat(underTest.selectProjectAssociations(dbSession, organization, profile1, null)) .extracting("projectId", "projectUuid", "projectKey", "projectName", "profileKey") .containsOnly( tuple(project1.getId(), project1.uuid(), project1.getDbKey(), project1.name(), profile1.getKee()), tuple(project2.getId(), project2.uuid(), project2.getDbKey(), project2.name(), null), tuple(project3.getId(), project3.uuid(), project3.getDbKey(), project3.name(), null)); assertThat(underTest.selectProjectAssociations(dbSession, organization, profile1, "ect2")).hasSize(1); assertThat(underTest.selectProjectAssociations(dbSession, organization, profile3, null)).hasSize(3); }
public static ComponentDto newChildComponent(String uuid, ComponentDto moduleOrProject, ComponentDto parent) { checkArgument(moduleOrProject.isPrivate() == parent.isPrivate(), "private flag inconsistent between moduleOrProject (%s) and parent (%s)", moduleOrProject.isPrivate(), parent.isPrivate()); return new ComponentDto() .setOrganizationUuid(parent.getOrganizationUuid()) .setUuid(uuid) .setUuidPath(formatUuidPathFromParent(parent)) .setProjectUuid(moduleOrProject.projectUuid()) .setRootUuid(moduleOrProject.uuid()) .setModuleUuid(moduleOrProject.uuid()) .setModuleUuidPath(moduleOrProject.moduleUuidPath()) .setMainBranchProjectUuid(moduleOrProject.getMainBranchProjectUuid()) .setCreatedAt(new Date()) .setEnabled(true) .setPrivate(moduleOrProject.isPrivate()); }
String uuid = "uuid_" + uuidCounter++; dbClient.componentDao().insert(dbSession, new ComponentDto() .setOrganizationUuid(organizationDto.getUuid()) .setUuid(uuid) .setUuidPath(uuid + ".")
public static ComponentDto newProjectBranch(ComponentDto project, BranchDto branchDto) { checkArgument(project.qualifier().equals(Qualifiers.PROJECT) || project.qualifier().equals(Qualifiers.APP)); checkArgument(project.getMainBranchProjectUuid() == null); String branchName = branchDto.getKey(); String branchSeparator = branchDto.getBranchType() == PULL_REQUEST ? PULL_REQUEST_SEPARATOR : BRANCH_KEY_SEPARATOR; String uuid = branchDto.getUuid(); return new ComponentDto() .setUuid(uuid) .setOrganizationUuid(project.getOrganizationUuid()) .setUuidPath(UUID_PATH_OF_ROOT) .setProjectUuid(uuid) .setModuleUuidPath(UUID_PATH_SEPARATOR + uuid + UUID_PATH_SEPARATOR) .setRootUuid(uuid) // name of the branch is not mandatory on the main branch .setDbKey(branchName != null ? project.getDbKey() + branchSeparator + branchName : project.getKey()) .setMainBranchProjectUuid(project.uuid()) .setName(project.name()) .setLongName(project.longName()) .setDescription(project.description()) .setScope(project.scope()) .setQualifier(project.qualifier()) .setPath(null) .setLanguage(null) .setEnabled(true) .setPrivate(project.isPrivate()); } }
private static ComponentDto newProjectDto(String organizationUuid, String uuid, boolean isPrivate) { return new ComponentDto() .setOrganizationUuid(organizationUuid) .setUuid(uuid) .setUuidPath(UUID_PATH_OF_ROOT) .setProjectUuid(uuid) .setModuleUuidPath(UUID_PATH_SEPARATOR + uuid + UUID_PATH_SEPARATOR) .setRootUuid(uuid) .setDbKey("KEY_" + uuid) .setName("NAME_" + uuid) .setLongName("LONG_NAME_" + uuid) .setDescription("DESCRIPTION_" + uuid) .setScope(Scopes.PROJECT) .setQualifier(Qualifiers.PROJECT) .setPath(null) .setLanguage(null) .setEnabled(true) .setPrivate(isPrivate); }
@Test public void update_project_view() { OrganizationDto organizationDto = dbTester.organizations().insert(); ComponentDto view = newViewDto(organizationDto); ComponentDto project = ComponentTesting.newPrivateProjectDto(organizationDto); persistComponents(view, project); ComponentDto projectView = ComponentTesting.newProjectCopy(PROJECT_VIEW_1_UUID, project, view) .setOrganizationUuid(ORGANIZATION_UUID) .setDbKey(PROJECT_VIEW_1_KEY) .setName("Old name") .setCreatedAt(now); persistComponents(projectView); treeRootHolder.setRoot( createViewBuilder(PORTFOLIO) .addChildren(createProjectView1Builder(project, null).build()) .build()); underTest.execute(new TestComputationStepContext()); // commit functional transaction -> copies B-fields to A-fields dbClient.componentDao().applyBChangesForRootComponentUuid(dbTester.getSession(), view.uuid()); dbTester.commit(); assertRowsCountInTableProjects(3); ComponentDto pv1Dto = getComponentFromDb(PROJECT_VIEW_1_KEY); assertDtoIsProjectView1(pv1Dto, view, view, project); }
public boolean wouldUserHaveScanPermissionWithDefaultTemplate(DbSession dbSession, String organizationUuid, @Nullable Integer userId, String projectKey, String qualifier) { if (userSession.hasPermission(OrganizationPermission.SCAN, organizationUuid)) { return true; } ComponentDto dto = new ComponentDto().setOrganizationUuid(organizationUuid).setDbKey(projectKey).setQualifier(qualifier); PermissionTemplateDto template = findTemplate(dbSession, organizationUuid, dto); if (template == null) { return false; } List<String> potentialPermissions = dbClient.permissionTemplateDao().selectPotentialPermissionsByUserIdAndTemplateId(dbSession, userId, template.getId()); return potentialPermissions.contains(OrganizationPermission.SCAN.getKey()); }
private ComponentDto createBase(Component component) { String componentKey = component.getKey(); String componentUuid = component.getUuid(); ComponentDto componentDto = new ComponentDto(); componentDto.setOrganizationUuid(analysisMetadataHolder.getOrganization().getUuid()); componentDto.setUuid(componentUuid); componentDto.setDbKey(componentKey); componentDto.setDeprecatedKey(componentKey); componentDto.setMainBranchProjectUuid(mainBranchProjectUuid); componentDto.setEnabled(true); componentDto.setCreatedAt(new Date(system2.now())); return componentDto; }
private ComponentDto createRootComponent(DbSession session, NewComponent newComponent) { checkBranchFormat(newComponent.qualifier(), newComponent.branch()); String keyWithBranch = ComponentKeys.createKey(newComponent.key(), newComponent.branch()); checkRequest(!dbClient.componentDao().selectByKey(session, keyWithBranch).isPresent(), "Could not create %s, key already exists: %s", getQualifierToDisplay(newComponent.qualifier()), keyWithBranch); String uuid = Uuids.create(); ComponentDto component = new ComponentDto() .setOrganizationUuid(newComponent.getOrganizationUuid()) .setUuid(uuid) .setUuidPath(ComponentDto.UUID_PATH_OF_ROOT) .setRootUuid(uuid) .setModuleUuid(null) .setModuleUuidPath(ComponentDto.UUID_PATH_SEPARATOR + uuid + ComponentDto.UUID_PATH_SEPARATOR) .setProjectUuid(uuid) .setDbKey(keyWithBranch) .setDeprecatedKey(keyWithBranch) .setName(newComponent.name()) .setLongName(newComponent.name()) .setScope(Scopes.PROJECT) .setQualifier(newComponent.qualifier()) .setPrivate(newComponent.isPrivate()) .setCreatedAt(new Date(system2.now())); dbClient.componentDao().insert(session, component); return component; }