use of org.sonar.db.permission.GlobalPermission.PROVISION_PROJECTS in project sonarqube by SonarSource.
the class SearchBitbucketServerReposAction method doHandle.
private SearchBitbucketserverReposWsResponse doHandle(Request request) {
try (DbSession dbSession = dbClient.openSession(false)) {
userSession.checkLoggedIn().checkPermission(PROVISION_PROJECTS);
String almSettingKey = request.mandatoryParam(PARAM_ALM_SETTING);
String userUuid = requireNonNull(userSession.getUuid(), "User UUID cannot be null");
AlmSettingDto almSettingDto = dbClient.almSettingDao().selectByKey(dbSession, almSettingKey).orElseThrow(() -> new NotFoundException(String.format("ALM Setting '%s' not found", almSettingKey)));
Optional<AlmPatDto> almPatDto = dbClient.almPatDao().selectByUserAndAlmSetting(dbSession, userUuid, almSettingDto);
String projectKey = request.param(PARAM_PROJECT_NAME);
String repoName = request.param(PARAM_REPO_NAME);
String pat = almPatDto.map(AlmPatDto::getPersonalAccessToken).orElseThrow(() -> new IllegalArgumentException("No personal access token found"));
String url = requireNonNull(almSettingDto.getUrl(), "ALM url cannot be null");
RepositoryList gsonBBSRepoList = bitbucketServerRestClient.getRepos(url, pat, projectKey, repoName);
Map<String, String> sqProjectsKeyByBBSKey = getSqProjectsKeyByBBSKey(dbSession, almSettingDto, gsonBBSRepoList);
List<BBSRepo> bbsRepos = gsonBBSRepoList.getValues().stream().map(gsonBBSRepo -> toBBSRepo(gsonBBSRepo, sqProjectsKeyByBBSKey)).collect(toList());
SearchBitbucketserverReposWsResponse.Builder builder = SearchBitbucketserverReposWsResponse.newBuilder().setIsLastPage(gsonBBSRepoList.isLastPage()).addAllRepositories(bbsRepos);
return builder.build();
}
}
use of org.sonar.db.permission.GlobalPermission.PROVISION_PROJECTS in project sonarqube by SonarSource.
the class ListAction method doHandle.
private ListWsResponse doHandle(Request request) {
try (DbSession dbSession = dbClient.openSession(false)) {
Request.StringParam projectKey = request.getParam(PARAM_PROJECT);
if (projectKey.isPresent()) {
ProjectDto project = componentFinder.getProjectByKey(dbSession, projectKey.getValue());
userSession.checkProjectPermission(ADMIN, project);
} else {
userSession.checkPermission(PROVISION_PROJECTS);
}
List<AlmSettingDto> settings = dbClient.almSettingDao().selectAll(dbSession);
List<AlmSetting> wsAlmSettings = settings.stream().sorted(Comparator.comparing(AlmSettingDto::getKey)).map(almSetting -> {
AlmSetting.Builder almSettingBuilder = AlmSetting.newBuilder().setKey(almSetting.getKey()).setAlm(AlmSettingsSupport.toAlmWs(almSetting.getAlm()));
if (almSetting.getAlm() == ALM.BITBUCKET_CLOUD) {
almSettingBuilder.setUrl(BITBUCKETCLOUD_ROOT_URL + almSetting.getAppId() + "/");
} else {
ofNullable(almSetting.getUrl()).ifPresent(almSettingBuilder::setUrl);
}
return almSettingBuilder.build();
}).collect(Collectors.toList());
return ListWsResponse.newBuilder().addAllAlmSettings(wsAlmSettings).build();
}
}
use of org.sonar.db.permission.GlobalPermission.PROVISION_PROJECTS in project sonarqube by SonarSource.
the class ReportSubmitterTest method submit_with_characteristics_fails_with_ISE_when_no_branch_support_delegate.
@Test
public void submit_with_characteristics_fails_with_ISE_when_no_branch_support_delegate() {
userSession.addPermission(GlobalPermission.SCAN).addPermission(PROVISION_PROJECTS);
mockSuccessfulPrepareSubmitCall();
when(permissionTemplateService.wouldUserHaveScanPermissionWithDefaultTemplate(any(), any(), eq(PROJECT_KEY))).thenReturn(true);
Map<String, String> nonEmptyCharacteristics = IntStream.range(0, 1 + new Random().nextInt(5)).boxed().collect(uniqueIndex(i -> randomAlphabetic(i + 10), i -> randomAlphabetic(i + 20)));
InputStream reportInput = IOUtils.toInputStream("{binary}", UTF_8);
assertThatThrownBy(() -> underTest.submit(PROJECT_KEY, PROJECT_NAME, nonEmptyCharacteristics, reportInput)).isInstanceOf(IllegalStateException.class).hasMessage("Current edition does not support branch feature");
}
Aggregations