use of org.sonar.db.webhook.WebhookDto in project sonarqube by SonarSource.
the class WebHooksImpl method readWebHooksFrom.
private Stream<WebhookDto> readWebHooksFrom(String projectUuid, @CheckForNull PostProjectAnalysisTask.LogStatistics taskLogStatistics) {
try (DbSession dbSession = dbClient.openSession(false)) {
Optional<ProjectDto> optionalProjectDto = dbClient.projectDao().selectByUuid(dbSession, projectUuid);
ProjectDto projectDto = checkStateWithOptional(optionalProjectDto, "the requested project '%s' was not found", projectUuid);
WebhookDao dao = dbClient.webhookDao();
List<WebhookDto> projectWebhooks = dao.selectByProject(dbSession, projectDto);
List<WebhookDto> globalWebhooks = dao.selectGlobalWebhooks(dbSession);
if (taskLogStatistics != null) {
taskLogStatistics.add("globalWebhooks", globalWebhooks.size());
taskLogStatistics.add("projectWebhooks", projectWebhooks.size());
}
return Stream.concat(projectWebhooks.stream(), globalWebhooks.stream());
}
}
use of org.sonar.db.webhook.WebhookDto in project sonarqube by SonarSource.
the class DeleteActionTest method project_deletion_also_ensure_that_webhooks_on_this_project_if_they_exists_are_deleted.
@Test
public void project_deletion_also_ensure_that_webhooks_on_this_project_if_they_exists_are_deleted() {
ProjectDto project = componentDbTester.insertPrivateProjectDto();
webhookDbTester.insertWebhook(project);
webhookDbTester.insertWebhook(project);
webhookDbTester.insertWebhook(project);
webhookDbTester.insertWebhook(project);
userSessionRule.logIn().addProjectPermission(ADMIN, project);
DeleteAction underTest = new DeleteAction(new ComponentCleanerService(dbClient, mockResourceTypes, new TestProjectIndexers()), from(db), dbClient, userSessionRule, projectLifeCycleListeners);
new WsActionTester(underTest).newRequest().setParam(PARAM_PROJECT, project.getKey()).execute();
List<WebhookDto> webhookDtos = dbClient.webhookDao().selectByProject(dbSession, project);
assertThat(webhookDtos).isEmpty();
}
use of org.sonar.db.webhook.WebhookDto in project sonarqube by SonarSource.
the class DeleteActionTest method fail_if_no_permission_on_webhook_scope_project.
@Test
public void fail_if_no_permission_on_webhook_scope_project() {
ProjectDto project = componentDbTester.insertPrivateProjectDto();
WebhookDto dto = webhookDbTester.insertWebhook(project);
userSession.logIn();
TestRequest request = wsActionTester.newRequest().setParam(KEY_PARAM, dto.getUuid());
assertThatThrownBy(request::execute).isInstanceOf(ForbiddenException.class).hasMessage("Insufficient privileges");
}
use of org.sonar.db.webhook.WebhookDto in project sonarqube by SonarSource.
the class DeleteActionTest method delete_a_global_webhook.
@Test
public void delete_a_global_webhook() {
WebhookDto dto = webhookDbTester.insertGlobalWebhook();
webhookDeliveryDbTester.insert(newDto().setWebhookUuid(dto.getUuid()));
webhookDeliveryDbTester.insert(newDto().setWebhookUuid(dto.getUuid()));
userSession.logIn().addPermission(ADMINISTER);
TestResponse response = wsActionTester.newRequest().setParam(KEY_PARAM, dto.getUuid()).execute();
assertThat(response.getStatus()).isEqualTo(HTTP_NO_CONTENT);
Optional<WebhookDto> reloaded = webhookDbTester.selectWebhook(dto.getUuid());
assertThat(reloaded).isEmpty();
int deliveriesCount = deliveryDao.countDeliveriesByWebhookUuid(dbSession, dto.getUuid());
assertThat(deliveriesCount).isZero();
}
use of org.sonar.db.webhook.WebhookDto in project sonarqube by SonarSource.
the class DeleteActionTest method fail_if_no_permission_on_webhook_scope_global.
@Test
public void fail_if_no_permission_on_webhook_scope_global() {
WebhookDto dto = webhookDbTester.insertGlobalWebhook();
userSession.logIn();
TestRequest request = wsActionTester.newRequest().setParam(KEY_PARAM, dto.getUuid());
assertThatThrownBy(request::execute).isInstanceOf(ForbiddenException.class).hasMessage("Insufficient privileges");
}
Aggregations