aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNolwenn Cadic <98824442+Nolwenn-cadic-sonarsource@users.noreply.github.com>2024-08-23 11:39:44 +0200
committersonartech <sonartech@sonarsource.com>2024-08-23 20:02:33 +0000
commitb80a57a23ecf821ce3b5c78b77bce4a20ef235e1 (patch)
tree86bd1846d27873e916a385d9c1ccad6f421f7e6c
parent9621821160e9618e20f90cd7ea3b1b696c1ac7b4 (diff)
downloadsonarqube-b80a57a23ecf821ce3b5c78b77bce4a20ef235e1.tar.gz
sonarqube-b80a57a23ecf821ce3b5c78b77bce4a20ef235e1.zip
SONAR-22807 Implement get and patch gitlab permissions mapping endpoint
-rw-r--r--server/sonar-db-dao/src/it/java/org/sonar/db/provisioning/DevOpsPermissionsMappingDaoIT.java2
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/provisioning/DevOpsPermissionsMappingDao.java2
-rw-r--r--server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v107/AddDevopsPlatformColumnInDevopsPermsMappingIT.java4
-rw-r--r--server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v107/PopulateGitlabDevopsPermissionsMappingIT.java7
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v107/DropPrimaryKeyOnDevopsPermsMappingTable.java2
-rw-r--r--server/sonar-webserver-common/src/main/java/org/sonar/server/common/almsettings/github/GithubProjectCreator.java3
-rw-r--r--server/sonar-webserver-webapi-v2/src/main/java/org/sonar/server/v2/WebApiEndpoints.java1
7 files changed, 11 insertions, 10 deletions
diff --git a/server/sonar-db-dao/src/it/java/org/sonar/db/provisioning/DevOpsPermissionsMappingDaoIT.java b/server/sonar-db-dao/src/it/java/org/sonar/db/provisioning/DevOpsPermissionsMappingDaoIT.java
index 12a9ad741b0..54378bab827 100644
--- a/server/sonar-db-dao/src/it/java/org/sonar/db/provisioning/DevOpsPermissionsMappingDaoIT.java
+++ b/server/sonar-db-dao/src/it/java/org/sonar/db/provisioning/DevOpsPermissionsMappingDaoIT.java
@@ -152,7 +152,7 @@ class DevOpsPermissionsMappingDaoIT {
underTest.insert(dbSession, mapping2);
underTest.insert(dbSession, mapping3);
- Set<DevOpsPermissionsMappingDto> forRole2 = underTest.findAllForRole(dbSession, DEV_OPS_PLATFORM, "GH_role2");
+ Set<DevOpsPermissionsMappingDto> forRole2 = underTest.findAllForDevopsRole(dbSession, DEV_OPS_PLATFORM, "GH_role2");
assertThat(forRole2).hasSize(2)
.containsExactlyInAnyOrder(mapping2, mapping3);
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/provisioning/DevOpsPermissionsMappingDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/provisioning/DevOpsPermissionsMappingDao.java
index c5737e62910..800ee25003f 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/provisioning/DevOpsPermissionsMappingDao.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/provisioning/DevOpsPermissionsMappingDao.java
@@ -37,7 +37,7 @@ public class DevOpsPermissionsMappingDao implements Dao {
return mapper(dbSession).selectAll(devOpsPlatform);
}
- public Set<DevOpsPermissionsMappingDto> findAllForRole(DbSession dbSession, String devOpsPlatform, String role) {
+ public Set<DevOpsPermissionsMappingDto> findAllForDevopsRole(DbSession dbSession, String devOpsPlatform, String role) {
return mapper(dbSession).selectAllForRole(devOpsPlatform, role);
}
diff --git a/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v107/AddDevopsPlatformColumnInDevopsPermsMappingIT.java b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v107/AddDevopsPlatformColumnInDevopsPermsMappingIT.java
index 0c9547dc723..c66906c6402 100644
--- a/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v107/AddDevopsPlatformColumnInDevopsPermsMappingIT.java
+++ b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v107/AddDevopsPlatformColumnInDevopsPermsMappingIT.java
@@ -26,7 +26,7 @@ import org.junit.jupiter.api.extension.RegisterExtension;
import org.sonar.db.MigrationDbTester;
import static java.sql.Types.VARCHAR;
-import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
+import static org.assertj.core.api.Assertions.assertThat;
import static org.sonar.server.platform.db.migration.version.v107.AddDevopsPlatformColumnInDevopsPermsMapping.DEVOPS_PLATFORM_COLUMN_NAME;
import static org.sonar.server.platform.db.migration.version.v107.AddDevopsPlatformColumnInDevopsPermsMapping.DEFAULT_COLUMN_VALUE;
import static org.sonar.server.platform.db.migration.version.v107.RenameGithubPermsMappingTable.DEVOPS_PERMS_MAPPING_TABLE_NAME;
@@ -62,7 +62,7 @@ class AddDevopsPlatformColumnInDevopsPermsMappingIT {
private void assertDevopsPlatformColumnSetToDefault() {
Map<String, Object> selectResult = db.selectFirst("select devops_platform from devops_perms_mapping where uuid = 'UUID'");
- assertThat(selectResult.get("devops_platform")).isEqualTo(DEFAULT_COLUMN_VALUE);
+ assertThat(selectResult).containsEntry("devops_platform", DEFAULT_COLUMN_VALUE);
}
private void assertColumnExists() {
diff --git a/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v107/PopulateGitlabDevopsPermissionsMappingIT.java b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v107/PopulateGitlabDevopsPermissionsMappingIT.java
index b3c7e3259ff..90342d1a9a4 100644
--- a/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v107/PopulateGitlabDevopsPermissionsMappingIT.java
+++ b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v107/PopulateGitlabDevopsPermissionsMappingIT.java
@@ -24,6 +24,7 @@ import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
import org.sonar.api.testfixtures.log.LogTesterJUnit5;
import org.sonar.core.util.UuidFactoryFast;
+import org.sonar.core.util.UuidFactoryImpl;
import org.sonar.db.MigrationDbTester;
import static org.assertj.core.api.Assertions.assertThat;
@@ -37,7 +38,7 @@ class PopulateGitlabDevopsPermissionsMappingIT {
@RegisterExtension
public final LogTesterJUnit5 logTester = new LogTesterJUnit5();
- private final PopulateGitlabDevOpsPermissionsMapping migration = new PopulateGitlabDevOpsPermissionsMapping(db.database(), UuidFactoryFast.getInstance());
+ private final PopulateGitlabDevOpsPermissionsMapping migration = new PopulateGitlabDevOpsPermissionsMapping(db.database(), UuidFactoryImpl.INSTANCE);
@Test
void execute_whenTableIsEmpty_shouldPopulate() throws SQLException {
@@ -57,7 +58,7 @@ class PopulateGitlabDevopsPermissionsMappingIT {
@Test
void execute_whenTableAlreadyPopulated_doesNothing() throws SQLException {
db.executeInsert(DEVOPS_PERMS_MAPPING_TABLE_NAME,
- "UUID", UuidFactoryFast.getInstance().create(),
+ "UUID", UuidFactoryImpl.INSTANCE.create(),
"devops_platform", "gitlab",
"devops_platform_role", "role1",
"sonarqube_permission", "sq_perm");
@@ -72,7 +73,7 @@ class PopulateGitlabDevopsPermissionsMappingIT {
@Test
void execute_whenTableAlreadyPopulatedWithGithub_appliesMigration() throws SQLException {
db.executeInsert(DEVOPS_PERMS_MAPPING_TABLE_NAME,
- "UUID", UuidFactoryFast.getInstance().create(),
+ "UUID", UuidFactoryImpl.INSTANCE.create(),
"devops_platform", "github",
"devops_platform_role", "role1",
"sonarqube_permission", "sq_perm");
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v107/DropPrimaryKeyOnDevopsPermsMappingTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v107/DropPrimaryKeyOnDevopsPermsMappingTable.java
index 6eb6aa7a803..693893ac1eb 100644
--- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v107/DropPrimaryKeyOnDevopsPermsMappingTable.java
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v107/DropPrimaryKeyOnDevopsPermsMappingTable.java
@@ -20,12 +20,10 @@
package org.sonar.server.platform.db.migration.version.v107;
import com.google.common.annotations.VisibleForTesting;
-import java.sql.Connection;
import java.sql.SQLException;
import java.util.List;
import java.util.Optional;
import org.sonar.db.Database;
-import org.sonar.db.DatabaseUtils;
import org.sonar.server.platform.db.migration.sql.DbPrimaryKeyConstraintFinder;
import org.sonar.server.platform.db.migration.sql.DropPrimaryKeySqlGenerator;
import org.sonar.server.platform.db.migration.step.DdlChange;
diff --git a/server/sonar-webserver-common/src/main/java/org/sonar/server/common/almsettings/github/GithubProjectCreator.java b/server/sonar-webserver-common/src/main/java/org/sonar/server/common/almsettings/github/GithubProjectCreator.java
index 63da5997679..e44c0debdb5 100644
--- a/server/sonar-webserver-common/src/main/java/org/sonar/server/common/almsettings/github/GithubProjectCreator.java
+++ b/server/sonar-webserver-common/src/main/java/org/sonar/server/common/almsettings/github/GithubProjectCreator.java
@@ -74,7 +74,8 @@ public class GithubProjectCreator extends DefaultDevOpsProjectCreator {
String organization = orgaAndRepoTokenified[0];
String repository = orgaAndRepoTokenified[1];
- Set<DevOpsPermissionsMappingDto> permissionsMappingDtos = dbClient.githubPermissionsMappingDao().findAll(dbClient.openSession(false), devOpsPlatformSettings.getDevOpsPlatform());
+ Set<DevOpsPermissionsMappingDto> permissionsMappingDtos = dbClient.githubPermissionsMappingDao()
+ .findAll(dbClient.openSession(false), devOpsPlatformSettings.getDevOpsPlatform());
boolean userHasDirectAccessToRepo = doesUserHaveScanPermission(organization, repository, permissionsMappingDtos);
if (userHasDirectAccessToRepo) {
diff --git a/server/sonar-webserver-webapi-v2/src/main/java/org/sonar/server/v2/WebApiEndpoints.java b/server/sonar-webserver-webapi-v2/src/main/java/org/sonar/server/v2/WebApiEndpoints.java
index a705491096d..62304f218b4 100644
--- a/server/sonar-webserver-webapi-v2/src/main/java/org/sonar/server/v2/WebApiEndpoints.java
+++ b/server/sonar-webserver-webapi-v2/src/main/java/org/sonar/server/v2/WebApiEndpoints.java
@@ -45,6 +45,7 @@ public class WebApiEndpoints {
public static final String BOUND_PROJECTS_ENDPOINT = DOP_TRANSLATION_DOMAIN + "/bound-projects";
public static final String PROJECT_BINDINGS_ENDPOINT = DOP_TRANSLATION_DOMAIN + "/project-bindings";
public static final String DOP_SETTINGS_ENDPOINT = DOP_TRANSLATION_DOMAIN + "/dop-settings";
+ public static final String GITLAB_PERMISSIONS_MAPPING_ENDPOINT = DOP_TRANSLATION_DOMAIN + "/gitlab-permission-mappings";
public static final String ANALYSIS_DOMAIN = "/analysis";
public static final String VERSION_ENDPOINT = ANALYSIS_DOMAIN + "/version";