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 static ComponentDto newView(String organizationUuid, String uuid) { return newProjectDto(organizationUuid, uuid, false) .setUuid(uuid) .setScope(Scopes.PROJECT) .setQualifier(Qualifiers.VIEW); }
public static ComponentDto newApplication(OrganizationDto organizationDto) { return newView(organizationDto.getUuid(), Uuids.createFast()) .setQualifier(Qualifiers.APP); }
@Test public void is_root_project() { assertThat(new ComponentDto().setModuleUuid("ABCD").isRootProject()).isFalse(); assertThat(new ComponentDto().setModuleUuid("ABCD").setScope(Scopes.DIRECTORY).isRootProject()).isFalse(); assertThat(new ComponentDto().setModuleUuid(null).setScope(Scopes.PROJECT).setQualifier(Qualifiers.PROJECT).isRootProject()).isTrue(); }
public ComponentDto createForDirectory(Component directory, PathAwareVisitor.Path<ComponentDtoHolder> path) { ComponentDto res = createBase(directory); res.setScope(Scopes.DIRECTORY); res.setQualifier(Qualifiers.DIRECTORY); res.setName(directory.getShortName()); res.setLongName(directory.getName()); res.setPath(directory.getName()); setParentModuleProperties(res, path); return res; }
public static ComponentDto newView(OrganizationDto organizationDto, String uuid) { return newPrivateProjectDto(organizationDto, uuid) .setUuid(uuid) .setScope(Scopes.PROJECT) .setQualifier(Qualifiers.VIEW) .setPrivate(false); }
private ComponentDto createForProjectView(Component projectView, PathAwareVisitor.Path<ComponentDtoHolder> path) { ComponentDto res = createBase(projectView); res.setScope(Scopes.FILE); res.setQualifier(Qualifiers.PROJECT); res.setName(projectView.getName()); res.setLongName(res.name()); res.setCopyComponentUuid(projectView.getProjectViewAttributes().getProjectUuid()); setRootAndParentModule(res, path); return res; }
public ComponentDto createForFile(Component file, PathAwareVisitor.Path<ComponentDtoHolder> path) { ComponentDto res = createBase(file); res.setScope(Scopes.FILE); res.setQualifier(getFileQualifier(file)); res.setName(file.getShortName()); res.setLongName(file.getName()); res.setPath(file.getName()); res.setLanguage(file.getFileAttributes().getLanguageKey()); setParentModuleProperties(res, path); return res; }
private static ComponentDto newComponentWithoutSnapshotId(String name, String qualifier, String path) { return new ComponentDto() .setUuid(Uuids.createFast()) .setName(name) .setQualifier(qualifier) .setPath(path); }
private ComponentDto createForSubView(Component subView, PathAwareVisitor.Path<ComponentDtoHolder> path) { ComponentDto res = createBase(subView); res.setScope(Scopes.PROJECT); res.setQualifier(Qualifiers.SUBVIEW); res.setName(subView.getName()); res.setDescription(subView.getDescription()); res.setLongName(res.name()); res.setCopyComponentUuid(subView.getSubViewAttributes().getOriginalViewUuid()); setRootAndParentModule(res, path); return res; }
public static ComponentDto newSubView(ComponentDto viewOrSubView, String uuid, String key) { return newModuleDto(uuid, viewOrSubView) .setDbKey(key) .setName(key) .setLongName(key) .setScope(Scopes.PROJECT) .setQualifier(Qualifiers.SUBVIEW) .setPath(null); }
private ComponentAndSource insertFileAndSource(ComponentDto parent, String qualifier) { ComponentDto file = db.components().insertComponent(ComponentTesting.newFileDto(parent).setQualifier(qualifier)); FileSourceDto fileSource = db.fileSources().insertFileSource(file); return new ComponentAndSource(file, fileSource); }
public static ComponentDto newFileDto(ComponentDto module, @Nullable ComponentDto directory, String fileUuid) { String filename = "NAME_" + fileUuid; String path = directory != null ? directory.path() + "/" + filename : module.path() + "/" + filename; return newChildComponent(fileUuid, module, directory == null ? module : directory) .setDbKey(generateKey("FILE_KEY_" + fileUuid, module)) .setName(filename) .setLongName(path) .setScope(Scopes.FILE) .setQualifier(Qualifiers.FILE) .setPath(path) .setCreatedAt(new Date()) .setLanguage("xoo"); }
public static ComponentDto newDirectory(ComponentDto module, String uuid, String path) { String key = !path.equals("/") ? module.getKey() + ":" + path : module.getKey() + ":/"; return newChildComponent(uuid, module, module) .setDbKey(generateKey(key, module)) .setName(path) .setLongName(path) .setPath(path) .setScope(Scopes.DIRECTORY) .setQualifier(Qualifiers.DIRECTORY); }
@Test public void param_componentUuids_enables_search_by_test_file() { ComponentDto project = db.components().insertPrivateProject(); ComponentDto file = db.components().insertComponent(newFileDto(project).setQualifier(Qualifiers.UNIT_TEST_FILE)); SearchRequest request = new SearchRequest() .setComponentUuids(asList(file.uuid())); IssueQuery query = underTest.create(request); assertThat(query.fileUuids()).containsExactly(file.uuid()); }
public ComponentDto createForProject(Component project) { ComponentDto res = createBase(project); res.setScope(Scopes.PROJECT); res.setQualifier(Qualifiers.PROJECT); res.setName(project.getName()); res.setLongName(res.name()); res.setDescription(project.getDescription()); res.setProjectUuid(res.uuid()); res.setRootUuid(res.uuid()); res.setUuidPath(UUID_PATH_OF_ROOT); res.setModuleUuidPath(UUID_PATH_SEPARATOR + res.uuid() + UUID_PATH_SEPARATOR); return res; }
@Test public void scrollAllFilesForFileMove_ignores_files_without_source() { OrganizationDto organization = db.organizations().insert(); ComponentDto project = random.nextBoolean() ? db.components().insertPrivateProject(organization) : db.components().insertPublicProject(organization); ComponentAndSource file = insertFileAndSource(project, FILE); ComponentAndSource ut = insertFileAndSource(project, UNIT_TEST_FILE); ComponentDto fileNoSource = db.components().insertComponent(ComponentTesting.newFileDto(project).setPath(null).setQualifier(FILE)); ComponentDto utNoSource = db.components().insertComponent(ComponentTesting.newFileDto(project).setPath(null).setQualifier(UNIT_TEST_FILE)); RecordingResultHandler resultHandler = new RecordingResultHandler(); underTest.scrollAllFilesForFileMove(dbSession, project.uuid(), resultHandler); assertThat(resultHandler.dtos).hasSize(2); verifyFileMoveRowDto(resultHandler, file); verifyFileMoveRowDto(resultHandler, ut); }
private ComponentDto createForView(Component view) { ComponentDto res = createBase(view); res.setScope(Scopes.PROJECT); res.setQualifier(view.getViewAttributes().getType().getQualifier()); res.setName(view.getName()); res.setDescription(view.getDescription()); res.setLongName(res.name()); res.setProjectUuid(res.uuid()); res.setRootUuid(res.uuid()); res.setUuidPath(UUID_PATH_OF_ROOT); res.setModuleUuidPath(UUID_PATH_SEPARATOR + res.uuid() + UUID_PATH_SEPARATOR); return res; }
public static ComponentDto newProjectCopy(String uuid, ComponentDto project, ComponentDto view) { checkNotNull(project.getId(), "The project need to be persisted before creating this technical project."); return newChildComponent(uuid, view, view) .setDbKey(view.getDbKey() + project.getDbKey()) .setName(project.name()) .setLongName(project.longName()) .setCopyComponentUuid(project.uuid()) .setScope(Scopes.FILE) .setQualifier(Qualifiers.PROJECT) .setPath(null) .setLanguage(null); }
public static ComponentDto newModuleDto(String uuid, ComponentDto parentModuleOrProject) { return newChildComponent(uuid, parentModuleOrProject, parentModuleOrProject) .setModuleUuidPath(parentModuleOrProject.moduleUuidPath() + uuid + UUID_PATH_SEPARATOR) .setDbKey(generateKey("MODULE_KEY_" + uuid, parentModuleOrProject)) .setName("NAME_" + uuid) .setLongName("LONG_NAME_" + uuid) .setPath("module") .setScope(Scopes.PROJECT) .setQualifier(Qualifiers.MODULE) .setLanguage(null); }