]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-15109 exclude project-specific webhooks from global webhook list
authorPierre <pierre.guillot@sonarsource.com>
Tue, 29 Jun 2021 11:40:49 +0000 (13:40 +0200)
committersonartech <sonartech@sonarsource.com>
Tue, 29 Jun 2021 20:03:18 +0000 (20:03 +0000)
server/sonar-db-dao/src/main/java/org/sonar/db/webhook/WebhookDao.java
server/sonar-db-dao/src/main/java/org/sonar/db/webhook/WebhookMapper.java
server/sonar-db-dao/src/main/resources/org/sonar/db/webhook/WebhookMapper.xml
server/sonar-db-dao/src/test/java/org/sonar/db/webhook/WebhookDaoTest.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/webhook/ws/ListAction.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/webhook/ws/ListActionTest.java

index 8c892304793b524fccc6811d1975e0a5fd4911ef..4baa61f2ce998e1312027d3b1f91b6f42b4f8856 100644 (file)
@@ -34,10 +34,6 @@ public class WebhookDao implements Dao {
     this.system2 = system2;
   }
 
-  public List<WebhookDto> selectAll(DbSession dbSession) {
-    return mapper(dbSession).selectAllOrderedByName();
-  }
-
   public List<WebhookDto> selectGlobalWebhooks(DbSession dbSession) {
     return mapper(dbSession).selectGlobalWebhooksOrderedByName();
   }
index d1d48898429bb20bf0ff906a86ebd1dabcce4122..dbf24214302e45e6679fb06d4c01c8e2b99addf0 100644 (file)
@@ -28,8 +28,6 @@ public interface WebhookMapper {
   @CheckForNull
   WebhookDto selectByUuid(@Param("webhookUuid") String webhookUuid);
 
-  List<WebhookDto> selectAllOrderedByName();
-
   List<WebhookDto> selectGlobalWebhooksOrderedByName();
 
   List<WebhookDto> selectForProjectUuidOrderedByName(@Param("projectUuid") String projectUuid);
index 7459d2b11e980d624bc46f9b8a05eeffd56701db..8978cdfb74f81cc8a1b1b1e8239c32903d7422db 100644 (file)
     where uuid = #{webhookUuid,jdbcType=VARCHAR}
   </select>
 
-  <select id="selectAllOrderedByName" parameterType="String" resultType="org.sonar.db.webhook.WebhookDto">
-    select <include refid="sqlColumns" />
-    from webhooks
-    order by name asc
-  </select>
-
   <select id="selectGlobalWebhooksOrderedByName" parameterType="String" resultType="org.sonar.db.webhook.WebhookDto">
     select <include refid="sqlColumns" />
     from webhooks
index c9484b6a205f4b48d08320d6c5b19cae4697e5c4..54161f2a626971b56cef11dee201d4385662c8f4 100644 (file)
@@ -50,26 +50,6 @@ public class WebhookDaoTest {
     assertThat(underTest.selectByUuid(dbSession, "missing")).isEmpty();
   }
 
-  @Test
-  public void select_all_webhooks() {
-    ProjectDto projectDto = componentDbTester.insertPrivateProjectDto();
-    webhookDbTester.insertGlobalWebhook();
-    webhookDbTester.insertGlobalWebhook();
-    webhookDbTester.insertWebhook(projectDto);
-    webhookDbTester.insertWebhook(projectDto);
-
-    List<WebhookDto> results = underTest.selectAll(dbSession);
-
-    assertThat(results).hasSize(4);
-  }
-
-  @Test
-  public void select_all_webhooks_returns_empty_list_if_there_are_no_webhooks() {
-    List<WebhookDto> results = underTest.selectAll(dbSession);
-
-    assertThat(results).isEmpty();
-  }
-
   @Test
   public void select_global_webhooks() {
     ProjectDto projectDto = componentDbTester.insertPrivateProjectDto();
index 6fd2dd5f17ba726a76f9ac37911008751b404049..b0c4e88d9820f4693493cbd52aa35a60b3bd72f4 100644 (file)
@@ -101,7 +101,7 @@ public class ListAction implements WebhooksWsAction {
       return dbClient.webhookDao().selectByProject(dbSession, projectDto);
     } else {
       webhookSupport.checkPermission();
-      return dbClient.webhookDao().selectAll(dbSession);
+      return dbClient.webhookDao().selectGlobalWebhooks(dbSession);
     }
   }
 
index 0ca1bd2984c9c88ca0139b6f4134195893708754..1c3b06850c492d8c080906923aec44cb2e604a98 100644 (file)
@@ -168,6 +168,9 @@ public class ListActionTest {
   public void list_global_webhooks() {
     WebhookDto dto1 = webhookDbTester.insertGlobalWebhook();
     WebhookDto dto2 = webhookDbTester.insertGlobalWebhook();
+    // insert a project-specific webhook, that should not be returned when listing global webhooks
+    webhookDbTester.insertWebhook(componentDbTester.insertPrivateProjectDto());
+
     userSession.logIn().addPermission(ADMINISTER);
 
     ListResponse response = wsActionTester.newRequest()
@@ -175,7 +178,7 @@ public class ListActionTest {
 
     assertThat(response.getWebhooksList())
       .extracting(Webhooks.ListResponseElement::getName, Webhooks.ListResponseElement::getUrl)
-      .contains(tuple(dto1.getName(), dto1.getUrl()),
+      .containsExactlyInAnyOrder(tuple(dto1.getName(), dto1.getUrl()),
         tuple(dto2.getName(), dto2.getUrl()));
 
   }